From: Eevee Date: Sun, 3 Apr 2011 08:25:59 +0000 (-0700) Subject: Split up MoveEffectProperty; don't detect dict proxies. X-Git-Tag: veekun-promotions/2011041101~14 X-Git-Url: http://git.veekun.com/zzz-pokedex.git/commitdiff_plain/2fee7534634e0f96094500811ae88b2bfae94fc6 Split up MoveEffectProperty; don't detect dict proxies. (It didn't work anyway!) --- diff --git a/pokedex/db/markdown.py b/pokedex/db/markdown.py index dd86746..616830a 100644 --- a/pokedex/db/markdown.py +++ b/pokedex/db/markdown.py @@ -72,12 +72,10 @@ class MoveEffectProperty(object): some_move.effect # returns a MarkdownString some_move.effect.as_html # returns a chunk of HTML - This class attempts to detect if the wrapped property is a dict-based - association proxy, and will act like such a dict if so. Don't rely on it - for querying, of course. - This class also performs simple substitution on the effect, replacing `$effect_chance` with the move's actual effect chance. + + Use `MoveEffectPropertyMap` for dict-like association proxies. """ def __init__(self, effect_column): @@ -85,16 +83,19 @@ class MoveEffectProperty(object): def __get__(self, obj, cls): prop = getattr(obj.move_effect, self.effect_column) - if isinstance(prop, dict): - # Looks like a dict proxy; markdownify everyone - newdict = dict(prop) - for key in newdict: - newdict[key] = _markdownify_effect_text(obj, newdict[key]) - return newdict - - # Otherwise, scalar prop. Boring return _markdownify_effect_text(obj, prop) +class MoveEffectPropertyMap(MoveEffectProperty): + """Similar to `MoveEffectProperty`, but works on dict-like association + proxies. + """ + def __get__(self, obj, cls): + prop = getattr(obj.move_effect, self.effect_column) + newdict = dict(prop) + for key in newdict: + newdict[key] = _markdownify_effect_text(obj, newdict[key]) + return newdict + class MarkdownColumn(sqlalchemy.types.TypeDecorator): """Generic SQLAlchemy column type for Markdown text. diff --git a/pokedex/db/tables.py b/pokedex/db/tables.py index a182730..d96b965 100644 --- a/pokedex/db/tables.py +++ b/pokedex/db/tables.py @@ -1781,18 +1781,18 @@ Move.target = relation(MoveTarget, backref='moves') Move.type = relation(Type, backref='moves') Move.effect = markdown.MoveEffectProperty('effect') -Move.effect_map = markdown.MoveEffectProperty('effect_map') +Move.effect_map = markdown.MoveEffectPropertyMap('effect_map') Move.short_effect = markdown.MoveEffectProperty('short_effect') -Move.short_effect_map = markdown.MoveEffectProperty('short_effect_map') +Move.short_effect_map = markdown.MoveEffectPropertyMap('short_effect_map') MoveChangelog.changed_in = relation(VersionGroup, backref='move_changelog') MoveChangelog.move_effect = relation(MoveEffect, backref='move_changelog') MoveChangelog.type = relation(Type, backref='move_changelog') MoveChangelog.effect = markdown.MoveEffectProperty('effect') -MoveChangelog.effect_map = markdown.MoveEffectProperty('effect_map') +MoveChangelog.effect_map = markdown.MoveEffectPropertyMap('effect_map') MoveChangelog.short_effect = markdown.MoveEffectProperty('short_effect') -MoveChangelog.short_effect_map = markdown.MoveEffectProperty('short_effect_map') +MoveChangelog.short_effect_map = markdown.MoveEffectPropertyMap('short_effect_map') MoveEffect.category_map = relation(MoveEffectCategoryMap) MoveEffect.categories = association_proxy('category_map', 'category')