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


Python six.itervalues方法代码示例

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


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

示例1: allow_lazy

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def allow_lazy(func, *resultclasses):
    """
    A decorator that allows a function to be called with one or more lazy
    arguments. If none of the args are lazy, the function is evaluated
    immediately, otherwise a __proxy__ is returned that will evaluate the
    function when needed.
    """
    lazy_func = lazy(func, *resultclasses)

    @wraps(func)
    def wrapper(*args, **kwargs):
        for arg in list(args) + list(six.itervalues(kwargs)):
            if isinstance(arg, Promise):
                break
        else:
            return func(*args, **kwargs)
        return lazy_func(*args, **kwargs)
    return wrapper 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:functional.py

示例2: keep_lazy

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def keep_lazy(*resultclasses):
    """
    A decorator that allows a function to be called with one or more lazy
    arguments. If none of the args are lazy, the function is evaluated
    immediately, otherwise a __proxy__ is returned that will evaluate the
    function when needed.
    """
    if not resultclasses:
        raise TypeError("You must pass at least one argument to keep_lazy().")

    def decorator(func):
        lazy_func = lazy(func, *resultclasses)

        @wraps(func)
        def wrapper(*args, **kwargs):
            for arg in list(args) + list(six.itervalues(kwargs)):
                if isinstance(arg, Promise):
                    break
            else:
                return func(*args, **kwargs)
            return lazy_func(*args, **kwargs)
        return wrapper
    return decorator 
开发者ID:Yeah-Kun,项目名称:python,代码行数:25,代码来源:functional.py

示例3: allow_lazy

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def allow_lazy(func, *resultclasses):
    """
    A decorator that allows a function to be called with one or more lazy
    arguments. If none of the args are lazy, the function is evaluated
    immediately, otherwise a __proxy__ is returned that will evaluate the
    function when needed.
    """
    @wraps(func)
    def wrapper(*args, **kwargs):
        for arg in list(args) + list(six.itervalues(kwargs)):
            if isinstance(arg, Promise):
                break
        else:
            return func(*args, **kwargs)
        return lazy(func, *resultclasses)(*args, **kwargs)
    return wrapper 
开发者ID:blackye,项目名称:luscan-devel,代码行数:18,代码来源:functional.py

示例4: _prepare

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def _prepare(self, model):
        if self.order_with_respect_to:
            # The app registry will not be ready at this point, so we cannot
            # use get_field().
            query = self.order_with_respect_to
            try:
                self.order_with_respect_to = next(
                    f for f in self._get_fields(reverse=False)
                    if f.name == query or f.attname == query
                )
            except StopIteration:
                raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, query))

            self.ordering = ('_order',)
            if not any(isinstance(field, OrderWrt) for field in model._meta.local_fields):
                model.add_to_class('_order', OrderWrt())
        else:
            self.order_with_respect_to = None

        if self.pk is None:
            if self.parents:
                # Promote the first parent link in lieu of adding yet another
                # field.
                field = next(six.itervalues(self.parents))
                # Look for a local field with the same name as the
                # first parent link. If a local field has already been
                # created, use it instead of promoting the parent
                already_created = [fld for fld in self.local_fields if fld.name == field.name]
                if already_created:
                    field = already_created[0]
                field.primary_key = True
                self.setup_pk(field)
            else:
                auto = AutoField(verbose_name='ID', primary_key=True,
                        auto_created=True)
                model.add_to_class('id', auto) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:38,代码来源:options.py

示例5: sitemap

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def sitemap(request, sitemaps, section=None,
            template_name='sitemap.xml', content_type='application/xml'):

    req_protocol = request.scheme
    req_site = get_current_site(request)

    if section is not None:
        if section not in sitemaps:
            raise Http404("No sitemap available for section: %r" % section)
        maps = [sitemaps[section]]
    else:
        maps = list(six.itervalues(sitemaps))
    page = request.GET.get("p", 1)

    urls = []
    for site in maps:
        try:
            if callable(site):
                site = site()
            urls.extend(site.get_urls(page=page, site=req_site,
                                      protocol=req_protocol))
        except EmptyPage:
            raise Http404("Page %s empty" % page)
        except PageNotAnInteger:
            raise Http404("No page '%s'" % page)
    response = TemplateResponse(request, template_name, {'urlset': urls},
                                content_type=content_type)
    if hasattr(site, 'latest_lastmod'):
        # if latest_lastmod is defined for site, set header so as
        # ConditionalGetMiddleware is able to send 304 NOT MODIFIED
        lastmod = site.latest_lastmod
        response['Last-Modified'] = http_date(
            timegm(
                lastmod.utctimetuple() if isinstance(lastmod, datetime.datetime)
                else lastmod.timetuple()
            )
        )
    return response 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:40,代码来源:views.py

示例6: __init__

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def __init__(self, form, inline_formsets):
        super(AdminErrorList, self).__init__()

        if form.is_bound:
            self.extend(list(six.itervalues(form.errors)))
            for inline_formset in inline_formsets:
                self.extend(inline_formset.non_form_errors())
                for errors_in_inline_form in inline_formset.errors:
                    self.extend(list(six.itervalues(errors_in_inline_form))) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:helpers.py

示例7: list

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def list(self, ignore_patterns):
        """
        List all files in all app storages.
        """
        for storage in six.itervalues(self.storages):
            if storage.exists(''):  # check if storage location exists
                for path in utils.get_files(storage, ignore_patterns):
                    yield path, storage 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,代码来源:finders.py

