From a18feffa5097f3309ae1a546eecede5cf12e619b Mon Sep 17 00:00:00 2001 From: Andrew Somerville Date: Thu, 15 Oct 2015 13:46:07 -0400 Subject: [PATCH] Cherry pick the 1.9 upgrades --- django_remote_forms/fields.py | 4 ++-- django_remote_forms/forms.py | 10 +++++++--- django_remote_forms/widgets.py | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index bdddf91..775e033 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -1,7 +1,7 @@ import datetime from django.conf import settings -from django.utils.datastructures import SortedDict +from collections import OrderedDict from django_remote_forms import logger, widgets @@ -24,7 +24,7 @@ def __init__(self, field, form_initial_data=None, field_name=None): self.form_initial_data = form_initial_data def as_dict(self): - field_dict = SortedDict() + field_dict = OrderedDict() field_dict['title'] = self.field.__class__.__name__ field_dict['required'] = self.field.required field_dict['label'] = self.field.label diff --git a/django_remote_forms/forms.py b/django_remote_forms/forms.py index 57abeb9..794837f 100644 --- a/django_remote_forms/forms.py +++ b/django_remote_forms/forms.py @@ -1,4 +1,5 @@ -from django.utils.datastructures import SortedDict +from collections import OrderedDict +from django import forms from django_remote_forms import fields, logger from django_remote_forms.utils import resolve_promise @@ -99,13 +100,16 @@ def as_dict(self): } } """ - form_dict = SortedDict() + form_dict = OrderedDict() + if isinstance(self.form, forms.formsets.BaseFormSet): + form_dict = self.get_formset_dict(self.form) + return form_dict form_dict['title'] = self.form.__class__.__name__ form_dict['non_field_errors'] = self.form.non_field_errors() form_dict['label_suffix'] = self.form.label_suffix form_dict['is_bound'] = self.form.is_bound form_dict['prefix'] = self.form.prefix - form_dict['fields'] = SortedDict() + form_dict['fields'] = OrderedDict() form_dict['errors'] = self.form.errors form_dict['fieldsets'] = getattr(self.form, 'fieldsets', []) diff --git a/django_remote_forms/widgets.py b/django_remote_forms/widgets.py index d8aa7b0..3ca30e6 100644 --- a/django_remote_forms/widgets.py +++ b/django_remote_forms/widgets.py @@ -1,7 +1,7 @@ import datetime from django.utils.dates import MONTHS -from django.utils.datastructures import SortedDict +from collections import OrderedDict class RemoteWidget(object): @@ -10,7 +10,7 @@ def __init__(self, widget, field_name=None): self.widget = widget def as_dict(self): - widget_dict = SortedDict() + widget_dict = OrderedDict() widget_dict['title'] = self.widget.__class__.__name__ widget_dict['is_hidden'] = self.widget.is_hidden widget_dict['needs_multipart_form'] = self.widget.needs_multipart_form @@ -197,7 +197,7 @@ def as_dict(self): class RemoteRadioInput(RemoteWidget): def as_dict(self): - widget_dict = SortedDict() + widget_dict = OrderedDict() widget_dict['title'] = self.widget.__class__.__name__ widget_dict['name'] = self.widget.name widget_dict['value'] = self.widget.value @@ -212,7 +212,7 @@ def as_dict(self): class RemoteRadioFieldRenderer(RemoteWidget): def as_dict(self): - widget_dict = SortedDict() + widget_dict = OrderedDict() widget_dict['title'] = self.widget.__class__.__name__ widget_dict['name'] = self.widget.name widget_dict['value'] = self.widget.value