From 358e5a8031be14efe33dc62e821408c2a6a8e85a Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 19 Oct 2011 00:09:41 +0000 Subject: [PATCH] Fixed #16393 -- FormWizard's cookie storage backend now works with all versions of simplejson and the standard library json module. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17014 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/formtools/wizard/storage/base.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/django/contrib/formtools/wizard/storage/base.py b/django/contrib/formtools/wizard/storage/base.py index 475b39dc75..274e07ffbe 100644 --- a/django/contrib/formtools/wizard/storage/base.py +++ b/django/contrib/formtools/wizard/storage/base.py @@ -1,9 +1,11 @@ from django.core.files.uploadedfile import UploadedFile -from django.utils.functional import lazy_property +from django.utils.datastructures import MultiValueDict from django.utils.encoding import smart_str +from django.utils.functional import lazy_property from django.contrib.formtools.wizard.storage.exceptions import NoFileStorageConfigured + class BaseStorage(object): step_key = 'step' step_data_key = 'step_data' @@ -43,9 +45,20 @@ class BaseStorage(object): extra_data = lazy_property(_get_extra_data, _set_extra_data) def get_step_data(self, step): - return self.data[self.step_data_key].get(step, None) + # When reading the serialized data, upconvert it to a MultiValueDict, + # some serializers (json) don't preserve the type of the object. + values = self.data[self.step_data_key].get(step, None) + if values is not None: + values = MultiValueDict(values) + return values def set_step_data(self, step, cleaned_data): + # If the value is a MultiValueDict, convert it to a regular dict of the + # underlying contents. Some serializers call the public API on it (as + # opposed to the underlying dict methods), in which case the content + # can be truncated (__getitem__ returns only the first item). + if isinstance(cleaned_data, MultiValueDict): + cleaned_data = dict(cleaned_data.lists()) self.data[self.step_data_key][step] = cleaned_data @property