示例8: check_generic_foreign_keys

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def check_generic_foreign_keys(**kwargs):
    from .fields import GenericForeignKey

    errors = []
    fields = (obj
        for cls in apps.get_models()
        for obj in six.itervalues(vars(cls))
        if isinstance(obj, GenericForeignKey))
    for field in fields:
        errors.extend(field.check())
    return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:checks.py

示例9: as_sql

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def as_sql(self):
        """ Generate SQL queries that perform related deletion """
        # List of (sql, params) tuples to perform deletion
        query_list = []

        for model, instances in self.data.items():
            self.data[model] = sorted(instances, key=attrgetter("pk"))
        self.sort()
        # Do not send pre_delete signals as in .delete()

        # Fast deletes
        for qs in self.fast_deletes:
            # TODO Check for any potential caveats from complex queries - assume none are generated by Collector

            # Clone queryset into DeleteQuery to use .as_sql()
            query_list.append(qs.query.clone(klass=sql.DeleteQuery).get_compiler(self.using).as_sql())

        # update fields
        for model, instances_for_fieldvalues in six.iteritems(self.field_updates):
            query = sql.UpdateQuery(model)
            for (field, value), instances in six.iteritems(instances_for_fieldvalues):
                query.add_update_values({field.name: value})
                query.add_q(models.Q(pk__in=[obj.pk for obj in instances]))
                query_list.append(query.get_compiler(using=self.using).as_sql())

        # reverse instance collections
        for instances in six.itervalues(self.data):
            instances.reverse()

        # delete instances
        for model, instances in six.iteritems(self.data):
            query = sql.DeleteQuery(model)
            pk_list = [obj.pk for obj in instances]
            query.where = query.where_class()
            query.add_q(models.Q(pk__in=pk_list))
            query_list.append(query.get_compiler(using=self.using).as_sql())

        # Do not update instances as in .delete()
        return query_list 
开发者ID:ashleywaite,项目名称:django-more,代码行数:41,代码来源:operations.py

示例10: has_joins

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def has_joins(queryset):
    """Return True iff. a queryset includes joins.

    If this is the case, it is possible for the queryset
    to return duplicate results.
    """
    for join in six.itervalues(queryset.query.alias_map):
        if join.join_type:
            return True
    return False 
开发者ID:AltSchool,项目名称:dynamic-rest,代码行数:12,代码来源:filters.py

示例11: _prepare

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def _prepare(self, model):
        if self.order_with_respect_to:
            # The app registry will not be ready at this point, so we cannot
            # use get_field().
            query = self.order_with_respect_to
            try:
                self.order_with_respect_to = next(
                    f for f in self._get_fields(reverse=False)
                    if f.name == query or f.attname == query
                )
            except StopIteration:
                raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, query))

            self.ordering = ('_order',)
            if not any(isinstance(field, OrderWrt) for field in model._meta.local_fields):
                model.add_to_class('_order', OrderWrt())
        else:
            self.order_with_respect_to = None

        if self.pk is None:
            if self.parents:
                # Promote the first parent link in lieu of adding yet another
                # field.
                field = next(six.itervalues(self.parents))
                # Look for a local field with the same name as the
                # first parent link. If a local field has already been
                # created, use it instead of promoting the parent
                already_created = [fld for fld in self.local_fields if fld.name == field.name]
                if already_created:
                    field = already_created[0]
                field.primary_key = True
                self.setup_pk(field)
                if not field.remote_field.parent_link:
                    warnings.warn(
                        'Add parent_link=True to %s as an implicit link is '
                        'deprecated.' % field, RemovedInDjango20Warning
                    )
            else:
                auto = AutoField(verbose_name='ID', primary_key=True, auto_created=True)
                model.add_to_class('id', auto) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:42,代码来源:options.py

示例12: get_action_choices

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
        """
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        """
        choices = [] + default_choices
        for func, name, description in six.itervalues(self.get_actions(request)):
            choice = (name, description % model_format_dict(self.opts))
            choices.append(choice)
        return choices 
开发者ID:Yeah-Kun,项目名称:python,代码行数:12,代码来源:options.py

示例13: test_itervalues

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def test_itervalues(self):
        self.context['x'] = 1
        self.context.modified = False
        self.context.accessed = False
        i = six.itervalues(self.context)
        self.assertTrue(hasattr(i, '__iter__'))
        self.assertTrue(self.context.accessed)
        self.assertFalse(self.context.modified)
        self.assertEqual(list(i), [1]) 
开发者ID:doraemonext,项目名称:wechat-python-sdk,代码行数:11,代码来源:tests.py

示例14: list

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def list(self, ignore_patterns):
        """
        List all files in all theme storages.
        """
        for storage in six.itervalues(self.storages):
            if storage.exists(''):  # check if storage location exists
                for path in utils.get_files(storage, ignore_patterns):
                    yield path, storage 
开发者ID:edx,项目名称:ecommerce,代码行数:10,代码来源:finders.py

示例15: get_node_ip_by_nictag

# 需要导入模块: from django.utils import six [as 别名]
# 或者: from django.utils.six import itervalues [as 别名]
def get_node_ip_by_nictag(self, nictag, node_nics=None):
        """Return node IP address according to NIC name (nictag)"""
        if node_nics is None:
            node_nics = self.used_nics

        for nic in six.itervalues(node_nics):
            if nictag in nic.get('NIC Names', ()):
                return nic['ip4addr']

        return None 
开发者ID:erigones,项目名称:esdc-ce,代码行数:12,代码来源:node.py


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