Remove the responsibility of setting a default language from multilang.
[zzz-pokedex.git] / pokedex / db / multilang.py
index 6690b8a..bd4266f 100644 (file)
@@ -154,26 +154,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):
-        try:
-            self.language_class = kwargs.pop('language_class')
-        except KeyError:
-            # Set the default language_class
-            # We need to import here, to prevent a circular depencency
-            from pokedex.db.tables import Language
-            self.language_class = Language
+        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(self.language_class)
-        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):