From: Eevee Date: Wed, 6 Apr 2011 04:04:32 +0000 (-0700) Subject: Merge branch 'encukou' X-Git-Tag: veekun-promotions/2011041101~8 X-Git-Url: http://git.veekun.com/zzz-pokedex.git/commitdiff_plain/a04865183fefdd58b0de1cea7c69a9b04a408e53?hp=-c Merge branch 'encukou' --- a04865183fefdd58b0de1cea7c69a9b04a408e53 diff --combined pokedex/db/multilang.py index dcbe489,bd4266f..3274f61 --- a/pokedex/db/multilang.py +++ b/pokedex/db/multilang.py @@@ -99,8 -99,7 +99,8 @@@ def create_translation_table(_table_nam 'foreign_id': synonym(foreign_key_name), 'local_language': relationship(language_class, primaryjoin=table.c.local_language_id == language_class.id, - innerjoin=True), + innerjoin=True, + lazy='joined'), }) # Add full-table relations to the original class @@@ -155,17 -154,26 +155,26 @@@ return Translations class MultilangSession(Session): - """A tiny Session subclass that adds support for a default language.""" - _default_language_id = 9 # English. XXX magic constant + """A tiny Session subclass that adds support for a default language. + + Caller will need to assign something to `default_language` before this will + actually work. + """ + _default_language_id = 0 # Better fill this in, caller + + def __init__(self, *args, **kwargs): + self.language_class = kwargs.pop('language_class') + super(MultilangSession, self).__init__(*args, **kwargs) @property def default_language(self): - # XXX need to get the right mapped class for this to work - raise NotImplementedError + return self.query(self.language_class) \ + .filter_by(id=self._default_language_id) \ + .one() @default_language.setter def default_language(self, new): - self._default_language_id = new#.id + self._default_language_id = new.id @default_language.deleter def default_language(self):