[py3] Fixed access to dict keys/values/items.
This commit is contained in:
parent
fa3f0aa021
commit
ee191715ea
|
@ -158,7 +158,7 @@ class UserSettingsHolder(BaseSettings):
|
||||||
return getattr(self.default_settings, name)
|
return getattr(self.default_settings, name)
|
||||||
|
|
||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
return self.__dict__.keys() + dir(self.default_settings)
|
return list(six.iterkeys(self.__dict__)) + dir(self.default_settings)
|
||||||
|
|
||||||
# For Python < 2.6:
|
# For Python < 2.6:
|
||||||
__members__ = property(lambda self: self.__dir__())
|
__members__ = property(lambda self: self.__dir__())
|
||||||
|
|
|
@ -325,11 +325,11 @@ class AdminErrorList(forms.util.ErrorList):
|
||||||
"""
|
"""
|
||||||
def __init__(self, form, inline_formsets):
|
def __init__(self, form, inline_formsets):
|
||||||
if form.is_bound:
|
if form.is_bound:
|
||||||
self.extend(form.errors.values())
|
self.extend(list(six.itervalues(form.errors)))
|
||||||
for inline_formset in inline_formsets:
|
for inline_formset in inline_formsets:
|
||||||
self.extend(inline_formset.non_form_errors())
|
self.extend(inline_formset.non_form_errors())
|
||||||
for errors_in_inline_form in inline_formset.errors:
|
for errors_in_inline_form in inline_formset.errors:
|
||||||
self.extend(errors_in_inline_form.values())
|
self.extend(list(six.itervalues(errors_in_inline_form)))
|
||||||
|
|
||||||
def normalize_fieldsets(fieldsets):
|
def normalize_fieldsets(fieldsets):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -425,7 +425,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
if self.declared_fieldsets:
|
if self.declared_fieldsets:
|
||||||
return self.declared_fieldsets
|
return self.declared_fieldsets
|
||||||
form = self.get_form(request, obj)
|
form = self.get_form(request, obj)
|
||||||
fields = form.base_fields.keys() + list(self.get_readonly_fields(request, obj))
|
fields = list(six.iterkeys(form.base_fields)) + list(self.get_readonly_fields(request, obj))
|
||||||
return [(None, {'fields': fields})]
|
return [(None, {'fields': fields})]
|
||||||
|
|
||||||
def get_form(self, request, obj=None, **kwargs):
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
|
@ -608,7 +608,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
tuple (name, description).
|
tuple (name, description).
|
||||||
"""
|
"""
|
||||||
choices = [] + default_choices
|
choices = [] + default_choices
|
||||||
for func, name, description in self.get_actions(request).itervalues():
|
for func, name, description in six.itervalues(self.get_actions(request)):
|
||||||
choice = (name, description % model_format_dict(self.opts))
|
choice = (name, description % model_format_dict(self.opts))
|
||||||
choices.append(choice)
|
choices.append(choice)
|
||||||
return choices
|
return choices
|
||||||
|
@ -1415,7 +1415,7 @@ class InlineModelAdmin(BaseModelAdmin):
|
||||||
if self.declared_fieldsets:
|
if self.declared_fieldsets:
|
||||||
return self.declared_fieldsets
|
return self.declared_fieldsets
|
||||||
form = self.get_formset(request, obj).form
|
form = self.get_formset(request, obj).form
|
||||||
fields = form.base_fields.keys() + list(self.get_readonly_fields(request, obj))
|
fields = list(six.iterkeys(form.base_fields)) + list(self.get_readonly_fields(request, obj))
|
||||||
return [(None, {'fields': fields})]
|
return [(None, {'fields': fields})]
|
||||||
|
|
||||||
def queryset(self, request):
|
def queryset(self, request):
|
||||||
|
|
|
@ -10,6 +10,7 @@ from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
from django.core.urlresolvers import reverse, NoReverseMatch
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils import six
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.views.decorators.cache import never_cache
|
from django.views.decorators.cache import never_cache
|
||||||
|
@ -133,7 +134,7 @@ class AdminSite(object):
|
||||||
"""
|
"""
|
||||||
Get all the enabled actions as an iterable of (name, func).
|
Get all the enabled actions as an iterable of (name, func).
|
||||||
"""
|
"""
|
||||||
return self._actions.iteritems()
|
return six.iteritems(self._actions)
|
||||||
|
|
||||||
def has_permission(self, request):
|
def has_permission(self, request):
|
||||||
"""
|
"""
|
||||||
|
@ -239,7 +240,7 @@ class AdminSite(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add in each model's views.
|
# Add in each model's views.
|
||||||
for model, model_admin in self._registry.iteritems():
|
for model, model_admin in six.iteritems(self._registry):
|
||||||
urlpatterns += patterns('',
|
urlpatterns += patterns('',
|
||||||
url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name),
|
url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name),
|
||||||
include(model_admin.urls))
|
include(model_admin.urls))
|
||||||
|
@ -370,7 +371,7 @@ class AdminSite(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sort the apps alphabetically.
|
# Sort the apps alphabetically.
|
||||||
app_list = app_dict.values()
|
app_list = list(six.itervalues(app_dict))
|
||||||
app_list.sort(key=lambda x: x['name'])
|
app_list.sort(key=lambda x: x['name'])
|
||||||
|
|
||||||
# Sort the models alphabetically within each app.
|
# Sort the models alphabetically within each app.
|
||||||
|
|
|
@ -12,6 +12,7 @@ from django.db import models
|
||||||
from django.utils import formats
|
from django.utils import formats
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils import six
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.utils.encoding import smart_unicode, force_unicode
|
from django.utils.encoding import smart_unicode, force_unicode
|
||||||
|
@ -125,7 +126,7 @@ def result_headers(cl):
|
||||||
if i in ordering_field_columns:
|
if i in ordering_field_columns:
|
||||||
sorted = True
|
sorted = True
|
||||||
order_type = ordering_field_columns.get(i).lower()
|
order_type = ordering_field_columns.get(i).lower()
|
||||||
sort_priority = ordering_field_columns.keys().index(i) + 1
|
sort_priority = list(six.iterkeys(ordering_field_columns)).index(i) + 1
|
||||||
th_classes.append('sorted %sending' % order_type)
|
th_classes.append('sorted %sending' % order_type)
|
||||||
new_order_type = {'asc': 'desc', 'desc': 'asc'}[order_type]
|
new_order_type = {'asc': 'desc', 'desc': 'asc'}[order_type]
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ from django.core import urlresolvers
|
||||||
from django.contrib.admindocs import utils
|
from django.contrib.admindocs import utils
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
|
from django.utils import six
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ def template_tag_index(request):
|
||||||
load_all_installed_template_libraries()
|
load_all_installed_template_libraries()
|
||||||
|
|
||||||
tags = []
|
tags = []
|
||||||
app_libs = template.libraries.items()
|
app_libs = list(six.iteritems(template.libraries))
|
||||||
builtin_libs = [(None, lib) for lib in template.builtins]
|
builtin_libs = [(None, lib) for lib in template.builtins]
|
||||||
for module_name, library in builtin_libs + app_libs:
|
for module_name, library in builtin_libs + app_libs:
|
||||||
for tag_name, tag_func in library.tags.items():
|
for tag_name, tag_func in library.tags.items():
|
||||||
|
@ -83,7 +84,7 @@ def template_filter_index(request):
|
||||||
load_all_installed_template_libraries()
|
load_all_installed_template_libraries()
|
||||||
|
|
||||||
filters = []
|
filters = []
|
||||||
app_libs = template.libraries.items()
|
app_libs = list(six.iteritems(template.libraries))
|
||||||
builtin_libs = [(None, lib) for lib in template.builtins]
|
builtin_libs = [(None, lib) for lib in template.builtins]
|
||||||
for module_name, library in builtin_libs + app_libs:
|
for module_name, library in builtin_libs + app_libs:
|
||||||
for filter_name, filter_func in library.filters.items():
|
for filter_name, filter_func in library.filters.items():
|
||||||
|
|
|
@ -12,6 +12,7 @@ from django.template.response import TemplateResponse
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils import six
|
||||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||||
from django.views.decorators.csrf import csrf_protect
|
from django.views.decorators.csrf import csrf_protect
|
||||||
from django.views.decorators.debug import sensitive_post_parameters
|
from django.views.decorators.debug import sensitive_post_parameters
|
||||||
|
@ -128,7 +129,7 @@ class UserAdmin(admin.ModelAdmin):
|
||||||
else:
|
else:
|
||||||
form = self.change_password_form(user)
|
form = self.change_password_form(user)
|
||||||
|
|
||||||
fieldsets = [(None, {'fields': form.base_fields.keys()})]
|
fieldsets = [(None, {'fields': list(six.iterkeys(form.base_fields))})]
|
||||||
adminForm = admin.helpers.AdminForm(form, fieldsets, {})
|
adminForm = admin.helpers.AdminForm(form, fieldsets, {})
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
|
|
|
@ -9,6 +9,7 @@ from django.forms.fields import Field, EmailField
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_unicode
|
||||||
|
from django.utils import six
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
@ -203,7 +204,7 @@ class PasswordChangeFormTest(TestCase):
|
||||||
def test_field_order(self):
|
def test_field_order(self):
|
||||||
# Regression test - check the order of fields:
|
# Regression test - check the order of fields:
|
||||||
user = User.objects.get(username='testclient')
|
user = User.objects.get(username='testclient')
|
||||||
self.assertEqual(PasswordChangeForm(user, {}).fields.keys(),
|
self.assertEqual(list(six.iterkeys(PasswordChangeForm(user, {}).fields)),
|
||||||
['old_password', 'new_password1', 'new_password2'])
|
['old_password', 'new_password1', 'new_password2'])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db.models import get_apps, get_models, signals
|
from django.db.models import get_apps, get_models, signals
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
def update_contenttypes(app, created_models, verbosity=2, **kwargs):
|
def update_contenttypes(app, created_models, verbosity=2, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -24,7 +25,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
|
||||||
)
|
)
|
||||||
to_remove = [
|
to_remove = [
|
||||||
ct
|
ct
|
||||||
for (model_name, ct) in content_types.iteritems()
|
for (model_name, ct) in six.iteritems(content_types)
|
||||||
if model_name not in app_models
|
if model_name not in app_models
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
|
||||||
app_label=app_label,
|
app_label=app_label,
|
||||||
model=model_name,
|
model=model_name,
|
||||||
)
|
)
|
||||||
for (model_name, model) in app_models.iteritems()
|
for (model_name, model) in six.iteritems(app_models)
|
||||||
if model_name not in content_types
|
if model_name not in content_types
|
||||||
])
|
])
|
||||||
if verbosity >= 2:
|
if verbosity >= 2:
|
||||||
|
|
|
@ -17,7 +17,7 @@ class EasyModel(object):
|
||||||
def __init__(self, site, model):
|
def __init__(self, site, model):
|
||||||
self.site = site
|
self.site = site
|
||||||
self.model = model
|
self.model = model
|
||||||
self.model_list = site.registry.keys()
|
self.model_list = list(site.registry.keys())
|
||||||
self.verbose_name = model._meta.verbose_name
|
self.verbose_name = model._meta.verbose_name
|
||||||
self.verbose_name_plural = model._meta.verbose_name_plural
|
self.verbose_name_plural = model._meta.verbose_name_plural
|
||||||
|
|
||||||
|
@ -176,8 +176,6 @@ class EasyInstanceField(object):
|
||||||
for plugin_name, plugin in self.model.model_databrowse().plugins.items():
|
for plugin_name, plugin in self.model.model_databrowse().plugins.items():
|
||||||
urls = plugin.urls(plugin_name, self)
|
urls = plugin.urls(plugin_name, self)
|
||||||
if urls is not None:
|
if urls is not None:
|
||||||
#plugin_urls.append(urls)
|
|
||||||
values = self.values()
|
|
||||||
return zip(self.values(), urls)
|
return zip(self.values(), urls)
|
||||||
if self.field.rel:
|
if self.field.rel:
|
||||||
m = EasyModel(self.model.site, self.field.rel.to)
|
m = EasyModel(self.model.site, self.field.rel.to)
|
||||||
|
@ -196,10 +194,10 @@ class EasyInstanceField(object):
|
||||||
url = '%s%s/%s/fields/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name, iri_to_uri(self.raw_value))
|
url = '%s%s/%s/fields/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.name, iri_to_uri(self.raw_value))
|
||||||
lst.append((value, url))
|
lst.append((value, url))
|
||||||
elif isinstance(self.field, models.URLField):
|
elif isinstance(self.field, models.URLField):
|
||||||
val = self.values()[0]
|
val = list(self.values())[0]
|
||||||
lst = [(val, iri_to_uri(val))]
|
lst = [(val, iri_to_uri(val))]
|
||||||
else:
|
else:
|
||||||
lst = [(self.values()[0], None)]
|
lst = [(list(self.values())[0], None)]
|
||||||
return lst
|
return lst
|
||||||
|
|
||||||
class EasyQuerySet(QuerySet):
|
class EasyQuerySet(QuerySet):
|
||||||
|
|
|
@ -96,7 +96,7 @@ class CalendarPlugin(DatabrowsePlugin):
|
||||||
|
|
||||||
def homepage_view(self, request):
|
def homepage_view(self, request):
|
||||||
easy_model = EasyModel(self.site, self.model)
|
easy_model = EasyModel(self.site, self.model)
|
||||||
field_list = self.fields.values()
|
field_list = list(self.fields.values())
|
||||||
field_list.sort(key=lambda k:k.verbose_name)
|
field_list.sort(key=lambda k:k.verbose_name)
|
||||||
return render_to_response('databrowse/calendar_homepage.html', {
|
return render_to_response('databrowse/calendar_homepage.html', {
|
||||||
'root_url': self.site.root_url,
|
'root_url': self.site.root_url,
|
||||||
|
|
|
@ -63,7 +63,7 @@ class FieldChoicePlugin(DatabrowsePlugin):
|
||||||
|
|
||||||
def homepage_view(self, request):
|
def homepage_view(self, request):
|
||||||
easy_model = EasyModel(self.site, self.model)
|
easy_model = EasyModel(self.site, self.model)
|
||||||
field_list = self.fields.values()
|
field_list = list(self.fields.values())
|
||||||
field_list.sort(key=lambda k: k.verbose_name)
|
field_list.sort(key=lambda k: k.verbose_name)
|
||||||
return render_to_response('databrowse/fieldchoice_homepage.html', {'root_url': self.site.root_url, 'model': easy_model, 'field_list': field_list})
|
return render_to_response('databrowse/fieldchoice_homepage.html', {'root_url': self.site.root_url, 'model': easy_model, 'field_list': field_list})
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ from django.core.files.uploadedfile import UploadedFile
|
||||||
from django.utils.datastructures import MultiValueDict
|
from django.utils.datastructures import MultiValueDict
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
from django.utils.functional import lazy_property
|
from django.utils.functional import lazy_property
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
from django.contrib.formtools.wizard.storage.exceptions import NoFileStorageConfigured
|
from django.contrib.formtools.wizard.storage.exceptions import NoFileStorageConfigured
|
||||||
|
|
||||||
|
@ -72,9 +73,9 @@ class BaseStorage(object):
|
||||||
raise NoFileStorageConfigured
|
raise NoFileStorageConfigured
|
||||||
|
|
||||||
files = {}
|
files = {}
|
||||||
for field, field_dict in wizard_files.iteritems():
|
for field, field_dict in six.iteritems(wizard_files):
|
||||||
field_dict = dict((smart_str(k), v)
|
field_dict = dict((smart_str(k), v)
|
||||||
for k, v in field_dict.iteritems())
|
for k, v in six.iteritems(field_dict))
|
||||||
tmp_name = field_dict.pop('tmp_name')
|
tmp_name = field_dict.pop('tmp_name')
|
||||||
files[field] = UploadedFile(
|
files[field] = UploadedFile(
|
||||||
file=self.file_storage.open(tmp_name), **field_dict)
|
file=self.file_storage.open(tmp_name), **field_dict)
|
||||||
|
@ -87,7 +88,7 @@ class BaseStorage(object):
|
||||||
if step not in self.data[self.step_files_key]:
|
if step not in self.data[self.step_files_key]:
|
||||||
self.data[self.step_files_key][step] = {}
|
self.data[self.step_files_key][step] = {}
|
||||||
|
|
||||||
for field, field_file in (files or {}).iteritems():
|
for field, field_file in six.iteritems(files or {}):
|
||||||
tmp_filename = self.file_storage.save(field_file.name, field_file)
|
tmp_filename = self.file_storage.save(field_file.name, field_file)
|
||||||
file_dict = {
|
file_dict = {
|
||||||
'tmp_name': tmp_filename,
|
'tmp_name': tmp_filename,
|
||||||
|
|
|
@ -44,7 +44,7 @@ class StepsHelper(object):
|
||||||
@property
|
@property
|
||||||
def all(self):
|
def all(self):
|
||||||
"Returns the names of all steps/forms."
|
"Returns the names of all steps/forms."
|
||||||
return self._wizard.get_form_list().keys()
|
return list(six.iterkeys(self._wizard.get_form_list()))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def count(self):
|
def count(self):
|
||||||
|
@ -164,14 +164,14 @@ class WizardView(TemplateView):
|
||||||
init_form_list[six.text_type(i)] = form
|
init_form_list[six.text_type(i)] = form
|
||||||
|
|
||||||
# walk through the new created list of forms
|
# walk through the new created list of forms
|
||||||
for form in init_form_list.itervalues():
|
for form in six.itervalues(init_form_list):
|
||||||
if issubclass(form, formsets.BaseFormSet):
|
if issubclass(form, formsets.BaseFormSet):
|
||||||
# if the element is based on BaseFormSet (FormSet/ModelFormSet)
|
# if the element is based on BaseFormSet (FormSet/ModelFormSet)
|
||||||
# we need to override the form variable.
|
# we need to override the form variable.
|
||||||
form = form.form
|
form = form.form
|
||||||
# check if any form contains a FileField, if yes, we need a
|
# check if any form contains a FileField, if yes, we need a
|
||||||
# file_storage added to the wizardview (by subclassing).
|
# file_storage added to the wizardview (by subclassing).
|
||||||
for field in form.base_fields.itervalues():
|
for field in six.itervalues(form.base_fields):
|
||||||
if (isinstance(field, forms.FileField) and
|
if (isinstance(field, forms.FileField) and
|
||||||
not hasattr(cls, 'file_storage')):
|
not hasattr(cls, 'file_storage')):
|
||||||
raise NoFileStorageConfigured
|
raise NoFileStorageConfigured
|
||||||
|
@ -196,7 +196,7 @@ class WizardView(TemplateView):
|
||||||
could use data from other (maybe previous forms).
|
could use data from other (maybe previous forms).
|
||||||
"""
|
"""
|
||||||
form_list = SortedDict()
|
form_list = SortedDict()
|
||||||
for form_key, form_class in self.form_list.iteritems():
|
for form_key, form_class in six.iteritems(self.form_list):
|
||||||
# try to fetch the value from condition list, by default, the form
|
# try to fetch the value from condition list, by default, the form
|
||||||
# gets passed to the new list.
|
# gets passed to the new list.
|
||||||
condition = self.condition_dict.get(form_key, True)
|
condition = self.condition_dict.get(form_key, True)
|
||||||
|
|
|
@ -3,6 +3,8 @@ from django.db.backends.mysql.base import DatabaseOperations
|
||||||
from django.contrib.gis.db.backends.adapter import WKTAdapter
|
from django.contrib.gis.db.backends.adapter import WKTAdapter
|
||||||
from django.contrib.gis.db.backends.base import BaseSpatialOperations
|
from django.contrib.gis.db.backends.base import BaseSpatialOperations
|
||||||
|
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
|
class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
|
|
||||||
compiler_module = 'django.contrib.gis.db.backends.mysql.compiler'
|
compiler_module = 'django.contrib.gis.db.backends.mysql.compiler'
|
||||||
|
@ -30,7 +32,7 @@ class MySQLOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
'within' : 'MBRWithin',
|
'within' : 'MBRWithin',
|
||||||
}
|
}
|
||||||
|
|
||||||
gis_terms = dict([(term, None) for term in geometry_functions.keys() + ['isnull']])
|
gis_terms = dict([(term, None) for term in list(six.iterkeys(geometry_functions)) + ['isnull']])
|
||||||
|
|
||||||
def geo_db_type(self, f):
|
def geo_db_type(self, f):
|
||||||
return f.geom_type
|
return f.geom_type
|
||||||
|
|
|
@ -128,7 +128,7 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
geometry_functions.update(distance_functions)
|
geometry_functions.update(distance_functions)
|
||||||
|
|
||||||
gis_terms = ['isnull']
|
gis_terms = ['isnull']
|
||||||
gis_terms += geometry_functions.keys()
|
gis_terms += list(six.iterkeys(geometry_functions))
|
||||||
gis_terms = dict([(term, None) for term in gis_terms])
|
gis_terms = dict([(term, None) for term in gis_terms])
|
||||||
|
|
||||||
truncate_params = {'relate' : None}
|
truncate_params = {'relate' : None}
|
||||||
|
|
|
@ -217,8 +217,8 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
|
|
||||||
# Creating a dictionary lookup of all GIS terms for PostGIS.
|
# Creating a dictionary lookup of all GIS terms for PostGIS.
|
||||||
gis_terms = ['isnull']
|
gis_terms = ['isnull']
|
||||||
gis_terms += self.geometry_operators.keys()
|
gis_terms += list(six.iterkeys(self.geometry_operators))
|
||||||
gis_terms += self.geometry_functions.keys()
|
gis_terms += list(six.iterkeys(self.geometry_functions))
|
||||||
self.gis_terms = dict([(term, None) for term in gis_terms])
|
self.gis_terms = dict([(term, None) for term in gis_terms])
|
||||||
|
|
||||||
self.area = prefix + 'Area'
|
self.area = prefix + 'Area'
|
||||||
|
|
|
@ -131,7 +131,7 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
|
||||||
|
|
||||||
# Creating the GIS terms dictionary.
|
# Creating the GIS terms dictionary.
|
||||||
gis_terms = ['isnull']
|
gis_terms = ['isnull']
|
||||||
gis_terms += self.geometry_functions.keys()
|
gis_terms += list(six.iterkeys(self.geometry_functions))
|
||||||
self.gis_terms = dict([(term, None) for term in gis_terms])
|
self.gis_terms = dict([(term, None) for term in gis_terms])
|
||||||
|
|
||||||
if version >= (2, 4, 0):
|
if version >= (2, 4, 0):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
from django.db.models.query import QuerySet, ValuesQuerySet, ValuesListQuerySet
|
from django.db.models.query import QuerySet, ValuesQuerySet, ValuesListQuerySet
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
from django.contrib.gis.db.models import aggregates
|
from django.contrib.gis.db.models import aggregates
|
||||||
from django.contrib.gis.db.models.fields import get_srid_info, PointField, LineStringField
|
from django.contrib.gis.db.models.fields import get_srid_info, PointField, LineStringField
|
||||||
|
@ -25,7 +26,7 @@ class GeoQuerySet(QuerySet):
|
||||||
flat = kwargs.pop('flat', False)
|
flat = kwargs.pop('flat', False)
|
||||||
if kwargs:
|
if kwargs:
|
||||||
raise TypeError('Unexpected keyword arguments to values_list: %s'
|
raise TypeError('Unexpected keyword arguments to values_list: %s'
|
||||||
% (kwargs.keys(),))
|
% (list(six.iterkeys(kwargs)),))
|
||||||
if flat and len(fields) > 1:
|
if flat and len(fields) > 1:
|
||||||
raise TypeError("'flat' is not valid when values_list is called with more than one field.")
|
raise TypeError("'flat' is not valid when values_list is called with more than one field.")
|
||||||
return self._clone(klass=GeoValuesListQuerySet, setup=True, flat=flat,
|
return self._clone(klass=GeoValuesListQuerySet, setup=True, flat=flat,
|
||||||
|
@ -531,7 +532,7 @@ class GeoQuerySet(QuerySet):
|
||||||
if settings.get('setup', True):
|
if settings.get('setup', True):
|
||||||
default_args, geo_field = self._spatial_setup(att, desc=settings['desc'], field_name=field_name,
|
default_args, geo_field = self._spatial_setup(att, desc=settings['desc'], field_name=field_name,
|
||||||
geo_field_type=settings.get('geo_field_type', None))
|
geo_field_type=settings.get('geo_field_type', None))
|
||||||
for k, v in default_args.iteritems(): settings['procedure_args'].setdefault(k, v)
|
for k, v in six.iteritems(default_args): settings['procedure_args'].setdefault(k, v)
|
||||||
else:
|
else:
|
||||||
geo_field = settings['geo_field']
|
geo_field = settings['geo_field']
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.utils.six.moves import zip
|
||||||
from django.db.backends.util import truncate_name, typecast_timestamp
|
from django.db.backends.util import truncate_name, typecast_timestamp
|
||||||
from django.db.models.sql import compiler
|
from django.db.models.sql import compiler
|
||||||
from django.db.models.sql.constants import MULTI
|
from django.db.models.sql.constants import MULTI
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
SQLCompiler = compiler.SQLCompiler
|
SQLCompiler = compiler.SQLCompiler
|
||||||
|
|
||||||
|
@ -24,7 +25,7 @@ class GeoSQLCompiler(compiler.SQLCompiler):
|
||||||
qn = self.quote_name_unless_alias
|
qn = self.quote_name_unless_alias
|
||||||
qn2 = self.connection.ops.quote_name
|
qn2 = self.connection.ops.quote_name
|
||||||
result = ['(%s) AS %s' % (self.get_extra_select_format(alias) % col[0], qn2(alias))
|
result = ['(%s) AS %s' % (self.get_extra_select_format(alias) % col[0], qn2(alias))
|
||||||
for alias, col in self.query.extra_select.iteritems()]
|
for alias, col in six.iteritems(self.query.extra_select)]
|
||||||
aliases = set(self.query.extra_select.keys())
|
aliases = set(self.query.extra_select.keys())
|
||||||
if with_aliases:
|
if with_aliases:
|
||||||
col_aliases = aliases.copy()
|
col_aliases = aliases.copy()
|
||||||
|
@ -170,7 +171,7 @@ class GeoSQLCompiler(compiler.SQLCompiler):
|
||||||
objects.
|
objects.
|
||||||
"""
|
"""
|
||||||
values = []
|
values = []
|
||||||
aliases = self.query.extra_select.keys()
|
aliases = list(six.iterkeys(self.query.extra_select))
|
||||||
|
|
||||||
# Have to set a starting row number offset that is used for
|
# Have to set a starting row number offset that is used for
|
||||||
# determining the correct starting row index -- needed for
|
# determining the correct starting row index -- needed for
|
||||||
|
|
|
@ -7,6 +7,7 @@ import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.contrib import gis
|
from django.contrib import gis
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
# This global used to store reference geometry data.
|
# This global used to store reference geometry data.
|
||||||
|
@ -25,7 +26,7 @@ def tuplize(seq):
|
||||||
|
|
||||||
def strconvert(d):
|
def strconvert(d):
|
||||||
"Converts all keys in dictionary to str type."
|
"Converts all keys in dictionary to str type."
|
||||||
return dict([(str(k), v) for k, v in d.iteritems()])
|
return dict([(str(k), v) for k, v in six.iteritems(d)])
|
||||||
|
|
||||||
|
|
||||||
def get_ds_file(name, ext):
|
def get_ds_file(name, ext):
|
||||||
|
|
|
@ -169,7 +169,7 @@ class MeasureBase(object):
|
||||||
"""
|
"""
|
||||||
val = 0.0
|
val = 0.0
|
||||||
default_unit = self.STANDARD_UNIT
|
default_unit = self.STANDARD_UNIT
|
||||||
for unit, value in kwargs.iteritems():
|
for unit, value in six.iteritems(kwargs):
|
||||||
if not isinstance(value, float): value = float(value)
|
if not isinstance(value, float): value = float(value)
|
||||||
if unit in self.UNITS:
|
if unit in self.UNITS:
|
||||||
val += self.UNITS[unit] * value
|
val += self.UNITS[unit] * value
|
||||||
|
|
|
@ -9,6 +9,7 @@ from django.contrib.gis.db.models.fields import GeometryField
|
||||||
from django.db import connections, DEFAULT_DB_ALIAS
|
from django.db import connections, DEFAULT_DB_ALIAS
|
||||||
from django.db.models import get_model
|
from django.db.models import get_model
|
||||||
from django.utils.encoding import smart_str
|
from django.utils.encoding import smart_str
|
||||||
|
from django.utils import six
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
|
from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
|
||||||
|
@ -46,7 +47,7 @@ def sitemap(request, sitemaps, section=None):
|
||||||
raise Http404(_("No sitemap available for section: %r") % section)
|
raise Http404(_("No sitemap available for section: %r") % section)
|
||||||
maps.append(sitemaps[section])
|
maps.append(sitemaps[section])
|
||||||
else:
|
else:
|
||||||
maps = sitemaps.values()
|
maps = list(six.itervalues(sitemaps))
|
||||||
|
|
||||||
page = request.GET.get("p", 1)
|
page = request.GET.get("p", 1)
|
||||||
current_site = get_current_site(request)
|
current_site = get_current_site(request)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.conf import settings
|
||||||
from django.contrib.messages.storage.base import BaseStorage, Message
|
from django.contrib.messages.storage.base import BaseStorage, Message
|
||||||
from django.http import SimpleCookie
|
from django.http import SimpleCookie
|
||||||
from django.utils.crypto import salted_hmac, constant_time_compare
|
from django.utils.crypto import salted_hmac, constant_time_compare
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
class MessageEncoder(json.JSONEncoder):
|
class MessageEncoder(json.JSONEncoder):
|
||||||
|
@ -33,7 +34,7 @@ class MessageDecoder(json.JSONDecoder):
|
||||||
return [self.process_messages(item) for item in obj]
|
return [self.process_messages(item) for item in obj]
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
return dict([(key, self.process_messages(value))
|
return dict([(key, self.process_messages(value))
|
||||||
for key, value in obj.iteritems()])
|
for key, value in six.iteritems(obj)])
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def decode(self, s, **kwargs):
|
def decode(self, s, **kwargs):
|
||||||
|
|
|
@ -16,6 +16,7 @@ from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import TestCase, RequestFactory
|
from django.test import TestCase, RequestFactory
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
from django.utils import six
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
|
||||||
|
@ -86,16 +87,16 @@ class SessionTestsMixin(object):
|
||||||
self.assertFalse(self.session.modified)
|
self.assertFalse(self.session.modified)
|
||||||
|
|
||||||
def test_values(self):
|
def test_values(self):
|
||||||
self.assertEqual(self.session.values(), [])
|
self.assertEqual(list(self.session.values()), [])
|
||||||
self.assertTrue(self.session.accessed)
|
self.assertTrue(self.session.accessed)
|
||||||
self.session['some key'] = 1
|
self.session['some key'] = 1
|
||||||
self.assertEqual(self.session.values(), [1])
|
self.assertEqual(list(self.session.values()), [1])
|
||||||
|
|
||||||
def test_iterkeys(self):
|
def test_iterkeys(self):
|
||||||
self.session['x'] = 1
|
self.session['x'] = 1
|
||||||
self.session.modified = False
|
self.session.modified = False
|
||||||
self.session.accessed = False
|
self.session.accessed = False
|
||||||
i = self.session.iterkeys()
|
i = six.iterkeys(self.session)
|
||||||
self.assertTrue(hasattr(i, '__iter__'))
|
self.assertTrue(hasattr(i, '__iter__'))
|
||||||
self.assertTrue(self.session.accessed)
|
self.assertTrue(self.session.accessed)
|
||||||
self.assertFalse(self.session.modified)
|
self.assertFalse(self.session.modified)
|
||||||
|
@ -105,7 +106,7 @@ class SessionTestsMixin(object):
|
||||||
self.session['x'] = 1
|
self.session['x'] = 1
|
||||||
self.session.modified = False
|
self.session.modified = False
|
||||||
self.session.accessed = False
|
self.session.accessed = False
|
||||||
i = self.session.itervalues()
|
i = six.itervalues(self.session)
|
||||||
self.assertTrue(hasattr(i, '__iter__'))
|
self.assertTrue(hasattr(i, '__iter__'))
|
||||||
self.assertTrue(self.session.accessed)
|
self.assertTrue(self.session.accessed)
|
||||||
self.assertFalse(self.session.modified)
|
self.assertFalse(self.session.modified)
|
||||||
|
@ -115,7 +116,7 @@ class SessionTestsMixin(object):
|
||||||
self.session['x'] = 1
|
self.session['x'] = 1
|
||||||
self.session.modified = False
|
self.session.modified = False
|
||||||
self.session.accessed = False
|
self.session.accessed = False
|
||||||
i = self.session.iteritems()
|
i = six.iteritems(self.session)
|
||||||
self.assertTrue(hasattr(i, '__iter__'))
|
self.assertTrue(hasattr(i, '__iter__'))
|
||||||
self.assertTrue(self.session.accessed)
|
self.assertTrue(self.session.accessed)
|
||||||
self.assertFalse(self.session.modified)
|
self.assertFalse(self.session.modified)
|
||||||
|
@ -125,9 +126,9 @@ class SessionTestsMixin(object):
|
||||||
self.session['x'] = 1
|
self.session['x'] = 1
|
||||||
self.session.modified = False
|
self.session.modified = False
|
||||||
self.session.accessed = False
|
self.session.accessed = False
|
||||||
self.assertEqual(self.session.items(), [('x', 1)])
|
self.assertEqual(list(self.session.items()), [('x', 1)])
|
||||||
self.session.clear()
|
self.session.clear()
|
||||||
self.assertEqual(self.session.items(), [])
|
self.assertEqual(list(self.session.items()), [])
|
||||||
self.assertTrue(self.session.accessed)
|
self.assertTrue(self.session.accessed)
|
||||||
self.assertTrue(self.session.modified)
|
self.assertTrue(self.session.modified)
|
||||||
|
|
||||||
|
@ -154,10 +155,10 @@ class SessionTestsMixin(object):
|
||||||
self.session['a'], self.session['b'] = 'c', 'd'
|
self.session['a'], self.session['b'] = 'c', 'd'
|
||||||
self.session.save()
|
self.session.save()
|
||||||
prev_key = self.session.session_key
|
prev_key = self.session.session_key
|
||||||
prev_data = self.session.items()
|
prev_data = list(self.session.items())
|
||||||
self.session.cycle_key()
|
self.session.cycle_key()
|
||||||
self.assertNotEqual(self.session.session_key, prev_key)
|
self.assertNotEqual(self.session.session_key, prev_key)
|
||||||
self.assertEqual(self.session.items(), prev_data)
|
self.assertEqual(list(self.session.items()), prev_data)
|
||||||
|
|
||||||
def test_invalid_key(self):
|
def test_invalid_key(self):
|
||||||
# Submitting an invalid session key (either by guessing, or if the db has
|
# Submitting an invalid session key (either by guessing, or if the db has
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.core import urlresolvers
|
||||||
from django.core.paginator import EmptyPage, PageNotAnInteger
|
from django.core.paginator import EmptyPage, PageNotAnInteger
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
def index(request, sitemaps,
|
def index(request, sitemaps,
|
||||||
template_name='sitemap_index.xml', mimetype='application/xml',
|
template_name='sitemap_index.xml', mimetype='application/xml',
|
||||||
|
@ -35,7 +36,7 @@ def sitemap(request, sitemaps, section=None,
|
||||||
raise Http404("No sitemap available for section: %r" % section)
|
raise Http404("No sitemap available for section: %r" % section)
|
||||||
maps = [sitemaps[section]]
|
maps = [sitemaps[section]]
|
||||||
else:
|
else:
|
||||||
maps = sitemaps.values()
|
maps = list(six.itervalues(sitemaps))
|
||||||
page = request.GET.get("p", 1)
|
page = request.GET.get("p", 1)
|
||||||
|
|
||||||
urls = []
|
urls = []
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.utils.datastructures import SortedDict
|
||||||
from django.utils.functional import empty, memoize, LazyObject
|
from django.utils.functional import empty, memoize, LazyObject
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
from django.utils._os import safe_join
|
from django.utils._os import safe_join
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
from django.contrib.staticfiles import utils
|
from django.contrib.staticfiles import utils
|
||||||
from django.contrib.staticfiles.storage import AppStaticStorage
|
from django.contrib.staticfiles.storage import AppStaticStorage
|
||||||
|
@ -132,7 +133,7 @@ class AppDirectoriesFinder(BaseFinder):
|
||||||
"""
|
"""
|
||||||
List all files in all app storages.
|
List all files in all app storages.
|
||||||
"""
|
"""
|
||||||
for storage in self.storages.itervalues():
|
for storage in six.itervalues(self.storages):
|
||||||
if storage.exists(''): # check if storage location exists
|
if storage.exists(''): # check if storage location exists
|
||||||
for path in utils.get_files(storage, ignore_patterns):
|
for path in utils.get_files(storage, ignore_patterns):
|
||||||
yield path, storage
|
yield path, storage
|
||||||
|
|
|
@ -8,6 +8,7 @@ import warnings
|
||||||
from django.core.management.base import BaseCommand, CommandError, handle_default_options
|
from django.core.management.base import BaseCommand, CommandError, handle_default_options
|
||||||
from django.core.management.color import color_style
|
from django.core.management.color import color_style
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
# For backwards compatibility: get_version() used to be in this module.
|
# For backwards compatibility: get_version() used to be in this module.
|
||||||
from django import get_version
|
from django import get_version
|
||||||
|
@ -228,7 +229,7 @@ class ManagementUtility(object):
|
||||||
"Available subcommands:",
|
"Available subcommands:",
|
||||||
]
|
]
|
||||||
commands_dict = collections.defaultdict(lambda: [])
|
commands_dict = collections.defaultdict(lambda: [])
|
||||||
for name, app in get_commands().iteritems():
|
for name, app in six.iteritems(get_commands()):
|
||||||
if app == 'django.core':
|
if app == 'django.core':
|
||||||
app = 'django'
|
app = 'django'
|
||||||
else:
|
else:
|
||||||
|
@ -294,7 +295,7 @@ class ManagementUtility(object):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
curr = ''
|
curr = ''
|
||||||
|
|
||||||
subcommands = get_commands().keys() + ['help']
|
subcommands = list(six.iterkeys(get_commands())) + ['help']
|
||||||
options = [('--help', None)]
|
options = [('--help', None)]
|
||||||
|
|
||||||
# subcommand
|
# subcommand
|
||||||
|
|
|
@ -22,9 +22,7 @@ class Command(NoArgsCommand):
|
||||||
default_settings = module_to_dict(global_settings)
|
default_settings = module_to_dict(global_settings)
|
||||||
|
|
||||||
output = []
|
output = []
|
||||||
keys = user_settings.keys()
|
for key in sorted(user_settings.keys()):
|
||||||
keys.sort()
|
|
||||||
for key in keys:
|
|
||||||
if key not in default_settings:
|
if key not in default_settings:
|
||||||
output.append("%s = %s ###" % (key, user_settings[key]))
|
output.append("%s = %s ###" % (key, user_settings[key]))
|
||||||
elif user_settings[key] != default_settings[key]:
|
elif user_settings[key] != default_settings[key]:
|
||||||
|
|
|
@ -18,6 +18,7 @@ To add your own serializers, use the SERIALIZATION_MODULES setting::
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import importlib
|
from django.utils import importlib
|
||||||
|
from django.utils import six
|
||||||
from django.core.serializers.base import SerializerDoesNotExist
|
from django.core.serializers.base import SerializerDoesNotExist
|
||||||
|
|
||||||
# Built-in serializers
|
# Built-in serializers
|
||||||
|
@ -75,12 +76,12 @@ def get_serializer(format):
|
||||||
def get_serializer_formats():
|
def get_serializer_formats():
|
||||||
if not _serializers:
|
if not _serializers:
|
||||||
_load_serializers()
|
_load_serializers()
|
||||||
return _serializers.keys()
|
return list(six.iterkeys(_serializers))
|
||||||
|
|
||||||
def get_public_serializer_formats():
|
def get_public_serializer_formats():
|
||||||
if not _serializers:
|
if not _serializers:
|
||||||
_load_serializers()
|
_load_serializers()
|
||||||
return [k for k, v in _serializers.iteritems() if not v.Serializer.internal_use_only]
|
return [k for k, v in six.iteritems(_serializers) if not v.Serializer.internal_use_only]
|
||||||
|
|
||||||
def get_deserializer(format):
|
def get_deserializer(format):
|
||||||
if not _serializers:
|
if not _serializers:
|
||||||
|
|
|
@ -9,6 +9,7 @@ from django.conf import settings
|
||||||
from django.core.serializers import base
|
from django.core.serializers import base
|
||||||
from django.db import models, DEFAULT_DB_ALIAS
|
from django.db import models, DEFAULT_DB_ALIAS
|
||||||
from django.utils.encoding import smart_unicode, is_protected_type
|
from django.utils.encoding import smart_unicode, is_protected_type
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
class Serializer(base.Serializer):
|
class Serializer(base.Serializer):
|
||||||
"""
|
"""
|
||||||
|
@ -87,7 +88,7 @@ def Deserializer(object_list, **options):
|
||||||
m2m_data = {}
|
m2m_data = {}
|
||||||
|
|
||||||
# Handle each field
|
# Handle each field
|
||||||
for (field_name, field_value) in d["fields"].iteritems():
|
for (field_name, field_value) in six.iteritems(d["fields"]):
|
||||||
if isinstance(field_value, str):
|
if isinstance(field_value, str):
|
||||||
field_value = smart_unicode(field_value, options.get("encoding", settings.DEFAULT_CHARSET), strings_only=True)
|
field_value = smart_unicode(field_value, options.get("encoding", settings.DEFAULT_CHARSET), strings_only=True)
|
||||||
|
|
||||||
|
|
|
@ -376,7 +376,7 @@ class RegexURLResolver(LocaleRegexProvider):
|
||||||
unicode_args = [force_unicode(val) for val in args]
|
unicode_args = [force_unicode(val) for val in args]
|
||||||
candidate = (prefix_norm + result) % dict(zip(prefix_args + params, unicode_args))
|
candidate = (prefix_norm + result) % dict(zip(prefix_args + params, unicode_args))
|
||||||
else:
|
else:
|
||||||
if set(kwargs.keys() + defaults.keys()) != set(params + defaults.keys() + prefix_args):
|
if set(kwargs.keys()) | set(defaults.keys()) != set(params) | set(defaults.keys()) | set(prefix_args):
|
||||||
continue
|
continue
|
||||||
matches = True
|
matches = True
|
||||||
for k, v in defaults.items():
|
for k, v in defaults.items():
|
||||||
|
|
|
@ -138,7 +138,7 @@ def ip_address_validators(protocol, unpack_ipv4):
|
||||||
return ip_address_validator_map[protocol.lower()]
|
return ip_address_validator_map[protocol.lower()]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError("The protocol '%s' is unknown. Supported: %s"
|
raise ValueError("The protocol '%s' is unknown. Supported: %s"
|
||||||
% (protocol, ip_address_validator_map.keys()))
|
% (protocol, list(six.iterkeys(ip_address_validator_map))))
|
||||||
|
|
||||||
comma_separated_int_list_re = re.compile('^[\d,]+$')
|
comma_separated_int_list_re = re.compile('^[\d,]+$')
|
||||||
validate_comma_separated_integer_list = RegexValidator(comma_separated_int_list_re, _('Enter only digits separated by commas.'), 'invalid')
|
validate_comma_separated_integer_list = RegexValidator(comma_separated_int_list_re, _('Enter only digits separated by commas.'), 'invalid')
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from django.db.backends import BaseDatabaseIntrospection
|
from django.db.backends import BaseDatabaseIntrospection
|
||||||
|
from django.utils import six
|
||||||
from MySQLdb import ProgrammingError, OperationalError
|
from MySQLdb import ProgrammingError, OperationalError
|
||||||
from MySQLdb.constants import FIELD_TYPE
|
from MySQLdb.constants import FIELD_TYPE
|
||||||
import re
|
import re
|
||||||
|
@ -79,7 +80,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||||
"""
|
"""
|
||||||
Returns the name of the primary key column for the given table
|
Returns the name of the primary key column for the given table
|
||||||
"""
|
"""
|
||||||
for column in self.get_indexes(cursor, table_name).iteritems():
|
for column in six.iteritems(self.get_indexes(cursor, table_name)):
|
||||||
if column[1]['primary_key']:
|
if column[1]['primary_key']:
|
||||||
return column[0]
|
return column[0]
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -364,14 +364,14 @@ class Model(six.with_metaclass(ModelBase, object)):
|
||||||
setattr(self, field.attname, val)
|
setattr(self, field.attname, val)
|
||||||
|
|
||||||
if kwargs:
|
if kwargs:
|
||||||
for prop in kwargs.keys():
|
for prop in list(six.iterkeys(kwargs)):
|
||||||
try:
|
try:
|
||||||
if isinstance(getattr(self.__class__, prop), property):
|
if isinstance(getattr(self.__class__, prop), property):
|
||||||
setattr(self, prop, kwargs.pop(prop))
|
setattr(self, prop, kwargs.pop(prop))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
if kwargs:
|
if kwargs:
|
||||||
raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])
|
raise TypeError("'%s' is an invalid keyword argument for this function" % list(six.iterkeys(kwargs))[0])
|
||||||
super(Model, self).__init__()
|
super(Model, self).__init__()
|
||||||
signals.post_init.send(sender=self.__class__, instance=self)
|
signals.post_init.send(sender=self.__class__, instance=self)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ from operator import attrgetter
|
||||||
from django.db import connections, transaction, IntegrityError
|
from django.db import connections, transaction, IntegrityError
|
||||||
from django.db.models import signals, sql
|
from django.db.models import signals, sql
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
class ProtectedError(IntegrityError):
|
class ProtectedError(IntegrityError):
|
||||||
|
@ -157,7 +158,7 @@ class Collector(object):
|
||||||
# Recursively collect concrete model's parent models, but not their
|
# Recursively collect concrete model's parent models, but not their
|
||||||
# related objects. These will be found by meta.get_all_related_objects()
|
# related objects. These will be found by meta.get_all_related_objects()
|
||||||
concrete_model = model._meta.concrete_model
|
concrete_model = model._meta.concrete_model
|
||||||
for ptr in concrete_model._meta.parents.itervalues():
|
for ptr in six.itervalues(concrete_model._meta.parents):
|
||||||
if ptr:
|
if ptr:
|
||||||
parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
|
parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
|
||||||
self.collect(parent_objs, source=model,
|
self.collect(parent_objs, source=model,
|
||||||
|
@ -199,14 +200,14 @@ class Collector(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
def instances_with_model(self):
|
def instances_with_model(self):
|
||||||
for model, instances in self.data.iteritems():
|
for model, instances in six.iteritems(self.data):
|
||||||
for obj in instances:
|
for obj in instances:
|
||||||
yield model, obj
|
yield model, obj
|
||||||
|
|
||||||
def sort(self):
|
def sort(self):
|
||||||
sorted_models = []
|
sorted_models = []
|
||||||
concrete_models = set()
|
concrete_models = set()
|
||||||
models = self.data.keys()
|
models = list(six.iterkeys(self.data))
|
||||||
while len(sorted_models) < len(models):
|
while len(sorted_models) < len(models):
|
||||||
found = False
|
found = False
|
||||||
for model in models:
|
for model in models:
|
||||||
|
@ -241,24 +242,24 @@ class Collector(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
# update fields
|
# update fields
|
||||||
for model, instances_for_fieldvalues in self.field_updates.iteritems():
|
for model, instances_for_fieldvalues in six.iteritems(self.field_updates):
|
||||||
query = sql.UpdateQuery(model)
|
query = sql.UpdateQuery(model)
|
||||||
for (field, value), instances in instances_for_fieldvalues.iteritems():
|
for (field, value), instances in six.iteritems(instances_for_fieldvalues):
|
||||||
query.update_batch([obj.pk for obj in instances],
|
query.update_batch([obj.pk for obj in instances],
|
||||||
{field.name: value}, self.using)
|
{field.name: value}, self.using)
|
||||||
|
|
||||||
# reverse instance collections
|
# reverse instance collections
|
||||||
for instances in self.data.itervalues():
|
for instances in six.itervalues(self.data):
|
||||||
instances.reverse()
|
instances.reverse()
|
||||||
|
|
||||||
# delete batches
|
# delete batches
|
||||||
for model, batches in self.batches.iteritems():
|
for model, batches in six.iteritems(self.batches):
|
||||||
query = sql.DeleteQuery(model)
|
query = sql.DeleteQuery(model)
|
||||||
for field, instances in batches.iteritems():
|
for field, instances in six.iteritems(batches):
|
||||||
query.delete_batch([obj.pk for obj in instances], self.using, field)
|
query.delete_batch([obj.pk for obj in instances], self.using, field)
|
||||||
|
|
||||||
# delete instances
|
# delete instances
|
||||||
for model, instances in self.data.iteritems():
|
for model, instances in six.iteritems(self.data):
|
||||||
query = sql.DeleteQuery(model)
|
query = sql.DeleteQuery(model)
|
||||||
pk_list = [obj.pk for obj in instances]
|
pk_list = [obj.pk for obj in instances]
|
||||||
query.delete_batch(pk_list, self.using)
|
query.delete_batch(pk_list, self.using)
|
||||||
|
@ -271,10 +272,10 @@ class Collector(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
# update collected instances
|
# update collected instances
|
||||||
for model, instances_for_fieldvalues in self.field_updates.iteritems():
|
for model, instances_for_fieldvalues in six.iteritems(self.field_updates):
|
||||||
for (field, value), instances in instances_for_fieldvalues.iteritems():
|
for (field, value), instances in six.iteritems(instances_for_fieldvalues):
|
||||||
for obj in instances:
|
for obj in instances:
|
||||||
setattr(obj, field.attname, value)
|
setattr(obj, field.attname, value)
|
||||||
for model, instances in self.data.iteritems():
|
for model, instances in six.iteritems(self.data):
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
setattr(instance, model._meta.pk.attname, None)
|
setattr(instance, model._meta.pk.attname, None)
|
||||||
|
|
|
@ -241,7 +241,7 @@ class SingleRelatedObjectDescriptor(object):
|
||||||
rel_obj_attr = attrgetter(self.related.field.attname)
|
rel_obj_attr = attrgetter(self.related.field.attname)
|
||||||
instance_attr = lambda obj: obj._get_pk_val()
|
instance_attr = lambda obj: obj._get_pk_val()
|
||||||
instances_dict = dict((instance_attr(inst), inst) for inst in instances)
|
instances_dict = dict((instance_attr(inst), inst) for inst in instances)
|
||||||
params = {'%s__pk__in' % self.related.field.name: instances_dict.keys()}
|
params = {'%s__pk__in' % self.related.field.name: list(six.iterkeys(instances_dict))}
|
||||||
qs = self.get_query_set(instance=instances[0]).filter(**params)
|
qs = self.get_query_set(instance=instances[0]).filter(**params)
|
||||||
# Since we're going to assign directly in the cache,
|
# Since we're going to assign directly in the cache,
|
||||||
# we must manage the reverse relation cache manually.
|
# we must manage the reverse relation cache manually.
|
||||||
|
@ -335,9 +335,9 @@ class ReverseSingleRelatedObjectDescriptor(object):
|
||||||
instance_attr = attrgetter(self.field.attname)
|
instance_attr = attrgetter(self.field.attname)
|
||||||
instances_dict = dict((instance_attr(inst), inst) for inst in instances)
|
instances_dict = dict((instance_attr(inst), inst) for inst in instances)
|
||||||
if other_field.rel:
|
if other_field.rel:
|
||||||
params = {'%s__pk__in' % self.field.rel.field_name: instances_dict.keys()}
|
params = {'%s__pk__in' % self.field.rel.field_name: list(six.iterkeys(instances_dict))}
|
||||||
else:
|
else:
|
||||||
params = {'%s__in' % self.field.rel.field_name: instances_dict.keys()}
|
params = {'%s__in' % self.field.rel.field_name: list(six.iterkeys(instances_dict))}
|
||||||
qs = self.get_query_set(instance=instances[0]).filter(**params)
|
qs = self.get_query_set(instance=instances[0]).filter(**params)
|
||||||
# Since we're going to assign directly in the cache,
|
# Since we're going to assign directly in the cache,
|
||||||
# we must manage the reverse relation cache manually.
|
# we must manage the reverse relation cache manually.
|
||||||
|
@ -488,7 +488,7 @@ class ForeignRelatedObjectsDescriptor(object):
|
||||||
instance_attr = attrgetter(attname)
|
instance_attr = attrgetter(attname)
|
||||||
instances_dict = dict((instance_attr(inst), inst) for inst in instances)
|
instances_dict = dict((instance_attr(inst), inst) for inst in instances)
|
||||||
db = self._db or router.db_for_read(self.model, instance=instances[0])
|
db = self._db or router.db_for_read(self.model, instance=instances[0])
|
||||||
query = {'%s__%s__in' % (rel_field.name, attname): instances_dict.keys()}
|
query = {'%s__%s__in' % (rel_field.name, attname): list(six.iterkeys(instances_dict))}
|
||||||
qs = super(RelatedManager, self).get_query_set().using(db).filter(**query)
|
qs = super(RelatedManager, self).get_query_set().using(db).filter(**query)
|
||||||
# Since we just bypassed this class' get_query_set(), we must manage
|
# Since we just bypassed this class' get_query_set(), we must manage
|
||||||
# the reverse relation manually.
|
# the reverse relation manually.
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
from django.utils.module_loading import module_has_submodule
|
from django.utils.module_loading import module_has_submodule
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
import imp
|
import imp
|
||||||
import sys
|
import sys
|
||||||
|
@ -193,9 +194,9 @@ class AppCache(object):
|
||||||
else:
|
else:
|
||||||
if only_installed:
|
if only_installed:
|
||||||
app_list = [self.app_models.get(app_label, SortedDict())
|
app_list = [self.app_models.get(app_label, SortedDict())
|
||||||
for app_label in self.app_labels.iterkeys()]
|
for app_label in six.iterkeys(self.app_labels)]
|
||||||
else:
|
else:
|
||||||
app_list = self.app_models.itervalues()
|
app_list = six.itervalues(self.app_models)
|
||||||
model_list = []
|
model_list = []
|
||||||
for app in app_list:
|
for app in app_list:
|
||||||
model_list.extend(
|
model_list.extend(
|
||||||
|
|
|
@ -127,7 +127,7 @@ class Options(object):
|
||||||
if self.parents:
|
if self.parents:
|
||||||
# Promote the first parent link in lieu of adding yet another
|
# Promote the first parent link in lieu of adding yet another
|
||||||
# field.
|
# field.
|
||||||
field = next(self.parents.itervalues())
|
field = next(six.itervalues(self.parents))
|
||||||
# Look for a local field with the same name as the
|
# Look for a local field with the same name as the
|
||||||
# first parent link. If a local field has already been
|
# first parent link. If a local field has already been
|
||||||
# created, use it instead of promoting the parent
|
# created, use it instead of promoting the parent
|
||||||
|
@ -147,13 +147,13 @@ class Options(object):
|
||||||
# self.duplicate_targets will map each duplicate field column to the
|
# self.duplicate_targets will map each duplicate field column to the
|
||||||
# columns it duplicates.
|
# columns it duplicates.
|
||||||
collections = {}
|
collections = {}
|
||||||
for column, target in self.duplicate_targets.iteritems():
|
for column, target in six.iteritems(self.duplicate_targets):
|
||||||
try:
|
try:
|
||||||
collections[target].add(column)
|
collections[target].add(column)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
collections[target] = set([column])
|
collections[target] = set([column])
|
||||||
self.duplicate_targets = {}
|
self.duplicate_targets = {}
|
||||||
for elt in collections.itervalues():
|
for elt in six.itervalues(collections):
|
||||||
if len(elt) == 1:
|
if len(elt) == 1:
|
||||||
continue
|
continue
|
||||||
for column in elt:
|
for column in elt:
|
||||||
|
@ -258,7 +258,7 @@ class Options(object):
|
||||||
self._m2m_cache
|
self._m2m_cache
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self._fill_m2m_cache()
|
self._fill_m2m_cache()
|
||||||
return self._m2m_cache.keys()
|
return list(six.iterkeys(self._m2m_cache))
|
||||||
many_to_many = property(_many_to_many)
|
many_to_many = property(_many_to_many)
|
||||||
|
|
||||||
def get_m2m_with_model(self):
|
def get_m2m_with_model(self):
|
||||||
|
@ -269,7 +269,7 @@ class Options(object):
|
||||||
self._m2m_cache
|
self._m2m_cache
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self._fill_m2m_cache()
|
self._fill_m2m_cache()
|
||||||
return self._m2m_cache.items()
|
return list(six.iteritems(self._m2m_cache))
|
||||||
|
|
||||||
def _fill_m2m_cache(self):
|
def _fill_m2m_cache(self):
|
||||||
cache = SortedDict()
|
cache = SortedDict()
|
||||||
|
@ -326,8 +326,7 @@ class Options(object):
|
||||||
cache = self._name_map
|
cache = self._name_map
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
cache = self.init_name_map()
|
cache = self.init_name_map()
|
||||||
names = cache.keys()
|
names = sorted(cache.keys())
|
||||||
names.sort()
|
|
||||||
# Internal-only names end with "+" (symmetrical m2m related names being
|
# Internal-only names end with "+" (symmetrical m2m related names being
|
||||||
# the main example). Trim them.
|
# the main example). Trim them.
|
||||||
return [val for val in names if not val.endswith('+')]
|
return [val for val in names if not val.endswith('+')]
|
||||||
|
@ -417,7 +416,7 @@ class Options(object):
|
||||||
cache = self._fill_related_many_to_many_cache()
|
cache = self._fill_related_many_to_many_cache()
|
||||||
if local_only:
|
if local_only:
|
||||||
return [k for k, v in cache.items() if not v]
|
return [k for k, v in cache.items() if not v]
|
||||||
return cache.keys()
|
return list(six.iterkeys(cache))
|
||||||
|
|
||||||
def get_all_related_m2m_objects_with_model(self):
|
def get_all_related_m2m_objects_with_model(self):
|
||||||
"""
|
"""
|
||||||
|
@ -428,7 +427,7 @@ class Options(object):
|
||||||
cache = self._related_many_to_many_cache
|
cache = self._related_many_to_many_cache
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
cache = self._fill_related_many_to_many_cache()
|
cache = self._fill_related_many_to_many_cache()
|
||||||
return cache.items()
|
return list(six.iteritems(cache))
|
||||||
|
|
||||||
def _fill_related_many_to_many_cache(self):
|
def _fill_related_many_to_many_cache(self):
|
||||||
cache = SortedDict()
|
cache = SortedDict()
|
||||||
|
|
|
@ -245,8 +245,8 @@ class QuerySet(object):
|
||||||
requested = None
|
requested = None
|
||||||
max_depth = self.query.max_depth
|
max_depth = self.query.max_depth
|
||||||
|
|
||||||
extra_select = self.query.extra_select.keys()
|
extra_select = list(six.iterkeys(self.query.extra_select))
|
||||||
aggregate_select = self.query.aggregate_select.keys()
|
aggregate_select = list(six.iterkeys(self.query.aggregate_select))
|
||||||
|
|
||||||
only_load = self.query.get_loaded_field_names()
|
only_load = self.query.get_loaded_field_names()
|
||||||
if not fill_cache:
|
if not fill_cache:
|
||||||
|
@ -593,7 +593,7 @@ class QuerySet(object):
|
||||||
flat = kwargs.pop('flat', False)
|
flat = kwargs.pop('flat', False)
|
||||||
if kwargs:
|
if kwargs:
|
||||||
raise TypeError('Unexpected keyword arguments to values_list: %s'
|
raise TypeError('Unexpected keyword arguments to values_list: %s'
|
||||||
% (kwargs.keys(),))
|
% (list(six.iterkeys(kwargs)),))
|
||||||
if flat and len(fields) > 1:
|
if flat and len(fields) > 1:
|
||||||
raise TypeError("'flat' is not valid when values_list is called with more than one field.")
|
raise TypeError("'flat' is not valid when values_list is called with more than one field.")
|
||||||
return self._clone(klass=ValuesListQuerySet, setup=True, flat=flat,
|
return self._clone(klass=ValuesListQuerySet, setup=True, flat=flat,
|
||||||
|
@ -693,7 +693,7 @@ class QuerySet(object):
|
||||||
depth = kwargs.pop('depth', 0)
|
depth = kwargs.pop('depth', 0)
|
||||||
if kwargs:
|
if kwargs:
|
||||||
raise TypeError('Unexpected keyword arguments to select_related: %s'
|
raise TypeError('Unexpected keyword arguments to select_related: %s'
|
||||||
% (kwargs.keys(),))
|
% (list(six.iterkeys(kwargs)),))
|
||||||
obj = self._clone()
|
obj = self._clone()
|
||||||
if fields:
|
if fields:
|
||||||
if depth:
|
if depth:
|
||||||
|
@ -751,7 +751,7 @@ class QuerySet(object):
|
||||||
|
|
||||||
obj = self._clone()
|
obj = self._clone()
|
||||||
|
|
||||||
obj._setup_aggregate_query(kwargs.keys())
|
obj._setup_aggregate_query(list(six.iterkeys(kwargs)))
|
||||||
|
|
||||||
# Add the aggregates to the query
|
# Add the aggregates to the query
|
||||||
for (alias, aggregate_expr) in kwargs.items():
|
for (alias, aggregate_expr) in kwargs.items():
|
||||||
|
@ -966,9 +966,9 @@ class ValuesQuerySet(QuerySet):
|
||||||
|
|
||||||
def iterator(self):
|
def iterator(self):
|
||||||
# Purge any extra columns that haven't been explicitly asked for
|
# Purge any extra columns that haven't been explicitly asked for
|
||||||
extra_names = self.query.extra_select.keys()
|
extra_names = list(six.iterkeys(self.query.extra_select))
|
||||||
field_names = self.field_names
|
field_names = self.field_names
|
||||||
aggregate_names = self.query.aggregate_select.keys()
|
aggregate_names = list(six.iterkeys(self.query.aggregate_select))
|
||||||
|
|
||||||
names = extra_names + field_names + aggregate_names
|
names = extra_names + field_names + aggregate_names
|
||||||
|
|
||||||
|
@ -1097,9 +1097,9 @@ class ValuesListQuerySet(ValuesQuerySet):
|
||||||
# When extra(select=...) or an annotation is involved, the extra
|
# When extra(select=...) or an annotation is involved, the extra
|
||||||
# cols are always at the start of the row, and we need to reorder
|
# cols are always at the start of the row, and we need to reorder
|
||||||
# the fields to match the order in self._fields.
|
# the fields to match the order in self._fields.
|
||||||
extra_names = self.query.extra_select.keys()
|
extra_names = list(six.iterkeys(self.query.extra_select))
|
||||||
field_names = self.field_names
|
field_names = self.field_names
|
||||||
aggregate_names = self.query.aggregate_select.keys()
|
aggregate_names = list(six.iterkeys(self.query.aggregate_select))
|
||||||
|
|
||||||
names = extra_names + field_names + aggregate_names
|
names = extra_names + field_names + aggregate_names
|
||||||
|
|
||||||
|
@ -1527,7 +1527,7 @@ class RawQuerySet(object):
|
||||||
# Associate fields to values
|
# Associate fields to values
|
||||||
if skip:
|
if skip:
|
||||||
model_init_kwargs = {}
|
model_init_kwargs = {}
|
||||||
for attname, pos in model_init_field_names.iteritems():
|
for attname, pos in six.iteritems(model_init_field_names):
|
||||||
model_init_kwargs[attname] = values[pos]
|
model_init_kwargs[attname] = values[pos]
|
||||||
instance = model_cls(**model_init_kwargs)
|
instance = model_cls(**model_init_kwargs)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -8,6 +8,7 @@ circular import difficulties.
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db.backends import util
|
from django.db.backends import util
|
||||||
|
from django.utils import six
|
||||||
from django.utils import tree
|
from django.utils import tree
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ class Q(tree.Node):
|
||||||
default = AND
|
default = AND
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Q, self).__init__(children=list(args) + kwargs.items())
|
super(Q, self).__init__(children=list(args) + list(six.iteritems(kwargs)))
|
||||||
|
|
||||||
def _combine(self, other, conn):
|
def _combine(self, other, conn):
|
||||||
if not isinstance(other, Q):
|
if not isinstance(other, Q):
|
||||||
|
@ -114,7 +115,7 @@ class DeferredAttribute(object):
|
||||||
|
|
||||||
def _check_parent_chain(self, instance, name):
|
def _check_parent_chain(self, instance, name):
|
||||||
"""
|
"""
|
||||||
Check if the field value can be fetched from a parent field already
|
Check if the field value can be fetched from a parent field already
|
||||||
loaded in the instance. This can be done if the to-be fetched
|
loaded in the instance. This can be done if the to-be fetched
|
||||||
field is a primary key field.
|
field is a primary key field.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -9,6 +9,7 @@ from django.db.models.sql.datastructures import EmptyResultSet
|
||||||
from django.db.models.sql.expressions import SQLEvaluator
|
from django.db.models.sql.expressions import SQLEvaluator
|
||||||
from django.db.models.sql.query import get_order_dir, Query
|
from django.db.models.sql.query import get_order_dir, Query
|
||||||
from django.db.utils import DatabaseError
|
from django.db.utils import DatabaseError
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
class SQLCompiler(object):
|
class SQLCompiler(object):
|
||||||
|
@ -82,7 +83,7 @@ class SQLCompiler(object):
|
||||||
where, w_params = self.query.where.as_sql(qn=qn, connection=self.connection)
|
where, w_params = self.query.where.as_sql(qn=qn, connection=self.connection)
|
||||||
having, h_params = self.query.having.as_sql(qn=qn, connection=self.connection)
|
having, h_params = self.query.having.as_sql(qn=qn, connection=self.connection)
|
||||||
params = []
|
params = []
|
||||||
for val in self.query.extra_select.itervalues():
|
for val in six.itervalues(self.query.extra_select):
|
||||||
params.extend(val[1])
|
params.extend(val[1])
|
||||||
|
|
||||||
result = ['SELECT']
|
result = ['SELECT']
|
||||||
|
@ -177,7 +178,7 @@ class SQLCompiler(object):
|
||||||
"""
|
"""
|
||||||
qn = self.quote_name_unless_alias
|
qn = self.quote_name_unless_alias
|
||||||
qn2 = self.connection.ops.quote_name
|
qn2 = self.connection.ops.quote_name
|
||||||
result = ['(%s) AS %s' % (col[0], qn2(alias)) for alias, col in self.query.extra_select.iteritems()]
|
result = ['(%s) AS %s' % (col[0], qn2(alias)) for alias, col in six.iteritems(self.query.extra_select)]
|
||||||
aliases = set(self.query.extra_select.keys())
|
aliases = set(self.query.extra_select.keys())
|
||||||
if with_aliases:
|
if with_aliases:
|
||||||
col_aliases = aliases.copy()
|
col_aliases = aliases.copy()
|
||||||
|
@ -553,7 +554,7 @@ class SQLCompiler(object):
|
||||||
group_by = self.query.group_by or []
|
group_by = self.query.group_by or []
|
||||||
|
|
||||||
extra_selects = []
|
extra_selects = []
|
||||||
for extra_select, extra_params in self.query.extra_select.itervalues():
|
for extra_select, extra_params in six.itervalues(self.query.extra_select):
|
||||||
extra_selects.append(extra_select)
|
extra_selects.append(extra_select)
|
||||||
params.extend(extra_params)
|
params.extend(extra_params)
|
||||||
cols = (group_by + self.query.select +
|
cols = (group_by + self.query.select +
|
||||||
|
|
|
@ -12,6 +12,7 @@ import copy
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_unicode
|
||||||
from django.utils.tree import Node
|
from django.utils.tree import Node
|
||||||
|
from django.utils import six
|
||||||
from django.db import connections, DEFAULT_DB_ALIAS
|
from django.db import connections, DEFAULT_DB_ALIAS
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
from django.db.models.expressions import ExpressionNode
|
from django.db.models.expressions import ExpressionNode
|
||||||
|
@ -602,22 +603,22 @@ class Query(object):
|
||||||
# slight complexity here is handling fields that exist on parent
|
# slight complexity here is handling fields that exist on parent
|
||||||
# models.
|
# models.
|
||||||
workset = {}
|
workset = {}
|
||||||
for model, values in seen.iteritems():
|
for model, values in six.iteritems(seen):
|
||||||
for field, m in model._meta.get_fields_with_model():
|
for field, m in model._meta.get_fields_with_model():
|
||||||
if field in values:
|
if field in values:
|
||||||
continue
|
continue
|
||||||
add_to_dict(workset, m or model, field)
|
add_to_dict(workset, m or model, field)
|
||||||
for model, values in must_include.iteritems():
|
for model, values in six.iteritems(must_include):
|
||||||
# If we haven't included a model in workset, we don't add the
|
# If we haven't included a model in workset, we don't add the
|
||||||
# corresponding must_include fields for that model, since an
|
# corresponding must_include fields for that model, since an
|
||||||
# empty set means "include all fields". That's why there's no
|
# empty set means "include all fields". That's why there's no
|
||||||
# "else" branch here.
|
# "else" branch here.
|
||||||
if model in workset:
|
if model in workset:
|
||||||
workset[model].update(values)
|
workset[model].update(values)
|
||||||
for model, values in workset.iteritems():
|
for model, values in six.iteritems(workset):
|
||||||
callback(target, model, values)
|
callback(target, model, values)
|
||||||
else:
|
else:
|
||||||
for model, values in must_include.iteritems():
|
for model, values in six.iteritems(must_include):
|
||||||
if model in seen:
|
if model in seen:
|
||||||
seen[model].update(values)
|
seen[model].update(values)
|
||||||
else:
|
else:
|
||||||
|
@ -631,7 +632,7 @@ class Query(object):
|
||||||
for model in orig_opts.get_parent_list():
|
for model in orig_opts.get_parent_list():
|
||||||
if model not in seen:
|
if model not in seen:
|
||||||
seen[model] = set()
|
seen[model] = set()
|
||||||
for model, values in seen.iteritems():
|
for model, values in six.iteritems(seen):
|
||||||
callback(target, model, values)
|
callback(target, model, values)
|
||||||
|
|
||||||
|
|
||||||
|
@ -770,7 +771,7 @@ class Query(object):
|
||||||
for k, aliases in self.join_map.items():
|
for k, aliases in self.join_map.items():
|
||||||
aliases = tuple([change_map.get(a, a) for a in aliases])
|
aliases = tuple([change_map.get(a, a) for a in aliases])
|
||||||
self.join_map[k] = aliases
|
self.join_map[k] = aliases
|
||||||
for old_alias, new_alias in change_map.iteritems():
|
for old_alias, new_alias in six.iteritems(change_map):
|
||||||
alias_data = self.alias_map[old_alias]
|
alias_data = self.alias_map[old_alias]
|
||||||
alias_data = alias_data._replace(rhs_alias=new_alias)
|
alias_data = alias_data._replace(rhs_alias=new_alias)
|
||||||
self.alias_refcount[new_alias] = self.alias_refcount[old_alias]
|
self.alias_refcount[new_alias] = self.alias_refcount[old_alias]
|
||||||
|
@ -792,7 +793,7 @@ class Query(object):
|
||||||
self.included_inherited_models[key] = change_map[alias]
|
self.included_inherited_models[key] = change_map[alias]
|
||||||
|
|
||||||
# 3. Update any joins that refer to the old alias.
|
# 3. Update any joins that refer to the old alias.
|
||||||
for alias, data in self.alias_map.iteritems():
|
for alias, data in six.iteritems(self.alias_map):
|
||||||
lhs = data.lhs_alias
|
lhs = data.lhs_alias
|
||||||
if lhs in change_map:
|
if lhs in change_map:
|
||||||
data = data._replace(lhs_alias=change_map[lhs])
|
data = data._replace(lhs_alias=change_map[lhs])
|
||||||
|
@ -842,7 +843,7 @@ class Query(object):
|
||||||
count. Note that after execution, the reference counts are zeroed, so
|
count. Note that after execution, the reference counts are zeroed, so
|
||||||
tables added in compiler will not be seen by this method.
|
tables added in compiler will not be seen by this method.
|
||||||
"""
|
"""
|
||||||
return len([1 for count in self.alias_refcount.itervalues() if count])
|
return len([1 for count in six.itervalues(self.alias_refcount) if count])
|
||||||
|
|
||||||
def join(self, connection, always_create=False, exclusions=(),
|
def join(self, connection, always_create=False, exclusions=(),
|
||||||
promote=False, outer_if_first=False, nullable=False, reuse=None):
|
promote=False, outer_if_first=False, nullable=False, reuse=None):
|
||||||
|
@ -1302,7 +1303,7 @@ class Query(object):
|
||||||
field, model, direct, m2m = opts.get_field_by_name(f.name)
|
field, model, direct, m2m = opts.get_field_by_name(f.name)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
names = opts.get_all_field_names() + self.aggregate_select.keys()
|
names = opts.get_all_field_names() + list(six.iterkeys(self.aggregate_select))
|
||||||
raise FieldError("Cannot resolve keyword %r into field. "
|
raise FieldError("Cannot resolve keyword %r into field. "
|
||||||
"Choices are: %s" % (name, ", ".join(names)))
|
"Choices are: %s" % (name, ", ".join(names)))
|
||||||
|
|
||||||
|
@ -1571,7 +1572,7 @@ class Query(object):
|
||||||
# Tag.objects.exclude(parent__parent__name='t1'), a tag with no parent
|
# Tag.objects.exclude(parent__parent__name='t1'), a tag with no parent
|
||||||
# would otherwise be overlooked).
|
# would otherwise be overlooked).
|
||||||
active_positions = [pos for (pos, count) in
|
active_positions = [pos for (pos, count) in
|
||||||
enumerate(query.alias_refcount.itervalues()) if count]
|
enumerate(six.itervalues(query.alias_refcount)) if count]
|
||||||
if active_positions[-1] > 1:
|
if active_positions[-1] > 1:
|
||||||
self.add_filter(('%s__isnull' % prefix, False), negate=True,
|
self.add_filter(('%s__isnull' % prefix, False), negate=True,
|
||||||
trim=True, can_reuse=can_reuse)
|
trim=True, can_reuse=can_reuse)
|
||||||
|
@ -1660,8 +1661,8 @@ class Query(object):
|
||||||
# from the model on which the lookup failed.
|
# from the model on which the lookup failed.
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
names = sorted(opts.get_all_field_names() + self.extra.keys()
|
names = sorted(opts.get_all_field_names() + list(six.iterkeys(self.extra))
|
||||||
+ self.aggregate_select.keys())
|
+ list(six.iterkeys(self.aggregate_select)))
|
||||||
raise FieldError("Cannot resolve keyword %r into field. "
|
raise FieldError("Cannot resolve keyword %r into field. "
|
||||||
"Choices are: %s" % (name, ", ".join(names)))
|
"Choices are: %s" % (name, ", ".join(names)))
|
||||||
self.remove_inherited_models()
|
self.remove_inherited_models()
|
||||||
|
|
|
@ -11,6 +11,7 @@ from django.db.models.sql.where import AND, Constraint
|
||||||
from django.utils.datastructures import SortedDict
|
from django.utils.datastructures import SortedDict
|
||||||
from django.utils.functional import Promise
|
from django.utils.functional import Promise
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_unicode
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['DeleteQuery', 'UpdateQuery', 'InsertQuery', 'DateQuery',
|
__all__ = ['DeleteQuery', 'UpdateQuery', 'InsertQuery', 'DateQuery',
|
||||||
|
@ -87,7 +88,7 @@ class UpdateQuery(Query):
|
||||||
querysets.
|
querysets.
|
||||||
"""
|
"""
|
||||||
values_seq = []
|
values_seq = []
|
||||||
for name, val in values.iteritems():
|
for name, val in six.iteritems(values):
|
||||||
field, model, direct, m2m = self.model._meta.get_field_by_name(name)
|
field, model, direct, m2m = self.model._meta.get_field_by_name(name)
|
||||||
if not direct or m2m:
|
if not direct or m2m:
|
||||||
raise FieldError('Cannot update model field %r (only non-relations and foreign keys permitted).' % field)
|
raise FieldError('Cannot update model field %r (only non-relations and foreign keys permitted).' % field)
|
||||||
|
@ -129,7 +130,7 @@ class UpdateQuery(Query):
|
||||||
if not self.related_updates:
|
if not self.related_updates:
|
||||||
return []
|
return []
|
||||||
result = []
|
result = []
|
||||||
for model, values in self.related_updates.iteritems():
|
for model, values in six.iteritems(self.related_updates):
|
||||||
query = UpdateQuery(model)
|
query = UpdateQuery(model)
|
||||||
query.values = values
|
query.values = values
|
||||||
if self.related_ids is not None:
|
if self.related_ids is not None:
|
||||||
|
|
|
@ -79,7 +79,7 @@ class SelectDateWidget(Widget):
|
||||||
year_val, month_val, day_val = [int(v) for v in match.groups()]
|
year_val, month_val, day_val = [int(v) for v in match.groups()]
|
||||||
choices = [(i, i) for i in self.years]
|
choices = [(i, i) for i in self.years]
|
||||||
year_html = self.create_select(name, self.year_field, value, year_val, choices)
|
year_html = self.create_select(name, self.year_field, value, year_val, choices)
|
||||||
choices = MONTHS.items()
|
choices = list(six.iteritems(MONTHS))
|
||||||
month_html = self.create_select(name, self.month_field, value, month_val, choices)
|
month_html = self.create_select(name, self.month_field, value, month_val, choices)
|
||||||
choices = [(i, i) for i in range(1, 32)]
|
choices = [(i, i) for i in range(1, 32)]
|
||||||
day_html = self.create_select(name, self.day_field, value, day_val, choices)
|
day_html = self.create_select(name, self.day_field, value, day_val, choices)
|
||||||
|
|
|
@ -38,7 +38,7 @@ def get_declared_fields(bases, attrs, with_base_fields=True):
|
||||||
used. The distinction is useful in ModelForm subclassing.
|
used. The distinction is useful in ModelForm subclassing.
|
||||||
Also integrates any additional media definitions
|
Also integrates any additional media definitions
|
||||||
"""
|
"""
|
||||||
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
|
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in list(six.iteritems(attrs)) if isinstance(obj, Field)]
|
||||||
fields.sort(key=lambda x: x[1].creation_counter)
|
fields.sort(key=lambda x: x[1].creation_counter)
|
||||||
|
|
||||||
# If this class is subclassing another Form, add that Form's fields.
|
# If this class is subclassing another Form, add that Form's fields.
|
||||||
|
@ -47,11 +47,11 @@ def get_declared_fields(bases, attrs, with_base_fields=True):
|
||||||
if with_base_fields:
|
if with_base_fields:
|
||||||
for base in bases[::-1]:
|
for base in bases[::-1]:
|
||||||
if hasattr(base, 'base_fields'):
|
if hasattr(base, 'base_fields'):
|
||||||
fields = base.base_fields.items() + fields
|
fields = list(six.iteritems(base.base_fields)) + fields
|
||||||
else:
|
else:
|
||||||
for base in bases[::-1]:
|
for base in bases[::-1]:
|
||||||
if hasattr(base, 'declared_fields'):
|
if hasattr(base, 'declared_fields'):
|
||||||
fields = base.declared_fields.items() + fields
|
fields = list(six.iteritems(base.declared_fields)) + fields
|
||||||
|
|
||||||
return SortedDict(fields)
|
return SortedDict(fields)
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ from django.utils.datastructures import SortedDict
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.text import get_text_list, capfirst
|
from django.utils.text import get_text_list, capfirst
|
||||||
from django.utils.translation import ugettext_lazy as _, ugettext
|
from django.utils.translation import ugettext_lazy as _, ugettext
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
@ -206,7 +207,7 @@ class ModelFormMetaclass(type):
|
||||||
fields = fields_for_model(opts.model, opts.fields,
|
fields = fields_for_model(opts.model, opts.fields,
|
||||||
opts.exclude, opts.widgets, formfield_callback)
|
opts.exclude, opts.widgets, formfield_callback)
|
||||||
# make sure opts.fields doesn't specify an invalid field
|
# make sure opts.fields doesn't specify an invalid field
|
||||||
none_model_fields = [k for k, v in fields.iteritems() if not v]
|
none_model_fields = [k for k, v in six.iteritems(fields) if not v]
|
||||||
missing_fields = set(none_model_fields) - \
|
missing_fields = set(none_model_fields) - \
|
||||||
set(declared_fields.keys())
|
set(declared_fields.keys())
|
||||||
if missing_fields:
|
if missing_fields:
|
||||||
|
|
|
@ -63,8 +63,7 @@ class Media(StrAndUnicode):
|
||||||
def render_css(self):
|
def render_css(self):
|
||||||
# To keep rendering order consistent, we can't just iterate over items().
|
# To keep rendering order consistent, we can't just iterate over items().
|
||||||
# We need to sort the keys, and iterate over the sorted list.
|
# We need to sort the keys, and iterate over the sorted list.
|
||||||
media = self._css.keys()
|
media = sorted(self._css.keys())
|
||||||
media.sort()
|
|
||||||
return chain(*[
|
return chain(*[
|
||||||
[format_html('<link href="{0}" type="text/css" media="{1}" rel="stylesheet" />', self.absolute_path(path), medium)
|
[format_html('<link href="{0}" type="text/css" media="{1}" rel="stylesheet" />', self.absolute_path(path), medium)
|
||||||
for path in self._css[medium]]
|
for path in self._css[medium]]
|
||||||
|
|
|
@ -961,7 +961,7 @@ def parse_bits(parser, bits, params, varargs, varkw, defaults,
|
||||||
kwarg = token_kwargs([bit], parser)
|
kwarg = token_kwargs([bit], parser)
|
||||||
if kwarg:
|
if kwarg:
|
||||||
# The kwarg was successfully extracted
|
# The kwarg was successfully extracted
|
||||||
param, value = kwarg.items()[0]
|
param, value = list(six.iteritems(kwarg))[0]
|
||||||
if param not in params and varkw is None:
|
if param not in params and varkw is None:
|
||||||
# An unexpected keyword argument was supplied
|
# An unexpected keyword argument was supplied
|
||||||
raise TemplateSyntaxError(
|
raise TemplateSyntaxError(
|
||||||
|
|
|
@ -17,6 +17,7 @@ from django.template.defaultfilters import date
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.html import format_html
|
from django.utils.html import format_html
|
||||||
|
from django.utils import six
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
register = Library()
|
register = Library()
|
||||||
|
@ -473,7 +474,7 @@ class WithNode(Node):
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
values = dict([(key, val.resolve(context)) for key, val in
|
values = dict([(key, val.resolve(context)) for key, val in
|
||||||
self.extra_context.iteritems()])
|
six.iteritems(self.extra_context)])
|
||||||
context.update(values)
|
context.update(values)
|
||||||
output = self.nodelist.render(context)
|
output = self.nodelist.render(context)
|
||||||
context.pop()
|
context.pop()
|
||||||
|
@ -1188,7 +1189,7 @@ def templatetag(parser, token):
|
||||||
if tag not in TemplateTagNode.mapping:
|
if tag not in TemplateTagNode.mapping:
|
||||||
raise TemplateSyntaxError("Invalid templatetag argument: '%s'."
|
raise TemplateSyntaxError("Invalid templatetag argument: '%s'."
|
||||||
" Must be one of: %s" %
|
" Must be one of: %s" %
|
||||||
(tag, TemplateTagNode.mapping.keys()))
|
(tag, list(six.iterkeys(TemplateTagNode.mapping))))
|
||||||
return TemplateTagNode(tag)
|
return TemplateTagNode(tag)
|
||||||
|
|
||||||
@register.tag
|
@register.tag
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.template.base import TemplateSyntaxError, Library, Node, TextNode,\
|
||||||
token_kwargs, Variable
|
token_kwargs, Variable
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ class BlockContext(object):
|
||||||
self.blocks = {}
|
self.blocks = {}
|
||||||
|
|
||||||
def add_blocks(self, blocks):
|
def add_blocks(self, blocks):
|
||||||
for name, block in blocks.iteritems():
|
for name, block in six.iteritems(blocks):
|
||||||
if name in self.blocks:
|
if name in self.blocks:
|
||||||
self.blocks[name].insert(0, block)
|
self.blocks[name].insert(0, block)
|
||||||
else:
|
else:
|
||||||
|
@ -130,7 +131,7 @@ class BaseIncludeNode(Node):
|
||||||
|
|
||||||
def render_template(self, template, context):
|
def render_template(self, template, context):
|
||||||
values = dict([(name, var.resolve(context)) for name, var
|
values = dict([(name, var.resolve(context)) for name, var
|
||||||
in self.extra_context.iteritems()])
|
in six.iteritems(self.extra_context)])
|
||||||
if self.isolated_context:
|
if self.isolated_context:
|
||||||
return template.render(context.new(values))
|
return template.render(context.new(values))
|
||||||
context.update(values)
|
context.update(values)
|
||||||
|
|
|
@ -425,7 +425,7 @@ def do_block_translate(parser, token):
|
||||||
options[option] = value
|
options[option] = value
|
||||||
|
|
||||||
if 'count' in options:
|
if 'count' in options:
|
||||||
countervar, counter = options['count'].items()[0]
|
countervar, counter = list(six.iteritems(options['count']))[0]
|
||||||
else:
|
else:
|
||||||
countervar, counter = None, None
|
countervar, counter = None, None
|
||||||
if 'context' in options:
|
if 'context' in options:
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
from django.utils import six
|
||||||
from django.utils.timezone import utc
|
from django.utils.timezone import utc
|
||||||
from django.utils.tzinfo import FixedOffset
|
from django.utils.tzinfo import FixedOffset
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ def parse_date(value):
|
||||||
"""
|
"""
|
||||||
match = date_re.match(value)
|
match = date_re.match(value)
|
||||||
if match:
|
if match:
|
||||||
kw = dict((k, int(v)) for k, v in match.groupdict().iteritems())
|
kw = dict((k, int(v)) for k, v in six.iteritems(match.groupdict()))
|
||||||
return datetime.date(**kw)
|
return datetime.date(**kw)
|
||||||
|
|
||||||
def parse_time(value):
|
def parse_time(value):
|
||||||
|
@ -53,7 +54,7 @@ def parse_time(value):
|
||||||
kw = match.groupdict()
|
kw = match.groupdict()
|
||||||
if kw['microsecond']:
|
if kw['microsecond']:
|
||||||
kw['microsecond'] = kw['microsecond'].ljust(6, '0')
|
kw['microsecond'] = kw['microsecond'].ljust(6, '0')
|
||||||
kw = dict((k, int(v)) for k, v in kw.iteritems() if v is not None)
|
kw = dict((k, int(v)) for k, v in six.iteritems(kw) if v is not None)
|
||||||
return datetime.time(**kw)
|
return datetime.time(**kw)
|
||||||
|
|
||||||
def parse_datetime(value):
|
def parse_datetime(value):
|
||||||
|
@ -80,6 +81,6 @@ def parse_datetime(value):
|
||||||
if tzinfo[0] == '-':
|
if tzinfo[0] == '-':
|
||||||
offset = -offset
|
offset = -offset
|
||||||
tzinfo = FixedOffset(offset)
|
tzinfo = FixedOffset(offset)
|
||||||
kw = dict((k, int(v)) for k, v in kw.iteritems() if v is not None)
|
kw = dict((k, int(v)) for k, v in six.iteritems(kw) if v is not None)
|
||||||
kw['tzinfo'] = tzinfo
|
kw['tzinfo'] = tzinfo
|
||||||
return datetime.datetime(**kw)
|
return datetime.datetime(**kw)
|
||||||
|
|
|
@ -363,7 +363,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
#which were in the previous configuration but
|
#which were in the previous configuration but
|
||||||
#which are not in the new configuration.
|
#which are not in the new configuration.
|
||||||
root = logging.root
|
root = logging.root
|
||||||
existing = root.manager.loggerDict.keys()
|
existing = list(six.iterkeys(root.manager.loggerDict))
|
||||||
#The list needs to be sorted so that we can
|
#The list needs to be sorted so that we can
|
||||||
#avoid disabling child loggers of explicitly
|
#avoid disabling child loggers of explicitly
|
||||||
#named loggers. With a sorted list it is easier
|
#named loggers. With a sorted list it is easier
|
||||||
|
|
|
@ -178,7 +178,7 @@ def allow_lazy(func, *resultclasses):
|
||||||
"""
|
"""
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
for arg in list(args) + kwargs.values():
|
for arg in list(args) + list(six.itervalues(kwargs)):
|
||||||
if isinstance(arg, Promise):
|
if isinstance(arg, Promise):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -84,7 +84,7 @@ def format_html(format_string, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
args_safe = map(conditional_escape, args)
|
args_safe = map(conditional_escape, args)
|
||||||
kwargs_safe = dict([(k, conditional_escape(v)) for (k, v) in
|
kwargs_safe = dict([(k, conditional_escape(v)) for (k, v) in
|
||||||
kwargs.iteritems()])
|
six.iteritems(kwargs)])
|
||||||
return mark_safe(format_string.format(*args_safe, **kwargs_safe))
|
return mark_safe(format_string.format(*args_safe, **kwargs_safe))
|
||||||
|
|
||||||
def format_html_join(sep, format_string, args_generator):
|
def format_html_join(sep, format_string, args_generator):
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
termcolors.py
|
termcolors.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white')
|
color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white')
|
||||||
foreground = dict([(color_names[x], '3%s' % x) for x in range(8)])
|
foreground = dict([(color_names[x], '3%s' % x) for x in range(8)])
|
||||||
background = dict([(color_names[x], '4%s' % x) for x in range(8)])
|
background = dict([(color_names[x], '4%s' % x) for x in range(8)])
|
||||||
|
@ -41,7 +43,7 @@ def colorize(text='', opts=(), **kwargs):
|
||||||
code_list = []
|
code_list = []
|
||||||
if text == '' and len(opts) == 1 and opts[0] == 'reset':
|
if text == '' and len(opts) == 1 and opts[0] == 'reset':
|
||||||
return '\x1b[%sm' % RESET
|
return '\x1b[%sm' % RESET
|
||||||
for k, v in kwargs.iteritems():
|
for k, v in six.iteritems(kwargs):
|
||||||
if k == 'fg':
|
if k == 'fg':
|
||||||
code_list.append(foreground[v])
|
code_list.append(foreground[v])
|
||||||
elif k == 'bg':
|
elif k == 'bg':
|
||||||
|
|
|
@ -111,7 +111,7 @@ class ExceptionReporterFilter(object):
|
||||||
return request.POST
|
return request.POST
|
||||||
|
|
||||||
def get_traceback_frame_variables(self, request, tb_frame):
|
def get_traceback_frame_variables(self, request, tb_frame):
|
||||||
return tb_frame.f_locals.items()
|
return list(six.iteritems(tb_frame.f_locals))
|
||||||
|
|
||||||
class SafeExceptionReporterFilter(ExceptionReporterFilter):
|
class SafeExceptionReporterFilter(ExceptionReporterFilter):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.log import getLogger
|
from django.utils.log import getLogger
|
||||||
from django.utils.decorators import classonlymethod
|
from django.utils.decorators import classonlymethod
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
logger = getLogger('django.request')
|
logger = getLogger('django.request')
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ class View(object):
|
||||||
"""
|
"""
|
||||||
# Go through keyword arguments, and either save their values to our
|
# Go through keyword arguments, and either save their values to our
|
||||||
# instance, or raise an error.
|
# instance, or raise an error.
|
||||||
for key, value in kwargs.iteritems():
|
for key, value in six.iteritems(kwargs):
|
||||||
setattr(self, key, value)
|
setattr(self, key, value)
|
||||||
|
|
||||||
@classonlymethod
|
@classonlymethod
|
||||||
|
|
|
@ -20,6 +20,7 @@ from django.http import HttpRequest
|
||||||
from django.template import Context, RequestContext, Template, TemplateSyntaxError
|
from django.template import Context, RequestContext, Template, TemplateSyntaxError
|
||||||
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
|
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
|
from django.utils import six
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.tzinfo import FixedOffset
|
from django.utils.tzinfo import FixedOffset
|
||||||
from django.utils.unittest import skipIf, skipUnless
|
from django.utils.unittest import skipIf, skipUnless
|
||||||
|
@ -690,8 +691,8 @@ class TemplateTests(TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for k1, dt in datetimes.iteritems():
|
for k1, dt in six.iteritems(datetimes):
|
||||||
for k2, tpl in templates.iteritems():
|
for k2, tpl in six.iteritems(templates):
|
||||||
ctx = Context({'dt': dt, 'ICT': ICT})
|
ctx = Context({'dt': dt, 'ICT': ICT})
|
||||||
actual = tpl.render(ctx)
|
actual = tpl.render(ctx)
|
||||||
expected = results[k1][k2]
|
expected = results[k1][k2]
|
||||||
|
@ -703,8 +704,8 @@ class TemplateTests(TestCase):
|
||||||
results['ict']['notag'] = t('ict', 'eat', 'utc', 'ict')
|
results['ict']['notag'] = t('ict', 'eat', 'utc', 'ict')
|
||||||
|
|
||||||
with self.settings(USE_TZ=False):
|
with self.settings(USE_TZ=False):
|
||||||
for k1, dt in datetimes.iteritems():
|
for k1, dt in six.iteritems(datetimes):
|
||||||
for k2, tpl in templates.iteritems():
|
for k2, tpl in six.iteritems(templates):
|
||||||
ctx = Context({'dt': dt, 'ICT': ICT})
|
ctx = Context({'dt': dt, 'ICT': ICT})
|
||||||
actual = tpl.render(ctx)
|
actual = tpl.render(ctx)
|
||||||
expected = results[k1][k2]
|
expected = results[k1][k2]
|
||||||
|
|
|
@ -8,6 +8,7 @@ from operator import attrgetter
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F, Q
|
from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F, Q
|
||||||
from django.test import TestCase, Approximate, skipUnlessDBFeature
|
from django.test import TestCase, Approximate, skipUnlessDBFeature
|
||||||
|
from django.utils import six
|
||||||
|
|
||||||
from .models import Author, Book, Publisher, Clues, Entries, HardbackBook
|
from .models import Author, Book, Publisher, Clues, Entries, HardbackBook
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ class AggregationTests(TestCase):
|
||||||
fixtures = ["aggregation_regress.json"]
|
fixtures = ["aggregation_regress.json"]
|
||||||
|
|
||||||
def assertObjectAttrs(self, obj, **kwargs):
|
def assertObjectAttrs(self, obj, **kwargs):
|
||||||
for attr, value in kwargs.iteritems():
|
for attr, value in six.iteritems(kwargs):
|
||||||
self.assertEqual(getattr(obj, attr), value)
|
self.assertEqual(getattr(obj, attr), value)
|
||||||
|
|
||||||
def test_aggregates_in_where_clause(self):
|
def test_aggregates_in_where_clause(self):
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.db.backends import util as typecasts
|
from django.db.backends import util as typecasts
|
||||||
|
from django.utils import six
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ TEST_CASES = {
|
||||||
|
|
||||||
class DBTypeCasts(unittest.TestCase):
|
class DBTypeCasts(unittest.TestCase):
|
||||||
def test_typeCasts(self):
|
def test_typeCasts(self):
|
||||||
for k, v in TEST_CASES.iteritems():
|
for k, v in six.iteritems(TEST_CASES):
|
||||||
for inpt, expected in v:
|
for inpt, expected in v:
|
||||||
got = getattr(typecasts, k)(inpt)
|
got = getattr(typecasts, k)(inpt)
|
||||||
self.assertEqual(got, expected, "In %s: %r doesn't match %r. Got %r instead." % (k, inpt, expected, got))
|
self.assertEqual(got, expected, "In %s: %r doesn't match %r. Got %r instead." % (k, inpt, expected, got))
|
||||||
|
|
|
@ -70,7 +70,7 @@ simple_only_unlimited_args.anything = "Expected simple_only_unlimited_args __dic
|
||||||
def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
||||||
"""Expected simple_unlimited_args_kwargs __doc__"""
|
"""Expected simple_unlimited_args_kwargs __doc__"""
|
||||||
# Sort the dictionary by key to guarantee the order for testing.
|
# Sort the dictionary by key to guarantee the order for testing.
|
||||||
sorted_kwarg = sorted(kwargs.iteritems(), key=operator.itemgetter(0))
|
sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0))
|
||||||
return "simple_unlimited_args_kwargs - Expected result: %s / %s" % (
|
return "simple_unlimited_args_kwargs - Expected result: %s / %s" % (
|
||||||
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
||||||
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
||||||
|
@ -221,7 +221,7 @@ inclusion_tag_use_l10n.anything = "Expected inclusion_tag_use_l10n __dict__"
|
||||||
def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
||||||
"""Expected inclusion_unlimited_args_kwargs __doc__"""
|
"""Expected inclusion_unlimited_args_kwargs __doc__"""
|
||||||
# Sort the dictionary by key to guarantee the order for testing.
|
# Sort the dictionary by key to guarantee the order for testing.
|
||||||
sorted_kwarg = sorted(kwargs.iteritems(), key=operator.itemgetter(0))
|
sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0))
|
||||||
return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % (
|
return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % (
|
||||||
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
||||||
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
||||||
|
@ -292,7 +292,7 @@ assignment_only_unlimited_args.anything = "Expected assignment_only_unlimited_ar
|
||||||
def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
||||||
"""Expected assignment_unlimited_args_kwargs __doc__"""
|
"""Expected assignment_unlimited_args_kwargs __doc__"""
|
||||||
# Sort the dictionary by key to guarantee the order for testing.
|
# Sort the dictionary by key to guarantee the order for testing.
|
||||||
sorted_kwarg = sorted(kwargs.iteritems(), key=operator.itemgetter(0))
|
sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0))
|
||||||
return "assignment_unlimited_args_kwargs - Expected result: %s / %s" % (
|
return "assignment_unlimited_args_kwargs - Expected result: %s / %s" % (
|
||||||
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
||||||
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
||||||
|
|
|
@ -30,6 +30,7 @@ from django.utils import unittest
|
||||||
from django.utils.formats import date_format
|
from django.utils.formats import date_format
|
||||||
from django.utils.translation import activate, deactivate, ugettext as _
|
from django.utils.translation import activate, deactivate, ugettext as _
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.utils import six
|
||||||
from django.utils.tzinfo import LocalTimezone
|
from django.utils.tzinfo import LocalTimezone
|
||||||
|
|
||||||
from .callables import CallableVariablesTests
|
from .callables import CallableVariablesTests
|
||||||
|
@ -402,7 +403,7 @@ class Templates(unittest.TestCase):
|
||||||
template_tests.update(filter_tests)
|
template_tests.update(filter_tests)
|
||||||
|
|
||||||
cache_loader = setup_test_template_loader(
|
cache_loader = setup_test_template_loader(
|
||||||
dict([(name, t[0]) for name, t in template_tests.iteritems()]),
|
dict([(name, t[0]) for name, t in six.iteritems(template_tests)]),
|
||||||
use_cached_loader=True,
|
use_cached_loader=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue