summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2019-02-05 11:22:08 +0000
committerTim Graham <timograham@gmail.com>2019-02-06 13:48:39 -0500
commit24b82cd201e21060fbc02117dc16d1702877a1f3 (patch)
tree7d36db9251700d0abf8fbf69399c8abc7fd9026a /django/forms
parent21bb71ef0dcb86798edb0d8b21138bcc4b947590 (diff)
Fixed #30159 -- Removed unneeded use of OrderedDict.
Dicts preserve order since Python 3.6.
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/forms.py12
-rw-r--r--django/forms/models.py16
2 files changed, 10 insertions, 18 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 51e6465539..0c49a94432 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -3,7 +3,6 @@ Form classes
"""
import copy
-from collections import OrderedDict
from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
# BoundField is imported for backwards compatibility in Django 1.9
@@ -31,12 +30,12 @@ class DeclarativeFieldsMetaclass(MediaDefiningClass):
if isinstance(value, Field):
current_fields.append((key, value))
attrs.pop(key)
- attrs['declared_fields'] = OrderedDict(current_fields)
+ attrs['declared_fields'] = dict(current_fields)
new_class = super(DeclarativeFieldsMetaclass, mcs).__new__(mcs, name, bases, attrs)
# Walk through the MRO.
- declared_fields = OrderedDict()
+ declared_fields = {}
for base in reversed(new_class.__mro__):
# Collect fields from base class.
if hasattr(base, 'declared_fields'):
@@ -52,11 +51,6 @@ class DeclarativeFieldsMetaclass(MediaDefiningClass):
return new_class
- @classmethod
- def __prepare__(metacls, name, bases, **kwds):
- # Remember the order in which form fields are defined.
- return OrderedDict()
-
@html_safe
class BaseForm:
@@ -129,7 +123,7 @@ class BaseForm:
"""
if field_order is None:
return
- fields = OrderedDict()
+ fields = {}
for key in field_order:
try:
fields[key] = self.fields.pop(key)
diff --git a/django/forms/models.py b/django/forms/models.py
index fe8a67ed2b..d157c291ef 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -3,7 +3,6 @@ Helper functions for creating Form classes from Django models
and database field objects.
"""
-from collections import OrderedDict
from itertools import chain
from django.core.exceptions import (
@@ -105,7 +104,7 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None,
labels=None, help_texts=None, error_messages=None,
field_classes=None, *, apply_limit_choices_to=True):
"""
- Return an ``OrderedDict`` containing form fields for the given model.
+ Return a dictionary containing form fields for the given model.
``fields`` is an optional list of field names. If provided, return only the
named fields.
@@ -134,7 +133,7 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None,
``apply_limit_choices_to`` is a boolean indicating if limit_choices_to
should be applied to a field's queryset.
"""
- field_list = []
+ field_dict = {}
ignored = []
opts = model._meta
# Avoid circular import
@@ -178,15 +177,14 @@ def fields_for_model(model, fields=None, exclude=None, widgets=None,
if formfield:
if apply_limit_choices_to:
apply_limit_choices_to_to_formfield(formfield)
- field_list.append((f.name, formfield))
+ field_dict[f.name] = formfield
else:
ignored.append(f.name)
- field_dict = OrderedDict(field_list)
if fields:
- field_dict = OrderedDict(
- [(f, field_dict.get(f)) for f in fields
- if ((not exclude) or (exclude and f not in exclude)) and (f not in ignored)]
- )
+ field_dict = {
+ f: field_dict.get(f) for f in fields
+ if (not exclude or f not in exclude) and f not in ignored
+ }
return field_dict