From 3a59ef1fe0a540d9bb4f1264bee89d8e5c423227 Mon Sep 17 00:00:00 2001 From: Eevee Date: Sun, 4 Sep 2011 23:18:36 -0700 Subject: [PATCH] Update us to SQLAlchemy 0.7. #582 --- pokedex/db/multilang.py | 26 ++++++++++---------------- setup.py | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/pokedex/db/multilang.py b/pokedex/db/multilang.py index 8720dcb..5b3ecbb 100644 --- a/pokedex/db/multilang.py +++ b/pokedex/db/multilang.py @@ -1,7 +1,7 @@ from functools import partial from sqlalchemy.ext.associationproxy import association_proxy -from sqlalchemy.orm import aliased, compile_mappers, mapper, relationship, synonym +from sqlalchemy.orm import Query, aliased, mapper, relationship, synonym from sqlalchemy.orm.collections import attribute_mapped_collection from sqlalchemy.orm.scoping import ScopedSession from sqlalchemy.orm.session import Session, object_session @@ -180,6 +180,13 @@ def create_translation_table(_table_name, foreign_class, relation_name, # Done return Translations +class MultilangQuery(Query): + def __iter__(self): + if '_default_language_id' not in self._params: + self._params = self._params.copy() + self._params['_default_language_id'] = self.session.default_language_id + return super(MultilangQuery, self).__iter__() + class MultilangSession(Session): """A tiny Session subclass that adds support for a default language. @@ -193,22 +200,13 @@ class MultilangSession(Session): self.pokedex_link_maker = markdown.MarkdownLinkMaker(self) + kwargs.setdefault('query_cls', MultilangQuery) + super(MultilangSession, self).__init__(*args, **kwargs) - def execute(self, clause, params=None, *args, **kwargs): - if not params: - params = {} - params.setdefault('_default_language_id', self.default_language_id) - - return super(MultilangSession, self).execute( - clause, params, *args, **kwargs) - class MultilangScopedSession(ScopedSession): """Dispatches language selection to the attached Session.""" - def __init__(self, *args, **kwargs): - super(MultilangScopedSession, self).__init__(*args, **kwargs) - @property def default_language_id(self): """Passes the new default language id through to the current session. @@ -224,7 +222,3 @@ class MultilangScopedSession(ScopedSession): """Passes the new link maker through to the current session. """ return self.registry().pokedex_link_maker - - @pokedex_link_maker.setter - def pokedex_link_maker(self, new): - self.registry().pokedex_link_maker = new diff --git a/setup.py b/setup.py index 3bc7028..9613ae8 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( 'pokedex': ['data/csv/*.csv'] }, install_requires=[ - 'SQLAlchemy>=0.6.6', + 'SQLAlchemy>=0.7', 'whoosh>=1.1.0', 'markdown', 'construct',