mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Remove LanguageSpecific.
This commit is contained in:
parent
8ad84e4032
commit
ef1db6029d
1 changed files with 17 additions and 28 deletions
|
@ -49,15 +49,6 @@ from inspect import isclass
|
||||||
|
|
||||||
from pokedex.db import markdown, multilang
|
from pokedex.db import markdown, multilang
|
||||||
|
|
||||||
# A list of all table classes will live in table_classes
|
|
||||||
table_classes = []
|
|
||||||
|
|
||||||
class TableMetaclass(DeclarativeMeta):
|
|
||||||
def __init__(cls, name, bases, attrs):
|
|
||||||
super(TableMetaclass, cls).__init__(name, bases, attrs)
|
|
||||||
if hasattr(cls, '__tablename__'):
|
|
||||||
table_classes.append(cls)
|
|
||||||
|
|
||||||
class TableSuperclass(object):
|
class TableSuperclass(object):
|
||||||
"""Superclass for declarative tables, to give them some generic niceties
|
"""Superclass for declarative tables, to give them some generic niceties
|
||||||
like stringification.
|
like stringification.
|
||||||
|
@ -83,15 +74,7 @@ class TableSuperclass(object):
|
||||||
return unicode(self).encode('utf8')
|
return unicode(self).encode('utf8')
|
||||||
|
|
||||||
metadata = MetaData()
|
metadata = MetaData()
|
||||||
TableBase = declarative_base(metadata=metadata, cls=TableSuperclass, metaclass=TableMetaclass)
|
TableBase = declarative_base(metadata=metadata, cls=TableSuperclass)
|
||||||
|
|
||||||
### Helper classes
|
|
||||||
class LanguageSpecific(object):
|
|
||||||
"""Mixin for prose and text tables"""
|
|
||||||
@declared_attr
|
|
||||||
def language_id(cls):
|
|
||||||
return Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
|
|
||||||
info=dict(description="The language"))
|
|
||||||
|
|
||||||
|
|
||||||
### Need Language first, to create the partial() below
|
### Need Language first, to create the partial() below
|
||||||
|
@ -162,7 +145,7 @@ create_translation_table('ability_changelog_prose', AbilityChangelog, 'prose',
|
||||||
info=dict(description="A description of the old behavior", format='markdown'))
|
info=dict(description="A description of the old behavior", format='markdown'))
|
||||||
)
|
)
|
||||||
|
|
||||||
class AbilityFlavorText(TableBase, LanguageSpecific):
|
class AbilityFlavorText(TableBase):
|
||||||
u"""In-game flavor text of an ability
|
u"""In-game flavor text of an ability
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'ability_flavor_text'
|
__tablename__ = 'ability_flavor_text'
|
||||||
|
@ -170,6 +153,8 @@ class AbilityFlavorText(TableBase, LanguageSpecific):
|
||||||
info=dict(description="The ID of the ability"))
|
info=dict(description="The ID of the ability"))
|
||||||
version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False,
|
version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False,
|
||||||
info=dict(description="The ID of the version group this flavor text is taken from"))
|
info=dict(description="The ID of the version group this flavor text is taken from"))
|
||||||
|
language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
|
||||||
|
info=dict(description="The language"))
|
||||||
flavor_text = Column(Unicode(64), nullable=False,
|
flavor_text = Column(Unicode(64), nullable=False,
|
||||||
info=dict(description="The actual flavor text", official=True, format='gametext'))
|
info=dict(description="The actual flavor text", official=True, format='gametext'))
|
||||||
|
|
||||||
|
@ -562,7 +547,7 @@ class ItemFlagMap(TableBase):
|
||||||
item_flag_id = Column(Integer, ForeignKey('item_flags.id'), primary_key=True, autoincrement=False, nullable=False,
|
item_flag_id = Column(Integer, ForeignKey('item_flags.id'), primary_key=True, autoincrement=False, nullable=False,
|
||||||
info=dict(description="The ID of the item flag"))
|
info=dict(description="The ID of the item flag"))
|
||||||
|
|
||||||
class ItemFlavorText(TableBase, LanguageSpecific):
|
class ItemFlavorText(TableBase):
|
||||||
u"""An in-game description of an item
|
u"""An in-game description of an item
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'item_flavor_text'
|
__tablename__ = 'item_flavor_text'
|
||||||
|
@ -571,6 +556,8 @@ class ItemFlavorText(TableBase, LanguageSpecific):
|
||||||
info=dict(description="The ID of the item"))
|
info=dict(description="The ID of the item"))
|
||||||
version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, autoincrement=False, nullable=False,
|
version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, autoincrement=False, nullable=False,
|
||||||
info=dict(description="ID of the version group that sports this text"))
|
info=dict(description="ID of the version group that sports this text"))
|
||||||
|
language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
|
||||||
|
info=dict(description="The language"))
|
||||||
flavor_text = Column(Unicode(255), nullable=False,
|
flavor_text = Column(Unicode(255), nullable=False,
|
||||||
info=dict(description="The flavor text itself", official=True, format='gametext'))
|
info=dict(description="The flavor text itself", official=True, format='gametext'))
|
||||||
|
|
||||||
|
@ -814,7 +801,7 @@ create_translation_table('move_flag_type_prose', MoveFlagType, 'prose',
|
||||||
info=dict(description="A short description of the flag", format='markdown')),
|
info=dict(description="A short description of the flag", format='markdown')),
|
||||||
)
|
)
|
||||||
|
|
||||||
class MoveFlavorText(TableBase, LanguageSpecific):
|
class MoveFlavorText(TableBase):
|
||||||
u"""In-game description of a move
|
u"""In-game description of a move
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'move_flavor_text'
|
__tablename__ = 'move_flavor_text'
|
||||||
|
@ -822,6 +809,8 @@ class MoveFlavorText(TableBase, LanguageSpecific):
|
||||||
info=dict(description="ID of the move"))
|
info=dict(description="ID of the move"))
|
||||||
version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False,
|
version_group_id = Column(Integer, ForeignKey('version_groups.id'), primary_key=True, nullable=False, autoincrement=False,
|
||||||
info=dict(description="ID of the version group this text appears in"))
|
info=dict(description="ID of the version group this text appears in"))
|
||||||
|
language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
|
||||||
|
info=dict(description="The language"))
|
||||||
flavor_text = Column(Unicode(255), nullable=False,
|
flavor_text = Column(Unicode(255), nullable=False,
|
||||||
info=dict(description="The flavor text", official=True, format='gametext'))
|
info=dict(description="The flavor text", official=True, format='gametext'))
|
||||||
|
|
||||||
|
@ -1283,7 +1272,7 @@ class PokemonEvolution(TableBase):
|
||||||
trade_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=True,
|
trade_pokemon_id = Column(Integer, ForeignKey('pokemon.id'), nullable=True,
|
||||||
info=dict(description=u"The ID of the Pokémon for which this Pokémon must be traded."))
|
info=dict(description=u"The ID of the Pokémon for which this Pokémon must be traded."))
|
||||||
|
|
||||||
class PokemonFlavorText(TableBase, LanguageSpecific):
|
class PokemonFlavorText(TableBase):
|
||||||
u"""In-game Pokédex descrption of a Pokémon.
|
u"""In-game Pokédex descrption of a Pokémon.
|
||||||
"""
|
"""
|
||||||
__tablename__ = 'pokemon_flavor_text'
|
__tablename__ = 'pokemon_flavor_text'
|
||||||
|
@ -1291,6 +1280,8 @@ class PokemonFlavorText(TableBase, LanguageSpecific):
|
||||||
info=dict(description=u"ID of the Pokémon"))
|
info=dict(description=u"ID of the Pokémon"))
|
||||||
version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, nullable=False, autoincrement=False,
|
version_id = Column(Integer, ForeignKey('versions.id'), primary_key=True, nullable=False, autoincrement=False,
|
||||||
info=dict(description=u"ID of the version that has this flavor text"))
|
info=dict(description=u"ID of the version that has this flavor text"))
|
||||||
|
language_id = Column(Integer, ForeignKey('languages.id'), primary_key=True, nullable=False,
|
||||||
|
info=dict(description="The language"))
|
||||||
flavor_text = Column(Unicode(255), nullable=False,
|
flavor_text = Column(Unicode(255), nullable=False,
|
||||||
info=dict(description=u"ID of the version that has this flavor text", official=True, format='gametext'))
|
info=dict(description=u"ID of the version that has this flavor text", official=True, format='gametext'))
|
||||||
|
|
||||||
|
@ -1679,6 +1670,7 @@ Ability.dream_pokemon = relation(Pokemon,
|
||||||
AbilityChangelog.changed_in = relation(VersionGroup, backref='ability_changelog')
|
AbilityChangelog.changed_in = relation(VersionGroup, backref='ability_changelog')
|
||||||
|
|
||||||
AbilityFlavorText.version_group = relation(VersionGroup)
|
AbilityFlavorText.version_group = relation(VersionGroup)
|
||||||
|
AbilityFlavorText.language = relation(Language)
|
||||||
|
|
||||||
Berry.berry_firmness = relation(BerryFirmness, backref='berries')
|
Berry.berry_firmness = relation(BerryFirmness, backref='berries')
|
||||||
Berry.firmness = association_proxy('berry_firmness', 'name')
|
Berry.firmness = association_proxy('berry_firmness', 'name')
|
||||||
|
@ -1732,6 +1724,7 @@ ItemCategory.items = relation(Item, order_by=Item.identifier)
|
||||||
ItemCategory.pocket = relation(ItemPocket)
|
ItemCategory.pocket = relation(ItemPocket)
|
||||||
|
|
||||||
ItemFlavorText.version_group = relation(VersionGroup)
|
ItemFlavorText.version_group = relation(VersionGroup)
|
||||||
|
ItemFlavorText.language = relation(Language)
|
||||||
|
|
||||||
ItemInternalID.item = relation(Item, backref='internal_ids')
|
ItemInternalID.item = relation(Item, backref='internal_ids')
|
||||||
ItemInternalID.generation = relation(Generation)
|
ItemInternalID.generation = relation(Generation)
|
||||||
|
@ -1788,6 +1781,7 @@ MoveEffectChangelog.changed_in = relation(VersionGroup, backref='move_effect_cha
|
||||||
MoveFlag.flag = relation(MoveFlagType)
|
MoveFlag.flag = relation(MoveFlagType)
|
||||||
|
|
||||||
MoveFlavorText.version_group = relation(VersionGroup)
|
MoveFlavorText.version_group = relation(VersionGroup)
|
||||||
|
MoveFlavorText.language = relation(Language)
|
||||||
|
|
||||||
MoveMeta.category = relation(MoveMetaCategory, backref='move_meta')
|
MoveMeta.category = relation(MoveMetaCategory, backref='move_meta')
|
||||||
MoveMeta.ailment = relation(MoveMetaAilment, backref='move_meta')
|
MoveMeta.ailment = relation(MoveMetaAilment, backref='move_meta')
|
||||||
|
@ -1902,6 +1896,7 @@ PokemonEvolution.trade_pokemon = relation(Pokemon,
|
||||||
)
|
)
|
||||||
|
|
||||||
PokemonFlavorText.version = relation(Version)
|
PokemonFlavorText.version = relation(Version)
|
||||||
|
PokemonFlavorText.language = relation(Language)
|
||||||
|
|
||||||
PokemonForm.form_base_pokemon = relation(Pokemon, primaryjoin=PokemonForm.form_base_pokemon_id==Pokemon.id)
|
PokemonForm.form_base_pokemon = relation(Pokemon, primaryjoin=PokemonForm.form_base_pokemon_id==Pokemon.id)
|
||||||
PokemonForm.unique_pokemon = relation(Pokemon, backref=backref('unique_form', uselist=False),
|
PokemonForm.unique_pokemon = relation(Pokemon, backref=backref('unique_form', uselist=False),
|
||||||
|
@ -1972,12 +1967,6 @@ VersionGroup.version_group_regions = relation(VersionGroupRegion, backref='versi
|
||||||
VersionGroup.regions = association_proxy('version_group_regions', 'region')
|
VersionGroup.regions = association_proxy('version_group_regions', 'region')
|
||||||
VersionGroup.pokedex = relation(Pokedex, back_populates='version_groups')
|
VersionGroup.pokedex = relation(Pokedex, back_populates='version_groups')
|
||||||
|
|
||||||
|
|
||||||
### Add language relations
|
|
||||||
for table in list(table_classes):
|
|
||||||
if issubclass(table, LanguageSpecific):
|
|
||||||
table.language = relation(Language, primaryjoin=table.language_id == Language.id)
|
|
||||||
|
|
||||||
Move.effect = markdown.MoveEffectProperty('effect')
|
Move.effect = markdown.MoveEffectProperty('effect')
|
||||||
Move.effect_map = markdown.MoveEffectProperty('effect_map')
|
Move.effect_map = markdown.MoveEffectProperty('effect_map')
|
||||||
Move.short_effect = markdown.MoveEffectProperty('short_effect')
|
Move.short_effect = markdown.MoveEffectProperty('short_effect')
|
||||||
|
|
Loading…
Reference in a new issue