Use DefaultLangProperty for Markdown columns

This commit is contained in:
Petr Viktorin 2011-03-13 17:08:18 +02:00 committed by Eevee
parent e5f7cd2aed
commit 7c039115ee
2 changed files with 10 additions and 31 deletions

View file

@ -77,27 +77,6 @@ class _MoveEffects(object):
return MarkdownString(effect_text) return MarkdownString(effect_text)
class MoveEffectProperty(object):
"""Property that wraps a move effect. Used like this:
MoveClass.effect = MoveEffectProperty('effect')
some_move.effect # returns a MarkdownString
some_move.effect.as_html # returns a chunk of HTML
This class also performs simple substitution on the effect, replacing
`$effect_chance` with the move's actual effect chance.
"""
def __init__(self, effect_column):
self.effect_column = effect_column
def __get__(self, move, move_class):
if move is None:
# Don't crash with getattr on the class
return NotImplemented
return _MoveEffects(self.effect_column, move)['en']
class MoveEffectsProperty(object): class MoveEffectsProperty(object):
"""Property that wraps move effects. Used like this: """Property that wraps move effects. Used like this:

View file

@ -1572,20 +1572,10 @@ Move.super_contest_combo_prev = association_proxy('super_contest_combo_second',
Move.target = relation(MoveTarget, backref='moves') Move.target = relation(MoveTarget, backref='moves')
Move.type = relation(Type, back_populates='moves') Move.type = relation(Type, back_populates='moves')
Move.effect = markdown.MoveEffectProperty('effect')
Move.effects = markdown.MoveEffectsProperty('effect')
Move.short_effect = markdown.MoveEffectProperty('short_effect')
Move.short_effects = markdown.MoveEffectsProperty('short_effect')
MoveChangelog.changed_in = relation(VersionGroup, backref='move_changelog') MoveChangelog.changed_in = relation(VersionGroup, backref='move_changelog')
MoveChangelog.move_effect = relation(MoveEffect, backref='move_changelog') MoveChangelog.move_effect = relation(MoveEffect, backref='move_changelog')
MoveChangelog.type = relation(Type, backref='move_changelog') MoveChangelog.type = relation(Type, backref='move_changelog')
MoveChangelog.effect = markdown.MoveEffectProperty('effect')
MoveChangelog.effects = markdown.MoveEffectsProperty('effect')
MoveChangelog.short_effect = markdown.MoveEffectProperty('short_effect')
MoveChangelog.short_effects = markdown.MoveEffectsProperty('short_effect')
MoveEffect.category_map = relation(MoveEffectCategoryMap) MoveEffect.category_map = relation(MoveEffectCategoryMap)
MoveEffect.categories = association_proxy('category_map', 'category') MoveEffect.categories = association_proxy('category_map', 'category')
MoveEffect.changelog = relation(MoveEffectChangelog, MoveEffect.changelog = relation(MoveEffectChangelog,
@ -1944,3 +1934,13 @@ for table in list(table_classes):
for table in list(table_classes): for table in list(table_classes):
if issubclass(table, LanguageSpecific): if issubclass(table, LanguageSpecific):
table.language = relation(Language, primaryjoin=table.language_id == Language.id) table.language = relation(Language, primaryjoin=table.language_id == Language.id)
Move.effect = DefaultLangProperty('effects')
Move.effects = markdown.MoveEffectsProperty('effect')
Move.short_effect = DefaultLangProperty('short_effects')
Move.short_effects = markdown.MoveEffectsProperty('short_effect')
MoveChangelog.effect = DefaultLangProperty('effects')
MoveChangelog.effects = markdown.MoveEffectsProperty('effect')
MoveChangelog.short_effect = DefaultLangProperty('short_effects')
MoveChangelog.short_effects = markdown.MoveEffectsProperty('short_effect')