當前位置: 首頁>>代碼示例>>Python>>正文


Python six.integer_types方法代碼示例

本文整理匯總了Python中django.utils.six.integer_types方法的典型用法代碼示例。如果您正苦於以下問題:Python six.integer_types方法的具體用法?Python six.integer_types怎麽用?Python six.integer_types使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.utils.six的用法示例。


在下文中一共展示了six.integer_types方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: localize

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def localize(value, use_l10n=None):
    """
    Checks if value is a localizable type (date, number...) and returns it
    formatted as a string using current locale format.

    If use_l10n is provided and is not None, that will force the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    if isinstance(value, bool):
        return mark_safe(six.text_type(value))
    elif isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.datetime):
        return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n)
    elif isinstance(value, datetime.date):
        return date_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.time):
        return time_format(value, 'TIME_FORMAT', use_l10n=use_l10n)
    else:
        return value 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:22,代碼來源:formats.py

示例2: localize_input

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def localize_input(value, default=None):
    """
    Checks if an input value is a localizable type and returns it
    formatted with the appropriate formatting string of the current locale.
    """
    if isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value)
    elif isinstance(value, datetime.datetime):
        value = datetime_safe.new_datetime(value)
        format = force_str(default or get_format('DATETIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.date):
        value = datetime_safe.new_date(value)
        format = force_str(default or get_format('DATE_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.time):
        format = force_str(default or get_format('TIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    return value 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:21,代碼來源:formats.py

示例3: int_to_base36

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def int_to_base36(i):
    """
    Converts an integer to a base36 string
    """
    char_set = '0123456789abcdefghijklmnopqrstuvwxyz'
    if i < 0:
        raise ValueError("Negative base36 conversion input.")
    if six.PY2:
        if not isinstance(i, six.integer_types):
            raise TypeError("Non-integer base36 conversion input.")
        if i > sys.maxint:
            raise ValueError("Base36 conversion input too large.")
    if i < 36:
        return char_set[i]
    b36 = ''
    while i != 0:
        i, n = divmod(i, 36)
        b36 = char_set[n] + b36
    return b36 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:21,代碼來源:http.py

示例4: display_for_value

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def display_for_value(value, boolean=False):
    from django.contrib.admin.templatetags.admin_list import _boolean_icon
    from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE

    if boolean:
        return _boolean_icon(value)
    elif value is None:
        return EMPTY_CHANGELIST_VALUE
    elif isinstance(value, datetime.datetime):
        return formats.localize(timezone.template_localtime(value))
    elif isinstance(value, (datetime.date, datetime.time)):
        return formats.localize(value)
    elif isinstance(value, six.integer_types + (decimal.Decimal, float)):
        return formats.number_format(value)
    else:
        return smart_text(value) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:18,代碼來源:utils.py

示例5: svg

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def svg(self, relative=False, precision=8, **kwargs):
        """
        Returns SVG representation of the geographic field in a `svg`
        attribute on each element of this GeoQuerySet.

        Keyword Arguments:
         `relative`  => If set to True, this will evaluate the path in
                        terms of relative moves (rather than absolute).

         `precision` => May be used to set the maximum number of decimal
                        digits used in output (defaults to 8).
        """
        relative = int(bool(relative))
        if not isinstance(precision, six.integer_types):
            raise TypeError('SVG precision keyword argument must be an integer.')
        s = {
            'desc': 'SVG',
            'procedure_fmt': '%(geo_col)s,%(rel)s,%(precision)s',
            'procedure_args': {
                'rel': relative,
                'precision': precision,
            }
        }
        return self._spatial_attribute('svg', s, **kwargs) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:26,代碼來源:query.py

示例6: get_for_objects

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def get_for_objects(self, queryset):
        """
        Get log entries for the objects in the specified queryset.
        :param queryset: The queryset to get the log entries for.
        :type queryset: QuerySet
        :return: The LogAction objects for the objects in the given queryset.
        :rtype: QuerySet
        """
        if not isinstance(queryset, QuerySet) or queryset.count() == 0:
            return self.none()

        content_type = ContentType.objects.get_for_model(queryset.model)
        primary_keys = queryset.values_list(queryset.model._meta.pk.name, flat=True)

        if isinstance(primary_keys[0], integer_types):
            return self.filter(content_type=content_type).filter(Q(object_id__in=primary_keys)).distinct()
        else:
            return self.filter(content_type=content_type).filter(Q(object_pk__in=primary_keys)).distinct() 
開發者ID:shtalinberg,項目名稱:django-actions-logger,代碼行數:20,代碼來源:models.py

示例7: _from_python

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def _from_python(self, value):
        """
        Converts Python values to a string for Whoosh.

        Code courtesy of pysolr.
        """
        if hasattr(value, 'strftime'):
            if not hasattr(value, 'hour'):
                value = datetime(value.year, value.month, value.day, 0, 0, 0)
        elif isinstance(value, bool):
            if value:
                value = 'true'
            else:
                value = 'false'
        elif isinstance(value, (list, tuple)):
            value = u','.join([force_text(v) for v in value])
        elif isinstance(value, (six.integer_types, float)):
            # Leave it alone.
            pass
        else:
            value = force_text(value)
        return value 
開發者ID:infinity1207,項目名稱:thirtylol,代碼行數:24,代碼來源:whoosh_cn_backend.py

示例8: localize

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def localize(value, use_l10n=None):
    """
    Checks if value is a localizable type (date, number...) and returns it
    formatted as a string using current locale format.

    If use_l10n is provided and is not None, that will force the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    if isinstance(value, six.string_types):  # Handle strings first for performance reasons.
        return value
    elif isinstance(value, bool):  # Make sure booleans don't get treated as numbers
        return mark_safe(six.text_type(value))
    elif isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.datetime):
        return date_format(value, 'DATETIME_FORMAT', use_l10n=use_l10n)
    elif isinstance(value, datetime.date):
        return date_format(value, use_l10n=use_l10n)
    elif isinstance(value, datetime.time):
        return time_format(value, 'TIME_FORMAT', use_l10n=use_l10n)
    return value 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:23,代碼來源:formats.py

