示例#1
0
    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))
示例#2
0
    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
示例#3
0
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)
示例#4
0
def translation_hybrid():
    return TranslationHybrid('fi', 'en')
 def setup_method(self, method):
     self.translation_hybrid = TranslationHybrid('fi', 'en')
     TestCase.setup_method(self, method)
示例#6
0
            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():