本文整理匯總了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
示例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
示例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
示例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)
示例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
示例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)))
示例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
示例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
示例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
示例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
示例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)
示例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
示例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])
示例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
示例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