Skip to content

Commit

Permalink
Removed unneeded string normalization in contrib.admin
Browse files Browse the repository at this point in the history
With Python 2.7 and up, named parameter keys are not limited to
bytestrings any longer. This mainly reverts 3bd384a.
  • Loading branch information
claudep committed Dec 7, 2013
1 parent e7dcd40 commit 65faa84
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
25 changes: 1 addition & 24 deletions django/contrib/admin/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ActionForm(forms.Form):

class AdminForm(object):
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 = [{
'field': form[field_name],
'dependencies': [form[f] for f in dependencies]
Expand Down Expand Up @@ -334,26 +334,3 @@ def __init__(self, form, inline_formsets):
self.extend(inline_formset.non_form_errors())
for errors_in_inline_form in inline_formset.errors:
self.extend(list(six.itervalues(errors_in_inline_form)))


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 changes: 1 addition & 8 deletions django/contrib/admin/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.db.models.fields import FieldDoesNotExist
from django.utils import six
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.http import urlencode

Expand Down Expand Up @@ -142,14 +142,7 @@ def get_filters(self, request):
lookup_params = self.get_filters_params()
use_distinct = False

# Normalize the types of keys
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):
raise DisallowedModelAdminLookup("Filtering by %s not allowed" % key)

Expand Down

0 comments on commit 65faa84

Please sign in to comment.