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))
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
def make_translation_hybrid(column): global translation_hybrid if translation_hybrid is None: translation_hybrid = TranslationHybrid(current_locale=get_locale, default_locale=default_locale) return translation_hybrid(column)
def translation_hybrid(): return TranslationHybrid('fi', 'en')
def setup_method(self, method): self.translation_hybrid = TranslationHybrid('fi', 'en') TestCase.setup_method(self, method)
return '' # checking for the default locale for a model instance if locale in attribute.keys(): return locale else: try: return sorted(attribute.keys())[0] except IndexError: return '' # return default deployment locale return locale translation_hybrid = TranslationHybrid(current_locale=get_locale, default_locale=get_default_locale) class CRUDMixin(object): '''CRUD mixin class''' @classmethod def create(cls, **kwargs): instance = cls(**kwargs) return instance.save() @declared_attr def uuid(self): return db.Column(UUID(as_uuid=True), default=uuid4, nullable=False) def update(self, commit=True, **kwargs): for attr, value in kwargs.items():