当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_language函数代码示例

本文整理汇总了Python中modeltranslation.utils.get_language函数的典型用法代码示例。如果您正苦于以下问题:Python get_language函数的具体用法?Python get_language怎么用?Python get_language使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_language函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rewrite_lookup_key

def rewrite_lookup_key(model, lookup_key):
    translatable_fields = get_translatable_fields_for_model(model)
    if translatable_fields is not None:
        pieces = lookup_key.split('__')
        # If we are doing a lookup on a translatable field,
        # we want to rewrite it to the actual field name
        # For example, we want to rewrite "name__startswith" to "name_fr__startswith"
        if pieces[0] in translatable_fields:
            lookup_key = build_localized_fieldname(pieces[0], get_language())

            remaining_lookup = '__'.join(pieces[1:])
            if remaining_lookup:
                lookup_key = '%s__%s' % (lookup_key, remaining_lookup)

    pieces = lookup_key.split('__')
    if len(pieces) > 1:
        # Check if we are doing a lookup to a related trans model
        fields_to_trans_models = get_fields_to_translatable_models(model)
        for field_to_trans, transmodel in fields_to_trans_models:
            if pieces[0] == field_to_trans:
                sub_lookup = '__'.join(pieces[1:])
                if sub_lookup:
                    sub_lookup = rewrite_lookup_key(transmodel, sub_lookup)
                    lookup_key = '%s__%s' % (pieces[0], sub_lookup)
                break

    return lookup_key
开发者ID:pigletto,项目名称:django-modeltranslation,代码行数:27,代码来源:manager.py

示例2: pre_save

 def pre_save(self, model_instance, add):
     val = super(TranslationField, self).pre_save(model_instance, add)
     if get_language() == self.language and not add:
         # Rule is: 3. Assigning a value to a translation field of the
         # default language also updates the original field
         model_instance.__dict__[self.translated_field.name] = val
     return val
开发者ID:BibliotekaOtwartejNauki,项目名称:wolnelektury,代码行数:7,代码来源:fields.py

示例3: __get__

 def __get__(self, instance, owner):
     """
     Returns value from the translation field for the current language, or
     value for some another language according to fallback languages, or the
     custom fallback value, or field's default value.
     """
     if instance is None:
         return self
     default = NONE
     undefined = self.fallback_undefined
     if undefined is NONE:
         default = self.field.get_default()
         undefined = default
     langs = resolution_order(get_language(), self.fallback_languages)
     for lang in langs:
         loc_field_name = build_localized_fieldname(self.field.name, lang)
         val = getattr(instance, loc_field_name, None)
         if val is not None and val != undefined:
             return val
     if mt_settings.ENABLE_FALLBACKS and self.fallback_value is not NONE:
         return self.fallback_value
     else:
         if default is NONE:
             default = self.field.get_default()
         return default
开发者ID:masterdubs,项目名称:django-modeltranslation,代码行数:25,代码来源:fields.py

示例4: formfield_exclude_irrelevant

def formfield_exclude_irrelevant(db_field, **kwargs):
    """ only localized fields """
    from modeltranslation.translator import translator
    from modeltranslation.utils import get_language
    trans_opts = translator.get_options_for_model(db_field.model)
    if db_field.name in trans_opts.fields:
        return None
    if 'field' in kwargs:
        field = kwargs['field']
    else:
        field = db_field.formfield(**kwargs)
    if hasattr(db_field, 'translated_field'):
        if db_field.name.endswith('_{0}'.format(get_language())):
            field.required = True
            field.widget.attrs['class'] = '{0} {1}'.format(
                getattr(field.widget.attrs, 'class', ''),
                'language-depended'
            )
            field.help_text = string_concat(
                field.help_text,
                _(' '),
                _('This field dependent on current language.')
            )
        else:
            return None
    return field
开发者ID:liminspace,项目名称:dj-utils,代码行数:26,代码来源:modeltranslation.py

示例5: cache_name

 def cache_name(self):
     """
     Used in django 1.x
     """
     lang = get_language()
     cache = build_localized_fieldname(self.accessor, lang)
     return "_%s_cache" % cache
开发者ID:deschler,项目名称:django-modeltranslation,代码行数:7,代码来源:fields.py

示例6: __get__

 def __get__(self, instance, owner):
     """
     Returns value from the translation field for the current language, or
     value for some another language according to fallback languages, or the
     custom fallback value, or field's default value.
     """
     if instance is None:
         return self
     default = NONE
     undefined = self.fallback_undefined
     if undefined is NONE:
         default = self.field.get_default()
         undefined = default
     langs = resolution_order(get_language(), self.fallback_languages)
     for lang in langs:
         loc_field_name = build_localized_fieldname(self.field.name, lang)
         val = getattr(instance, loc_field_name, None)
         if self.meaningful_value(val, undefined):
             return val
     if mt_settings.ENABLE_FALLBACKS and self.fallback_value is not NONE:
         return self.fallback_value
     else:
         if default is NONE:
             default = self.field.get_default()
         # Some fields like FileField behave strange, as their get_default() doesn't return
         # instance of attr_class, but rather None or ''.
         # Normally this case is handled in the descriptor, but since we have overridden it, we
         # must mock it up.
         if (isinstance(self.field, fields.files.FileField) and
                 not isinstance(default, self.field.attr_class)):
             return self.field.attr_class(instance, self.field, default)
         return default
