On 24/01/2010 16:57, werner wrote:
...
Next thing is to make "_get_translation" reusable for different tables.
I got it down to this:
def _do_translation(bInstance, tTable, fCrit, cLang, dLang):
try:
x =
sao.object_session(bInstance).query(tTable).with_parent(bInstance).filter(fCrit==cLang)
return x.one()
except sao.exc.NoResultFound:
try:
x =
sao.object_session(bInstance).query(tTable).with_parent(bInstance).filter(fCrit==dLang)
return x.one()
except sao.exc.NoResultFound:
return 'no translation found'
class Country_B(Base):
__table__ = sa.Table(u'countries_b', metadata,
sa.Column(u'id', sa.Integer(), sa.Sequence('countries_b_id'),
primary_key=True, nullable=False),
..
)
def _get_translation(self):
return _do_translation(self, Country_T, Country_T.lang_code5,
getCurrentUserLang, getDefaultUserLang)
country_t = sao.relation('Country_T', backref='country_b')
country = property(_get_translation)
But would like to remove the "def _get_translation" and call directly
_do_translation, something like this:
country = property(_do_translation('Country_B', 'Country_T',
'lang_code5', getCurrentUserLang, getDefaultUserLang))
But can't figure out how I would then get at the instance of "Country_B"
within _do_translation.
As always tips or pointers to documentation are very appreciated.
Werner
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.