Here are the examples of the python api sqlalchemy_utils.TranslationHybrid taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
Example 1
Project: sqlalchemy-utils Source File: test_translation_hybrid.py
def test_dynamic_locale(self, Base):
translation_hybrid = TranslationHybrid(
lambda obj: obj.locale,
'fi'
)
class Article(Base):
__tablename__ = 'article'
id = sa.Column(sa.Integer, primary_key=True)
name_translations = sa.Column(HSTORE)
name = translation_hybrid(name_translations)
locale = sa.Column(sa.String)
assert (
'coalesce(article.name_translations -> article.locale'
in str(Article.name.expression)
)
3
Example 2
Project: sqlalchemy-utils Source File: test_translation_hybrid.py
def test_locales_casted_only_in_compilation_phase(self, Base):
class LocaleGetter(object):
def current_locale(self):
return lambda obj: obj.locale
flexmock(LocaleGetter).should_receive('current_locale').never()
translation_hybrid = TranslationHybrid(
LocaleGetter().current_locale,
'fi'
)
class Article(Base):
__tablename__ = 'article'
id = sa.Column(sa.Integer, primary_key=True)
name_translations = sa.Column(HSTORE)
name = translation_hybrid(name_translations)
locale = sa.Column(sa.String)
Article.name
0
Example 3
Project: sqlalchemy-utils Source File: test_translation_hybrid.py
@pytest.fixture
def translation_hybrid():
return TranslationHybrid('fi', 'en')