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


Python functional.Promise方法代码示例

本文整理汇总了Python中django.utils.functional.Promise方法的典型用法代码示例。如果您正苦于以下问题:Python functional.Promise方法的具体用法?Python functional.Promise怎么用?Python functional.Promise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.utils.functional的用法示例。


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

示例1: field_display

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def field_display(field, safe=False):
    out = []
    if isinstance(field.field.widget, (forms.widgets.RadioSelect, forms.widgets.CheckboxSelectMultiple)):
        out.append('<div class="field radio">%s</div>' % (str(field)))
    else:
        out.append('<div class="field">%s</div>' % (str(field)))
    out.append(str(field.errors))

    if field.help_text:
        if isinstance(field.help_text, Promise):
            out.append('<div class="helptext">%s</div>' % (escape(field.help_text)))
        else:
            if safe:
                out.append('<div class="helptext">%s</div>' % (field.help_text))
            else:
                out.append('<div class="helptext">%s</div>' % (escape(field.help_text)))
    return mark_safe('\n'.join(out)) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:form_display.py

示例2: mark_safe

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def mark_safe(s):
    """
    Explicitly mark a string as safe for (HTML) output purposes. The returned
    object can be used everywhere a string is appropriate.

    If used on a method as a decorator, mark the returned data as safe.

    Can be called multiple times on a single string.
    """
    if hasattr(s, '__html__'):
        return s
    if isinstance(s, (str, Promise)):
        return SafeText(s)
    if callable(s):
        return _safety_decorator(mark_safe, s)
    return SafeText(str(s)) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:18,代码来源:safestring.py

示例3: force_bytes

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
    """
    Similar to smart_bytes, except that lazy instances are resolved to
    strings, rather than kept as lazy objects.

    If strings_only is True, don't convert (some) non-string-like objects.
    """
    # Handle the common case first for performance reasons.
    if isinstance(s, bytes):
        if encoding == 'utf-8':
            return s
        else:
            return s.decode('utf-8', errors).encode(encoding, errors)
    if strings_only and is_protected_type(s):
        return s
    if isinstance(s, memoryview):
        return bytes(s)
    if isinstance(s, Promise) or not isinstance(s, str):
        return str(s).encode(encoding, errors)
    else:
        return s.encode(encoding, errors) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:23,代码来源:encoding.py

示例4: get_model_fields

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def get_model_fields(model, base=None):
    list = []
    fields = model._meta.fields
    for f in fields:
        label = f.name
        if hasattr(f, 'verbose_name'):
            label = getattr(f, 'verbose_name')

        if isinstance(label, Promise):
            label = str(label)

        if base:
            list.append(('{}__{}'.format(base, f.name), label))
        else:
            list.append((f.name, label))

    return list 
开发者ID:jeeyshe,项目名称:ishare,代码行数:19,代码来源:simpletags.py

示例5: mark_safe

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def mark_safe(s):
    """
    Explicitly mark a string as safe for (HTML) output purposes. The returned
    object can be used everywhere a string or unicode object is appropriate.

    If used on a method as a decorator, mark the returned data as safe.

    Can be called multiple times on a single string.
    """
    if hasattr(s, '__html__'):
        return s
    if isinstance(s, bytes) or (isinstance(s, Promise) and s._delegate_bytes):
        return SafeBytes(s)
    if isinstance(s, (six.text_type, Promise)):
        return SafeText(s)
    if callable(s):
        return _safety_decorator(mark_safe, s)
    return SafeString(str(s)) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:20,代码来源:safestring.py

示例6: mark_for_escaping

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def mark_for_escaping(s):
    """
    Explicitly mark a string as requiring HTML escaping upon output. Has no
    effect on SafeData subclasses.

    Can be called multiple times on a single string (the resulting escaping is
    only applied once).
    """
    warnings.warn('mark_for_escaping() is deprecated.', RemovedInDjango20Warning)
    if hasattr(s, '__html__') or isinstance(s, EscapeData):
        return s
    if isinstance(s, bytes) or (isinstance(s, Promise) and s._delegate_bytes):
        return EscapeBytes(s)
    if isinstance(s, (six.text_type, Promise)):
        return EscapeText(s)
    return EscapeString(str(s)) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:18,代码来源:safestring.py

示例7: insert_values

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def insert_values(self, fields, objs, raw=False):
        """
        Set up the insert query from the 'insert_values' dictionary. The
        dictionary gives the model field names and their target values.

        If 'raw_values' is True, the values in the 'insert_values' dictionary
        are inserted directly into the query, rather than passed as SQL
        parameters. This provides a way to insert NULL and DEFAULT keywords
        into the query, for example.
        """
        self.fields = fields
        # Check that no Promise object reaches the DB. Refs #10498.
        for field in fields:
            for obj in objs:
                value = getattr(obj, field.attname)
                if isinstance(value, Promise):
                    setattr(obj, field.attname, force_text(value))
        self.objs = objs
        self.raw = raw 
