X-Git-Url: http://git.veekun.com/zzz-pokedex.git/blobdiff_plain/9f083a8f296186583d592ceb7263b24f0c282d18..e61d2b2c191e590a4d60c529eca0b717be9b1a33:/pokedex/db/tables.py?ds=sidebyside diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index 71ce534..2278cb0 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -16,13 +16,8 @@ Columns have a info dictionary with these keys: for translation. - latex: A formula in LaTeX syntax. -A localizable text column is visible as two properties: -The plural-name property (e.g. Pokemon.names) is a language-to-name dictionary: - bulbasaur.names['en'] == "Bulbasaur" and bulbasaur.names['de'] == "Bisasam". - You can use Pokemon.names['en'] to filter a query. -The singular-name property returns the name in the default language, English. - For example bulbasaur.name == "Bulbasaur" - Setting pokedex.db.tables.default_lang changes the default language. +See `pokedex.db.multilang` for how localizable text columns work. The session +classes in that module can be used to change the default language. """ # XXX: Check if "gametext" is set correctly everywhere @@ -30,7 +25,7 @@ import collections from functools import partial from sqlalchemy import Column, ForeignKey, MetaData, PrimaryKeyConstraint, Table, UniqueConstraint -from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.orm import backref, relation from sqlalchemy.orm.session import Session @@ -65,14 +60,22 @@ class TableSuperclass(object): def __str__(self): return unicode(self).encode('utf8') +mapped_classes = [] +class TableMetaclass(DeclarativeMeta): + def __init__(cls, name, bases, attrs): + super(TableMetaclass, cls).__init__(name, bases, attrs) + if hasattr(cls, '__tablename__'): + mapped_classes.append(cls) + cls.translation_classes = [] + metadata = MetaData() -TableBase = declarative_base(metadata=metadata, cls=TableSuperclass) +TableBase = declarative_base(metadata=metadata, cls=TableSuperclass, metaclass=TableMetaclass) ### Need Language first, to create the partial() below class Language(TableBase): - u"""A language the Pokémon games have been transleted into + u"""A language the Pokémon games have been translated into """ __tablename__ = 'languages' __singlename__ = 'language' @@ -855,7 +858,7 @@ class MoveMetaAilment(TableBase): """ __tablename__ = 'move_meta_ailments' __singlename__ = 'move_meta_ailment' - id = Column(Integer, primary_key=True, nullable=False, + id = Column(Integer, primary_key=True, nullable=False, autoincrement=False, info=dict(description="A numeric ID")) identifier = Column(Unicode(24), nullable=False, info=dict(description="An identifier", format='identifier')) @@ -876,7 +879,7 @@ class MoveMetaCategory(TableBase): create_translation_table('move_meta_category_prose', MoveMetaCategory, 'prose', relation_lazy='joined', description = Column(Unicode(64), nullable=False, - info=dict(description="A description of the category")), + info=dict(description="A description of the category", format="plaintext", official=False)), ) class MoveMetaStatChange(TableBase): @@ -1083,7 +1086,7 @@ class Pokemon(TableBase): info=dict(description=u"The weight of the Pokémon, in tenths of a kilogram (decigrams)")) color_id = Column(Integer, ForeignKey('pokemon_colors.id'), nullable=False, info=dict(description=u"ID of this Pokémon's Pokédex color, as used for a gimmick search function in the games.")) - pokemon_shape_id = Column(Integer, ForeignKey('pokemon_shapes.id'), nullable=True, + pokemon_shape_id = Column(Integer, ForeignKey('pokemon_shapes.id'), nullable=False, info=dict(description=u"ID of this Pokémon's body shape, as used for a gimmick search function in the games.")) habitat_id = Column(Integer, ForeignKey('pokemon_habitats.id'), nullable=True, info=dict(description=u"ID of this Pokémon's habitat, as used for a gimmick search function in the games.")) @@ -1538,6 +1541,8 @@ class Stat(TableBase): info=dict(description=u"For offensive and defensive stats, the damage this stat relates to; otherwise None (the NULL value)")) identifier = Column(Unicode(16), nullable=False, info=dict(description=u"An identifier", format='identifier')) + is_battle_only = Column(Boolean, nullable=False, + info=dict(description=u"Whether this stat only exists within a battle")) create_translation_table('stat_names', Stat, 'names', relation_lazy='joined',