Removed unneeded string normalization in contrib.admin
With Python 2.7 and up, named parameter keys are not limited to
bytestrings any longer. This mainly reverts 3bd384aa62
.
This commit is contained in:
parent
e7dcd40da2
commit
65faa84de3
|
@ -30,7 +30,7 @@ checkbox = forms.CheckboxInput({'class': 'action-select'}, lambda value: False)
|
||||||
|
|
||||||
class AdminForm(object):
|
class AdminForm(object):
|
||||||
def __init__(self, form, fieldsets, prepopulated_fields, readonly_fields=None, model_admin=None):
|
def __init__(self, form, fieldsets, prepopulated_fields, readonly_fields=None, model_admin=None):
|
||||||
self.form, self.fieldsets = form, normalize_fieldsets(fieldsets)
|
self.form, self.fieldsets = form, fieldsets
|
||||||
self.prepopulated_fields = [{
|
self.prepopulated_fields = [{
|
||||||
'field': form[field_name],
|
'field': form[field_name],
|
||||||
'dependencies': [form[f] for f in dependencies]
|
'dependencies': [form[f] for f in dependencies]
|
||||||
|
@ -334,26 +334,3 @@ class AdminErrorList(forms.utils.ErrorList):
|
||||||
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(list(six.itervalues(errors_in_inline_form)))
|
self.extend(list(six.itervalues(errors_in_inline_form)))
|
||||||
|
|
||||||
|
|
||||||
def normalize_fieldsets(fieldsets):
|
|
||||||
"""
|
|
||||||
Make sure the keys in fieldset dictionaries are strings. Returns the
|
|
||||||
normalized data.
|
|
||||||
"""
|
|
||||||
result = []
|
|
||||||
for name, options in fieldsets:
|
|
||||||
result.append((name, normalize_dictionary(options)))
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_dictionary(data_dict):
|
|
||||||
"""
|
|
||||||
Converts all the keys in "data_dict" to strings. The keys must be
|
|
||||||
convertible using str().
|
|
||||||
"""
|
|
||||||
for key, value in data_dict.items():
|
|
||||||
if not isinstance(key, str):
|
|
||||||
del data_dict[key]
|
|
||||||
data_dict[str(key)] = value
|
|
||||||
return data_dict
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django.db import models
|
||||||
from django.db.models.fields import FieldDoesNotExist
|
from django.db.models.fields import FieldDoesNotExist
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.deprecation import RenameMethodsBase
|
from django.utils.deprecation import RenameMethodsBase
|
||||||
from django.utils.encoding import force_str, force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.translation import ugettext, ugettext_lazy
|
from django.utils.translation import ugettext, ugettext_lazy
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
|
|
||||||
|
@ -142,14 +142,7 @@ class ChangeList(six.with_metaclass(RenameChangeListMethods)):
|
||||||
lookup_params = self.get_filters_params()
|
lookup_params = self.get_filters_params()
|
||||||
use_distinct = False
|
use_distinct = False
|
||||||
|
|
||||||
# Normalize the types of keys
|
|
||||||
for key, value in lookup_params.items():
|
for key, value in lookup_params.items():
|
||||||
if not isinstance(key, str):
|
|
||||||
# 'key' will be used as a keyword argument later, so Python
|
|
||||||
# requires it to be a string.
|
|
||||||
del lookup_params[key]
|
|
||||||
lookup_params[force_str(key)] = value
|
|
||||||
|
|
||||||
if not self.model_admin.lookup_allowed(key, value):
|
if not self.model_admin.lookup_allowed(key, value):
|
||||||
raise DisallowedModelAdminLookup("Filtering by %s not allowed" % key)
|
raise DisallowedModelAdminLookup("Filtering by %s not allowed" % key)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue