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


Python itercompat.is_iterable方法代码示例

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


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

示例1: run_checks

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def run_checks(self, app_configs=None, tags=None, include_deployment_checks=False):
        """ Run all registered checks and return list of Errors and Warnings.
        """
        errors = []
        checks = self.get_checks(include_deployment_checks)

        if tags is not None:
            checks = [check for check in checks
                      if hasattr(check, 'tags') and set(check.tags) & set(tags)]

        for check in checks:
            new_errors = check(app_configs=app_configs)
            assert is_iterable(new_errors), (
                "The function %r did not return a list. All functions registered "
                "with the checks registry must return a list." % check)
            errors.extend(new_errors)
        return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:19,代码来源:registry.py

示例2: _check_choices

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def _check_choices(self):
        if self.choices:
            if isinstance(self.choices, str) or not is_iterable(self.choices):
                return [
                    checks.Error(
                        "'choices' must be an iterable (e.g., a list or tuple).",
                        obj=self,
                        id='fields.E004',
                    )
                ]
            elif any(isinstance(choice, str) or
                     not is_iterable(choice) or len(choice) != 2
                     for choice in self.choices):
                return [
                    checks.Error(
                        "'choices' must be an iterable containing "
                        "(actual value, human readable name) tuples.",
                        obj=self,
                        id='fields.E005',
                    )
                ]
            else:
                return []
        else:
            return [] 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:__init__.py

示例3: make_hashable

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def make_hashable(value):
    if isinstance(value, dict):
        return tuple([
            (key, make_hashable(nested_value))
            for key, nested_value in value.items()
        ])
    # Try hash to avoid converting a hashable iterable (e.g. string, frozenset)
    # to a tuple.
    try:
        hash(value)
    except TypeError:
        if is_iterable(value):
            return tuple(map(make_hashable, value))
        # Non-hashable, non-iterable.
        raise
    return value 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:18,代码来源:hashable.py

示例4: normalize_fields

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def normalize_fields(cls, fields):
        """
        Normalize the fields into an ordered map of {field name: param name}
        """
        # fields is a mapping, copy into new OrderedDict
        if isinstance(fields, dict):
            return OrderedDict(fields)

        # convert iterable of values => iterable of pairs (field name, param name)
        assert is_iterable(fields), \
            "'fields' must be an iterable (e.g., a list, tuple, or mapping)."

        # fields is an iterable of field names
        assert all(isinstance(field, six.string_types) or
                   is_iterable(field) and len(field) == 2  # may need to be wrapped in parens
                   for field in fields), \
            "'fields' must contain strings or (field name, param name) pairs."

        return OrderedDict([
            (f, f) if isinstance(f, six.string_types) else f for f in fields
        ]) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:23,代码来源:filters.py

示例5: inclusion_tag

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def inclusion_tag(file_name, context_class=Context, takes_context=False):
    def wrap(func):
        @functools.wraps(func)
        def method(self, context, nodes, *arg, **kwargs):
            _dict = func(self, context, nodes, *arg, **kwargs)
            from django.template.loader import get_template, select_template
            if isinstance(file_name, Template):
                t = file_name
            elif not isinstance(file_name, basestring) and is_iterable(file_name):
                t = select_template(file_name)
            else:
                t = get_template(file_name)

            _dict['autoescape'] = context.autoescape
            _dict['use_l10n'] = context.use_l10n
            _dict['use_tz'] = context.use_tz
            _dict['admin_view'] = context['admin_view']

            csrf_token = context.get('csrf_token', None)
            if csrf_token is not None:
                _dict['csrf_token'] = csrf_token
            nodes.append(t.render(_dict))

        return method
    return wrap 
开发者ID:Liweimin0512,项目名称:ImitationTmall_Django,代码行数:27,代码来源:base.py

示例6: _check_columns_attribute

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def _check_columns_attribute(self, textual_columns):
        if not self.columns:
            return
        if not textual_columns:
            yield checks.Error(
                "No textual columns available in this model for search vector indexing.",
                obj=self, id='postgres.E100',
            )
        elif not is_iterable(self.columns) or \
                not all(isinstance(wc, WeightedColumn) for wc in self.columns):
            yield checks.Error(
                "'columns' must be an iterable containing WeightedColumn instances",
                obj=self, id='postgres.E101',
            )
        else:
            for column in self.columns:
                for error in column.check(self, textual_columns):
                    yield error 
开发者ID:damoti,项目名称:django-tsvector-field,代码行数:20,代码来源:fields.py

示例7: inclusion_tag

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def inclusion_tag(file_name, context_class=Context, takes_context=False):
    def wrap(func):
        @functools.wraps(func)
        def method(self, context, nodes, *arg, **kwargs):
            _dict = func(self, context, nodes, *arg, **kwargs)
            from django.template.loader import get_template, select_template
            cls_str = str if six.PY3 else basestring
            if isinstance(file_name, Template):
                t = file_name
            elif not isinstance(file_name, cls_str) and is_iterable(file_name):
                t = select_template(file_name)
            else:
                t = get_template(file_name)

            _dict['autoescape'] = context.autoescape
            _dict['use_l10n'] = context.use_l10n
            _dict['use_tz'] = context.use_tz
            _dict['admin_view'] = context['admin_view']

            csrf_token = context.get('csrf_token', None)
            if csrf_token is not None:
                _dict['csrf_token'] = csrf_token
            nodes.append(t.render(_dict))

        return method
    return wrap 
开发者ID:stormsha,项目名称:StormOnline,代码行数:28,代码来源:base.py

示例8: _check_choices

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def _check_choices(self):
        if self.choices:
            if (isinstance(self.choices, six.string_types) or
                    not is_iterable(self.choices)):
                return [
                    checks.Error(
                        "'choices' must be an iterable (e.g., a list or tuple).",
                        hint=None,
                        obj=self,
                        id='fields.E004',
                    )
                ]
            elif any(isinstance(choice, six.string_types) or
                     not is_iterable(choice) or len(choice) != 2
                     for choice in self.choices):
                return [
                    checks.Error(
                        ("'choices' must be an iterable containing "
                         "(actual value, human readable name) tuples."),
                        hint=None,
                        obj=self,
                        id='fields.E005',
                    )
                ]
            else:
                return []
        else:
            return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:30,代码来源:__init__.py

示例9: render

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def render(self, context):
        """
        Render the specified template and context. Cache the template object
        in render_context to avoid reparsing and loading when used in a for
        loop.
        """
        resolved_args, resolved_kwargs = self.get_resolved_arguments(context)
        _dict = self.func(*resolved_args, **resolved_kwargs)

        t = context.render_context.get(self)
        if t is None:
            if isinstance(self.filename, Template):
                t = self.filename
            elif isinstance(getattr(self.filename, 'template', None), Template):
                t = self.filename.template
            elif not isinstance(self.filename, str) and is_iterable(self.filename):
                t = context.template.engine.select_template(self.filename)
            else:
                t = context.template.engine.get_template(self.filename)
            context.render_context[self] = t
        new_context = context.new(_dict)
        # Copy across the CSRF token, if present, because inclusion tags are
        # often used for forms, and we need instructions for using CSRF
        # protection to be as simple as possible.
        csrf_token = context.get('csrf_token')
        if csrf_token is not None:
            new_context['csrf_token'] = csrf_token
        return t.render(new_context) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:30,代码来源:library.py

示例10: __init__

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def __init__(self, verbose_name=None, choices=None, **kwargs):
        kwargs['verbose_name'] = verbose_name
        super().__init__(**kwargs)
        self.suggestions = choices
        if not isinstance(choices, six.string_types) and is_iterable(choices):
            choices = [('{:03d}'.format(i), choice)
                       if isinstance(choice, six.string_types) or not is_iterable(choice)
                       else choice
                       for i, choice in enumerate(choices, start=1)]
        self.choices = choices 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:12,代码来源:fields.py

示例11: _check_choices

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def _check_choices(self):
        if self.choices:
            if (isinstance(self.choices, six.string_types) or
                    not is_iterable(self.choices)):
                return [
                    checks.Error(
                        "'choices' must be an iterable (e.g., a list or tuple).",
                        obj=self,
                        id='fields.E004',
                    )
                ]
            elif any(isinstance(choice, six.string_types) or
                     not is_iterable(choice) or len(choice) != 2
                     for choice in self.choices):
                return [
                    checks.Error(
                        "'choices' must be an iterable containing "
                        "(actual value, human readable name) tuples.",
                        obj=self,
                        id='fields.E005',
                    )
                ]
            else:
                return []
        else:
            return [] 
开发者ID:Yeah-Kun,项目名称:python,代码行数:28,代码来源:__init__.py

示例12: render

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def render(self, context):
        """
        Render the specified template and context. Cache the template object
        in render_context to avoid reparsing and loading when used in a for
        loop.
        """
        resolved_args, resolved_kwargs = self.get_resolved_arguments(context)
        _dict = self.func(*resolved_args, **resolved_kwargs)

        t = context.render_context.get(self)
        if t is None:
            if isinstance(self.filename, Template):
                t = self.filename
            elif isinstance(getattr(self.filename, 'template', None), Template):
                t = self.filename.template
            elif not isinstance(self.filename, six.string_types) and is_iterable(self.filename):
                t = context.template.engine.select_template(self.filename)
            else:
                t = context.template.engine.get_template(self.filename)
            context.render_context[self] = t
        new_context = context.new(_dict)
        # Copy across the CSRF token, if present, because inclusion tags are
        # often used for forms, and we need instructions for using CSRF
        # protection to be as simple as possible.
        csrf_token = context.get('csrf_token')
        if csrf_token is not None:
            new_context['csrf_token'] = csrf_token
        return t.render(new_context) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:30,代码来源:library.py

示例13: inclusion_tag

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def inclusion_tag(file_name, context_class=Context, takes_context=False):
    def wrap(func):
        @functools.wraps(func)
        def method(self, context, nodes, *arg, **kwargs):
            _dict = func(self, context, nodes, *arg, **kwargs)
            from django.template.loader import get_template, select_template
            cls_str = str
            if isinstance(file_name, Template):
                t = file_name
            elif not isinstance(file_name, cls_str) and is_iterable(file_name):
                t = select_template(file_name)
            else:
                t = get_template(file_name)

            _dict['autoescape'] = context.autoescape
            _dict['use_l10n'] = context.use_l10n
            _dict['use_tz'] = context.use_tz
            _dict['admin_view'] = context['admin_view']

            csrf_token = context.get('csrf_token', None)
            if csrf_token is not None:
                _dict['csrf_token'] = csrf_token
            nodes.append(t.render(_dict))

        return method
    return wrap 
开发者ID:mtianyan,项目名称:Mxonline3,代码行数:28,代码来源:base.py

示例14: inclusion_tag

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def inclusion_tag(file_name, context_class=Context, takes_context=False):
    def wrap(func):
        @functools.wraps(func)
        def method(self, context, nodes, *arg, **kwargs):
            _dict = func(self, context, nodes, *arg, **kwargs)
            from django.template.loader import get_template, select_template
            if isinstance(file_name, Template):
                t = file_name
            elif not isinstance(file_name, basestring) and is_iterable(file_name):
                t = select_template(file_name)
            else:
                t = get_template(file_name)
            new_context = context_class(_dict, **{
                'autoescape': context.autoescape,
                'current_app': context.current_app,
                'use_l10n': context.use_l10n,
                'use_tz': context.use_tz,
            })
            new_context['admin_view'] = context['admin_view']
            csrf_token = context.get('csrf_token', None)
            if csrf_token is not None:
                new_context['csrf_token'] = csrf_token
            nodes.append(t.render(new_context))

        return method
    return wrap 
开发者ID:madre,项目名称:devops,代码行数:28,代码来源:base.py

示例15: inclusion_tag

# 需要导入模块: from django.utils import itercompat [as 别名]
# 或者: from django.utils.itercompat import is_iterable [as 别名]
def inclusion_tag(self, file_name, takes_context=False, name=None):
        def dec(func):
            params, varargs, varkw, defaults = getargspec(func)

            class InclusionNode(TagHelperNode):

                def render(self, context):
                    """
                    Renders the specified template and context. Caches the
                    template object in render_context to avoid reparsing and
                    loading when used in a for loop.
                    """
                    resolved_args, resolved_kwargs = self.get_resolved_arguments(context)
                    _dict = func(*resolved_args, **resolved_kwargs)

                    t = context.render_context.get(self)
                    if t is None:
                        if isinstance(file_name, Template):
                            t = file_name
                        elif isinstance(getattr(file_name, 'template', None), Template):
                            t = file_name.template
                        elif not isinstance(file_name, six.string_types) and is_iterable(file_name):
                            t = context.template.engine.select_template(file_name)
                        else:
                            t = context.template.engine.get_template(file_name)
                        context.render_context[self] = t
                    new_context = context.new(_dict)
                    # Copy across the CSRF token, if present, because
                    # inclusion tags are often used for forms, and we need
                    # instructions for using CSRF protection to be as simple
                    # as possible.
                    csrf_token = context.get('csrf_token', None)
                    if csrf_token is not None:
                        new_context['csrf_token'] = csrf_token
                    return t.render(new_context)

            function_name = (name or
                getattr(func, '_decorated_function', func).__name__)
            compile_func = partial(generic_tag_compiler,
                params=params, varargs=varargs, varkw=varkw,
                defaults=defaults, name=function_name,
                takes_context=takes_context, node_class=InclusionNode)
            compile_func.__doc__ = func.__doc__
            self.tag(function_name, compile_func)
            return func
        return dec 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:48,代码来源:base.py


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