當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。