Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added WizardView.file_storage exception message and docs

Thanks Danilo Bargen for the patch.
  • Loading branch information...
commit af7ea808d8540d1be87d89172f371ac928ff5c19 1 parent d9213d0
Tim Graham authored November 01, 2012
8  django/contrib/formtools/wizard/storage/base.py
@@ -69,7 +69,9 @@ def get_step_files(self, step):
69 69
         wizard_files = self.data[self.step_files_key].get(step, {})
70 70
 
71 71
         if wizard_files and not self.file_storage:
72  
-            raise NoFileStorageConfigured
  72
+            raise NoFileStorageConfigured(
  73
+                    "You need to define 'file_storage' in your "
  74
+                    "wizard view in order to handle file uploads.")
73 75
 
74 76
         files = {}
75 77
         for field, field_dict in six.iteritems(wizard_files):
@@ -81,7 +83,9 @@ def get_step_files(self, step):
81 83
 
82 84
     def set_step_files(self, step, files):
83 85
         if files and not self.file_storage:
84  
-            raise NoFileStorageConfigured
  86
+            raise NoFileStorageConfigured(
  87
+                    "You need to define 'file_storage' in your "
  88
+                    "wizard view in order to handle file uploads.")
85 89
 
86 90
         if step not in self.data[self.step_files_key]:
87 91
             self.data[self.step_files_key][step] = {}
12  django/contrib/formtools/wizard/views.py
@@ -174,7 +174,9 @@ def get_initkwargs(cls, form_list, initial_dict=None,
174 174
             for field in six.itervalues(form.base_fields):
175 175
                 if (isinstance(field, forms.FileField) and
176 176
                         not hasattr(cls, 'file_storage')):
177  
-                    raise NoFileStorageConfigured
  177
+                    raise NoFileStorageConfigured(
  178
+                            "You need to define 'file_storage' in your "
  179
+                            "wizard view in order to handle file uploads.")
178 180
 
179 181
         # build the kwargs for the wizardview instances
180 182
         kwargs['form_list'] = init_form_list
@@ -436,8 +438,8 @@ def get_form_step_files(self, form):
436 438
     def get_all_cleaned_data(self):
437 439
         """
438 440
         Returns a merged dictionary of all step cleaned_data dictionaries.
439  
-        If a step contains a `FormSet`, the key will be prefixed with formset
440  
-        and contain a list of the formset cleaned_data dictionaries.
  441
+        If a step contains a `FormSet`, the key will be prefixed with
  442
+        'formset-' and contain a list of the formset cleaned_data dictionaries.
441 443
         """
442 444
         cleaned_data = {}
443 445
         for form_key in self.get_form_list():
@@ -458,8 +460,8 @@ def get_all_cleaned_data(self):
458 460
     def get_cleaned_data_for_step(self, step):
459 461
         """
460 462
         Returns the cleaned data for a given `step`. Before returning the
461  
-        cleaned data, the stored values are being revalidated through the
462  
-        form. If the data doesn't validate, None will be returned.
  463
+        cleaned data, the stored values are revalidated through the form.
  464
+        If the data doesn't validate, None will be returned.
463 465
         """
464 466
         if step in self.form_list:
465 467
             form_obj = self.get_form(step=step,
25  docs/ref/contrib/formtools/form-wizard.txt
@@ -493,6 +493,21 @@ Advanced ``WizardView`` methods
493 493
             context = self.get_context_data(form=form, **kwargs)
494 494
             return self.render_to_response(context)
495 495
 
  496
+.. method:: WizardView.get_cleaned_data_for_step(step)
  497
+
  498
+    This method returns the cleaned data for a given ``step``. Before returning
  499
+    the cleaned data, the stored values are revalidated through the form. If
  500
+    the data doesn't validate, ``None`` will be returned.
  501
+
  502
+.. method:: WizardView.get_all_cleaned_data()
  503
+
  504
+    This method returns a merged dictionary of all form steps' ``cleaned_data``
  505
+    dictionaries. If a step contains a ``FormSet``, the key will be prefixed
  506
+    with ``formset-`` and contain a list of the formset's ``cleaned_data``
  507
+    dictionaries. Note that if two or more steps have a field with the same
  508
+    name, the value for that field from the latest step will overwrite the
  509
+    value from any earlier steps.
  510
+
496 511
 Providing initial data for the forms
497 512
 ====================================
498 513
 
@@ -534,6 +549,16 @@ This storage will temporarily store the uploaded files for the wizard. The
534 549
 :attr:`file_storage` attribute should be a
535 550
 :class:`~django.core.files.storage.Storage` subclass.
536 551
 
  552
+Django provides a built-in storage class (see :ref:`the built-in filesystem
  553
+storage class <builtin-fs-storage>`)::
  554
+
  555
+    from django.conf import settings
  556
+    from django.core.files.storage import FileSystemStorage
  557
+
  558
+    class CustomWizardView(WizardView):
  559
+        ...
  560
+        file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'photos'))
  561
+
537 562
 .. warning::
538 563
 
539 564
     Please remember to take care of removing old files as the
2  docs/topics/files.txt
@@ -139,6 +139,8 @@ useful -- you can use the global default storage system::
139 139
 
140 140
 See :doc:`/ref/files/storage` for the file storage API.
141 141
 
  142
+.. _builtin-fs-storage:
  143
+
142 144
 The built-in filesystem storage class
143 145
 -------------------------------------
144 146
 

0 notes on commit af7ea80

Please sign in to comment.
Something went wrong with that request. Please try again.