python类smart_text()的实例源码

filters.py 文件源码 项目:sdining 作者: Lurance 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def choices(self):
        yield {
            'selected': (self.lookup_exact_val is '' and self.lookup_isnull_val is ''),
            'query_string': self.query_string({}, [self.lookup_exact_name, self.lookup_isnull_name]),
            'display': _('All'),
        }
        include_none = False
        for val in self.lookup_choices:
            if val is None:
                include_none = True
                continue
            val = smart_text(val)
            yield {
                'selected': self.lookup_exact_val == val,
                'query_string': self.query_string({self.lookup_exact_name: val},
                                                  [self.lookup_isnull_name]),
                'display': val,
            }
        if include_none:
            yield {
                'selected': bool(self.lookup_isnull_val),
                'query_string': self.query_string({self.lookup_isnull_name: 'True'},
                                                  [self.lookup_exact_name]),
                'display': EMPTY_CHANGELIST_VALUE,
            }
util.py 文件源码 项目:sdining 作者: Lurance 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def display_for_field(value, field):
    from xadmin.views.list import EMPTY_CHANGELIST_VALUE

    if field.flatchoices:
        return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
    # NullBooleanField needs special-case null-handling, so it comes
    # before the general null test.
    elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
        return boolean_icon(value)
    elif value is None:
        return EMPTY_CHANGELIST_VALUE
    elif isinstance(field, models.DateTimeField):
        return formats.localize(tz_localtime(value))
    elif isinstance(field, (models.DateField, models.TimeField)):
        return formats.localize(value)
    elif isinstance(field, models.DecimalField):
        return formats.number_format(value, field.decimal_places)
    elif isinstance(field, models.FloatField):
        return formats.number_format(value)
    elif isinstance(field.rel, models.ManyToManyRel):
        return ', '.join([smart_text(obj) for obj in value.all()])
    else:
        return smart_text(value)
xversion.py 文件源码 项目:sdining 作者: Lurance 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_related_versions(self, obj, version, formset):
        """Retreives all the related Version objects for the given FormSet."""
        object_id = obj.pk
        # Get the fk name.
        try:
            fk_name = formset.fk.name + '_' + formset.fk.rel.get_related_field().name
        except AttributeError:
            # This is a GenericInlineFormset, or similar.
            fk_name = formset.ct_fk_field.name
        # Look up the revision data.
        revision_versions = version.revision.version_set.all()
        related_versions = dict([(related_version.object_id, related_version)
                                 for related_version in revision_versions
                                 if ContentType.objects.get_for_id(related_version.content_type_id).model_class() == formset.model
                                 and smart_text(related_version.field_dict[fk_name]) == smart_text(object_id)])
        return related_versions
editable.py 文件源码 项目:sdining 作者: Lurance 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def _get_new_field_html(self, field_name):
        try:
            f, attr, value = lookup_field(field_name, self.org_obj, self)
        except (AttributeError, ObjectDoesNotExist):
            return EMPTY_CHANGELIST_VALUE
        else:
            allow_tags = False
            if f is None:
                allow_tags = getattr(attr, 'allow_tags', False)
                boolean = getattr(attr, 'boolean', False)
                if boolean:
                    allow_tags = True
                    text = boolean_icon(value)
                else:
                    text = smart_text(value)
            else:
                if isinstance(f.rel, models.ManyToOneRel):
                    field_val = getattr(self.org_obj, f.name)
                    if field_val is None:
                        text = EMPTY_CHANGELIST_VALUE
                    else:
                        text = field_val
                else:
                    text = display_for_field(value, f)
            return mark_safe(text) if allow_tags else conditional_escape(text)
forms.py 文件源码 项目:tumanov_castleoaks 作者: Roamdev 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def __iter__(self):
        if self.field.group_by is None:
            yield from super().__iter__()
            return

        if self.field.empty_label is not None:
            yield ("", self.field.empty_label)

        qs = self.queryset
        if self.field.is_relation:
            if self.field.group_by not in qs.query.order_by:
                qs.query.order_by.insert(0, self.field.group_by)
            qs = qs.select_related(self.field.group_by)

        groups = groupby(
            qs.all(),
            key=lambda row: getattr(row, self.field.group_by)
        )
        for group, choices in groups:
            yield smart_text(group), [self.choice(ch) for ch in choices]
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{}".format(smart_text(self.name))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __str__(self):
        return u"{}".format(smart_text(self.description_short))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __str__(self):
        if self.code:
            return u"{} ({})".format(smart_text(getattr(self, settings.LANGUAGES_DATABASES[0].lower()).name), smart_text(self.code))
        else:
            return u"{}".format(smart_text(getattr(self, settings.LANGUAGES_DATABASES[0].lower()).name))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __str__(self):
        if self.code:
            return u"{} ({})".format(smart_text(getattr(self, settings.LANGUAGES_DATABASES[0].lower()).name), smart_text(self.code))
        else:
            return u"{}".format(smart_text(getattr(self, settings.LANGUAGES_DATABASES[0].lower()).name))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def __str__(self):
        if self.code:
            return u"{} ({})".format(smart_text(getattr(self, settings.LANGUAGES_DATABASES[0].lower()).name), smart_text(self.code))
        else:
            return u"{}".format(smart_text(getattr(self, settings.LANGUAGES_DATABASES[0].lower()).name))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __unicode__(self):
        name_res = _("Missing brand name")
        for lang_code, lang_name in settings.LANGUAGES:
            translation = getattr(self, lang_code.lower(), None)
            if translation is not None:
                if translation.name and len(translation.name) > 0:
                    name_res = u"{}".format(smart_text(translation.name))
                else:
                    name_res = u"{}".format(smart_text(translation.slug))
        return name_res
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{}".format(smart_text(self.code))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{} ({})".format(smart_text(self.product), smart_text(self.hits))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{} ({})".format(smart_text(self.product), smart_text(self.order))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{}".format(smart_text(self.product))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{} ({})".format(smart_text(self.product_final), smart_text(self.order))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{}".format(smart_text(self.product))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{}".format(smart_text(self.product_final))
models.py 文件源码 项目:django-codenerix-products 作者: centrologic 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __unicode__(self):
        return u"{}".format(smart_text(self.product_final))
django_orm.py 文件源码 项目:oscars2016 作者: 0x0ece 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_prep_value(self, value):
        if value is None:
            return None
        return smart_text(base64.b64encode(pickle.dumps(value)))


问题


面经


文章

微信
公众号

扫码关注公众号