X-Git-Url: http://git.veekun.com/zzz-pokedex.git/blobdiff_plain/06545f5b48416ba0507d26499db2d57d6d69e13b..b668cf69b068d647af6d9cb394dbff7c2d0a78bf:/pokedex/db/multilang.py?ds=sidebyside diff --git a/pokedex/db/multilang.py b/pokedex/db/multilang.py index b5f87e4..d58f6df 100644 --- a/pokedex/db/multilang.py +++ b/pokedex/db/multilang.py @@ -99,7 +99,8 @@ def create_translation_table(_table_name, foreign_class, relation_name, '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 @@ -154,16 +155,22 @@ def create_translation_table(_table_name, foreign_class, relation_name, 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): - # Need to import tables here to avoid a circular dependency - from pokedex.db import tables - query = self.query(tables.Language) - query = query.filter_by(id=self._default_language_id) - return query.one() + return self.query(self.language_class) \ + .filter_by(id=self._default_language_id) \ + .one() @default_language.setter def default_language(self, new): @@ -193,7 +200,3 @@ class MultilangScopedSession(ScopedSession): @default_language.setter def default_language(self, new): self.registry().default_language = new - - def remove(self): - del self.registry().default_language - super(MultilangScopedSession, self).remove()