示例9: localize_input

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def localize_input(value, default=None):
    """
    Checks if an input value is a localizable type and returns it
    formatted with the appropriate formatting string of the current locale.
    """
    if isinstance(value, six.string_types):  # Handle strings first for performance reasons.
        return value
    elif isinstance(value, bool):  # Don't treat booleans as numbers.
        return six.text_type(value)
    elif isinstance(value, (decimal.Decimal, float) + six.integer_types):
        return number_format(value)
    elif isinstance(value, datetime.datetime):
        value = datetime_safe.new_datetime(value)
        format = force_str(default or get_format('DATETIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.date):
        value = datetime_safe.new_date(value)
        format = force_str(default or get_format('DATE_INPUT_FORMATS')[0])
        return value.strftime(format)
    elif isinstance(value, datetime.time):
        format = force_str(default or get_format('TIME_INPUT_FORMATS')[0])
        return value.strftime(format)
    return value 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:25,代碼來源:formats.py

示例10: _check_max_length_attribute

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def _check_max_length_attribute(self, **kwargs):
        if self.max_length is None:
            return [
                checks.Error(
                    "CharFields must define a 'max_length' attribute.",
                    obj=self,
                    id='fields.E120',
                )
            ]
        elif not isinstance(self.max_length, six.integer_types) or self.max_length <= 0:
            return [
                checks.Error(
                    "'max_length' must be a positive integer.",
                    obj=self,
                    id='fields.E121',
                )
            ]
        else:
            return [] 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:21,代碼來源:__init__.py

示例11: display_for_value

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def display_for_value(value, empty_value_display, boolean=False):
    from django.contrib.admin.templatetags.admin_list import _boolean_icon

    if boolean:
        return _boolean_icon(value)
    elif value is None:
        return empty_value_display
    elif isinstance(value, datetime.datetime):
        return formats.localize(timezone.template_localtime(value))
    elif isinstance(value, (datetime.date, datetime.time)):
        return formats.localize(value)
    elif isinstance(value, six.integer_types + (decimal.Decimal, float)):
        return formats.number_format(value)
    elif isinstance(value, (list, tuple)):
        return ', '.join(force_text(v) for v in value)
    else:
        return force_text(value) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:19,代碼來源:utils.py

示例12: _check_max_length_attribute

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def _check_max_length_attribute(self, **kwargs):
        if self.max_length is None:
            return [
                checks.Error(
                    "CharFields must define a 'max_length' attribute.",
                    hint=None,
                    obj=self,
                    id='fields.E120',
                )
            ]
        elif not isinstance(self.max_length, six.integer_types) or self.max_length <= 0:
            return [
                checks.Error(
                    "'max_length' must be a positive integer.",
                    hint=None,
                    obj=self,
                    id='fields.E121',
                )
            ]
        else:
            return [] 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:23,代碼來源:__init__.py

示例13: __delitem__

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def __delitem__(self, index):
        "Delete the item(s) at the specified index/slice."
        if not isinstance(index, six.integer_types + (slice,)):
            raise TypeError("%s is not a legal index" % index)

        # calculate new length and dimensions
        origLen = len(self)
        if isinstance(index, six.integer_types):
            index = self._checkindex(index)
            indexRange = [index]
        else:
            indexRange = range(*index.indices(origLen))

        newLen = origLen - len(indexRange)
        newItems = (self._get_single_internal(i)
                    for i in range(origLen)
                    if i not in indexRange)

        self._rebuild(newLen, newItems) 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:21,代碼來源:mutable_list.py

示例14: display_for_value

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def display_for_value(value):
    if isinstance(value, bool):
        return force_text(value)
    elif isinstance(value, (int, decimal.Decimal, float)):
        return formats.number_format(value)
    elif isinstance(value, (list, tuple)):
        return ', '.join(force_text(v) for v in value)
    elif isinstance(value, six.integer_types + (decimal.Decimal, float)):
        return formats.number_format(value)
    elif isinstance(value, datetime.datetime):
        return formats.localize(timezone.template_localtime(value))
    elif isinstance(value, (datetime.date, datetime.time)):
        return formats.localize(value)
    elif isinstance(value, models.query.QuerySet):
        if value.model is Option and COLOR_TAGS:
            html = ''
            for v in value:
                item = '<span class="badge bg-{}">{}</span>&nbsp'.format(
                    v.color, v.text
                )
                html += item
            return mark_safe(html)
        else:
            value = [force_text(i) for i in value]
            return display_for_value(value)
    else:
        return force_text(value) 
開發者ID:Wenvki,項目名稱:django-idcops,代碼行數:29,代碼來源:utils.py

示例15: __getitem__

# 需要導入模塊: from django.utils import six [as 別名]
# 或者: from django.utils.six import integer_types [as 別名]
def __getitem__(self, idx):
        # Prevent unnecessary reevaluation when accessing BoundField's attrs
        # from templates.
        if not isinstance(idx, six.integer_types):
            raise TypeError
        return list(self.__iter__())[idx] 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:8,代碼來源:forms.py


注:本文中的django.utils.six.integer_types方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。