开发者ID:GDGLima,项目名称:contentbox,代码行数:32,代码来源:fields.py

示例7: _validate_slugs

def _validate_slugs(page):
    """
    Determine whether the given slug is available for use on a child page of
    parent_page.
    """
    parent_page = page.get_parent()

    if parent_page is None:
        # the root page's slug can be whatever it likes...
        return {}

    # Save the current active language
    current_language = get_language()

    siblings = page.get_siblings(inclusive=False).specific()

    errors = {}

    for language in mt_settings.AVAILABLE_LANGUAGES:
        # Temporarily activate every language because even though there might
        # be no repeated value for slug_pt the fallback of an empty slug could
        # already be in use

        trans_real.activate(language)

        siblings_slugs = [sibling.slug for sibling in siblings]

        if page.specific.slug in siblings_slugs:
            errors[build_localized_fieldname('slug', language)] = _("This slug is already in use")

    # Re-enable the original language
    trans_real.activate(current_language)

    return errors
开发者ID:sinnwerkstatt,项目名称:wagtail-modeltranslation,代码行数:34,代码来源:patch_wagtailadmin.py

示例8: __set__

 def __set__(self, instance, value):
     lang = get_language()
     loc_field_name = build_localized_fieldname(self.field_name, lang)
     # Localized field name with '_id'
     loc_attname = instance._meta.get_field(loc_field_name).get_attname()
     setattr(instance, loc_attname, value)
     base_attname = instance._meta.get_field(self.field_name).get_attname()
     instance.__dict__[base_attname] = value
开发者ID:deschler,项目名称:django-modeltranslation,代码行数:8,代码来源:fields.py

示例9: keywords_list_language

 def keywords_list_language(self, lang=None):
     if not lang:
         lang = get_language() or DEFAULT_LANGUAGE
     keywords = []
     list = self.keywords_list()
     for k in list:
         keywords.append([k[0][lang], k[1], k[2], k[0][lang].split('>')[-1].strip()])
     return keywords
开发者ID:paulck,项目名称:Anteo,代码行数:8,代码来源:models.py

示例10: __set__

 def __set__(self, instance, value):
     lang = get_language()
     loc_field_name = build_localized_fieldname(self.name, lang)
     # also update the translation field of the current language
     setattr(instance, loc_field_name, value)
     # update the original field via the __dict__ to prevent calling the
     # descriptor
     instance.__dict__[self.name] = value
开发者ID:umdsp,项目名称:romeu,代码行数:8,代码来源:fields.py

示例11: __set__

 def __set__(self, instance, value):
     if getattr(instance, '_mt_init', False):
         # When assignment takes place in model instance constructor, don't set value.
         # This is essential for only/defer to work, but I think it's sensible anyway.
         return
     lang = get_language()
     loc_field_name = build_localized_fieldname(self.field.name, lang)
     # also update the translation field of the current language
     setattr(instance, loc_field_name, value)
开发者ID:20tab,项目名称:django-modeltranslation,代码行数:9,代码来源:fields.py

示例12: keywords_list_clean

 def keywords_list_clean(self, lang=None):
     if not lang:
         lang = get_language() or DEFAULT_LANGUAGE
     keywords = []
     if self.gemetkeywords is not None and self.gemetkeywords != '':
         list = json.loads(self.gemetkeywords)
         for k in list:
             keywords.append(k[0][lang].split('>')[-1].strip())
     return keywords
开发者ID:paulck,项目名称:Anteo,代码行数:9,代码来源:models.py

示例13: save_form_data

 def save_form_data(self, instance, data):
     # Allow 3rd-party apps forms to be saved using only translated field name.
     # When translated field (e.g. 'name') is specified and translation field (e.g. 'name_en')
     # not, we assume that form was saved without knowledge of modeltranslation and we make
     # things right:
     # Translated field is saved first, settings respective translation field value. Then
     # translation field is being saved without value - and we handle this here (only for
     # active language).
     if self.language == get_language() and getattr(instance, self.name) and not data:
         return
     super(TranslationField, self).save_form_data(instance, data)
开发者ID:20tab,项目名称:django-modeltranslation,代码行数:11,代码来源:fields.py

示例14: lbyl

def lbyl(terms, lang_priority = None):
    terms_dict = {}
    if not lang_priority:
        lang_priority = [get_language(), DEFAULT_LANGUAGE]
    for i in terms:
        terms_dict[i.language] = i
    for lang in lang_priority:
        value = terms_dict.get(lang)
        if value is not None:
            return value
    return terms.first
开发者ID:paulck,项目名称:Anteo,代码行数:11,代码来源:views_rdf.py

示例15: _patch_prepopulated_fields

 def _patch_prepopulated_fields(self):
     if self.prepopulated_fields:
         # TODO: Perhaps allow to configure which language the slug should be based on?
         lang = get_language()
         prepopulated_fields_new = dict(self.prepopulated_fields)
         translation_fields = []
         for k, v in self.prepopulated_fields.items():
             for i in v:
                 if i in self.trans_opts.fields.keys():
                     translation_fields.append(build_localized_fieldname(i, lang))
             prepopulated_fields_new[k] = tuple(translation_fields)
         self.prepopulated_fields = prepopulated_fields_new
开发者ID:acdha,项目名称:django-modeltranslation,代码行数:12,代码来源:admin.py


注:本文中的modeltranslation.utils.get_language函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。