开发者ID:blackye,项目名称:luscan-devel,代码行数:21,代码来源:subqueries.py

示例8: convert_context_to_json

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def convert_context_to_json(self, context):
        """
        Get what we want out of the context dict and convert that to a JSON
        object. Note that this does no object serialization b/c we're
        not sending any objects.
        """
        if 'month/shift' in self.request.path:  # month calendar
            return dumps(self.get_month_calendar_dict(context))
        elif 'event-list/shift' in self.request.path:  # month event list
            return dumps(self.get_month_event_list_dict(context))
        elif 'cal-and-list/shift' in self.request.path:
            cal = self.get_month_calendar_dict(context)
            l = self.get_month_event_list_dict(context)
            cal.update(l)
            return dumps(cal)
        else:  # day list view
            for key, val in context.items():
                if isinstance(val, Promise):
                    context[key] = force_text(val)

            return dumps(self.get_day_context_dict(context)) 
开发者ID:wreckage,项目名称:django-happenings,代码行数:23,代码来源:mixins.py

示例9: smart_repr

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def smart_repr(value):
    if isinstance(value, models.Manager):
        return manager_repr(value)

    if isinstance(value, Promise) and value._delegate_text:
        value = force_text(value)

    value = unicode_repr(value)

    # Representations like u'help text'
    # should simply be presented as 'help text'
    if value.startswith("u'") and value.endswith("'"):
        return value[1:]

    # Representations like
    # <django.core.validators.RegexValidator object at 0x1047af050>
    # Should be presented as
    # <django.core.validators.RegexValidator object>
    value = re.sub(' at 0x[0-9A-Fa-f]{4,32}>', '>', value)

    return value 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:23,代码来源:representation.py

示例10: default

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def default(self, obj):
        if isinstance(obj, Promise):
            return force_text(obj)
        return super(LazyEncoder, self).default(obj) 
开发者ID:Arello-Mobile,项目名称:py2swagger,代码行数:6,代码来源:api.py

示例11: default

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def default(self, o):
        if isinstance(o, datetime.datetime):
            return o.strftime('%Y-%m-%d %H:%M:%S')
        elif isinstance(o, datetime.date):
            return o.strftime('%Y-%m-%d')
        elif isinstance(o, decimal.Decimal):
            return str(o)
        elif isinstance(o, Promise):
            return force_text(o)
        else:
            try:
                return super(JSONEncoder, self).default(o)
            except Exception:
                return smart_text(o) 
开发者ID:stormsha,项目名称:StormOnline,代码行数:16,代码来源:base.py

示例12: mark_safe

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def mark_safe(s):
    """
    Explicitly mark a string as safe for (HTML) output purposes. The returned
    object can be used everywhere a string or unicode object is appropriate.

    Can be called multiple times on a single string.
    """
    if hasattr(s, '__html__'):
        return s
    if isinstance(s, bytes) or (isinstance(s, Promise) and s._delegate_bytes):
        return SafeBytes(s)
    if isinstance(s, (six.text_type, Promise)):
        return SafeText(s)
    return SafeString(str(s)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:16,代码来源:safestring.py

示例13: mark_for_escaping

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def mark_for_escaping(s):
    """
    Explicitly mark a string as requiring HTML escaping upon output. Has no
    effect on SafeData subclasses.

    Can be called multiple times on a single string (the resulting escaping is
    only applied once).
    """
    if hasattr(s, '__html__') or isinstance(s, EscapeData):
        return s
    if isinstance(s, bytes) or (isinstance(s, Promise) and s._delegate_bytes):
        return EscapeBytes(s)
    if isinstance(s, (six.text_type, Promise)):
        return EscapeText(s)
    return EscapeString(str(s)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:17,代码来源:safestring.py

示例14: smart_text

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'):
    """
    Returns a text object representing 's' -- unicode on Python 2 and str on
    Python 3. Treats bytestrings using the 'encoding' codec.

    If strings_only is True, don't convert (some) non-string-like objects.
    """
    if isinstance(s, Promise):
        # The input is the result of a gettext_lazy() call.
        return s
    return force_text(s, encoding, strings_only, errors) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:encoding.py

示例15: smart_bytes

# 需要导入模块: from django.utils import functional [as 别名]
# 或者: from django.utils.functional import Promise [as 别名]
def smart_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
    """
    Returns a bytestring version of 's', encoded as specified in 'encoding'.

    If strings_only is True, don't convert (some) non-string-like objects.
    """
    if isinstance(s, Promise):
        # The input is the result of a gettext_lazy() call.
        return s
    return force_bytes(s, encoding, strings_only, errors) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:encoding.py


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