Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

FormWizard: file_storage exception message and docs #173

Closed
wants to merge 5 commits into from

4 participants

@dbrgn

Small pull request, easy to review and merge.

  • Provided error message for NoFileStorageConfigured
  • Improved docs regarding file_storage

New commit 03.07.12:

  • Improved docs for WizardView methods
docs/ref/contrib/formtools/form-wizard.txt
@@ -474,6 +474,15 @@ This storage will temporarily store the uploaded files for the wizard. The
:attr:`file_storage` attribute should be a
:class:`~django.core.files.storage.Storage` subclass.
+Django provides a builtin storage class (see :ref:`the built-in
+filesystem storage class <builtin-fs-storage>`)::
+
+ from django.conf import settings
+ from django.core.files.storage import FileSystemStorage
+ class CustomWizardView(WizardView):
@apollo13 Owner
apollo13 added a note

Missing empty lines here, see pep008

@dbrgn
dbrgn added a note

I missed that one, thanks. Fixed with new commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
django/contrib/formtools/wizard/storage/base.py
@@ -69,7 +69,9 @@ def get_step_files(self, step):
wizard_files = self.data[self.step_files_key].get(step, {})
if wizard_files and not self.file_storage:
- raise NoFileStorageConfigured
+ raise NoFileStorageConfigured(
+ "You need to define 'file_storage' in your " \
@jezdez Owner
jezdez added a note

No need for backslashes here, please remove them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
django/contrib/formtools/wizard/storage/base.py
@@ -82,7 +84,9 @@ def get_step_files(self, step):
def set_step_files(self, step, files):
if files and not self.file_storage:
- raise NoFileStorageConfigured
+ raise NoFileStorageConfigured(
+ "You need to define 'file_storage' in your " \
@jezdez Owner
jezdez added a note

Again, backslashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dbrgn

@jezdez thanks, done!

@dbrgn

I saw that the WizardView's get_all_cleaned_data() and get_cleaned_data_for_step(step) were still undocumented and added their docstrings to the main documentation.

Maybe get_all_cleaned_data() should even be mentioned in an example at https://docs.djangoproject.com/en/1.4/ref/contrib/formtools/form-wizard/#django.contrib.formtools.wizard.views.WizardView.done? It seems to be very useful (as long as form field names don't clash).

@dbrgn

This is a very small pull request, it would be great if someone could review and merge it :)

@timgraham
Owner

Made a few tweaks and merged this, thanks!

@timgraham timgraham closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 25, 2012
  1. Mention FileSystemStorage in formwizard docs

    Danilo Bargen authored
Commits on Jul 2, 2012
  1. Added missing empty line in docs example (PEP8)

    Danilo Bargen authored
  2. Removed unnecessary backslashes in exception messages

    Danilo Bargen authored
Commits on Jul 3, 2012
  1. Added documentation for WizardView's get_cleaned_data_for_step() and …

    Danilo Bargen authored
    …get_all_cleaned_data()
This page is out of date. Refresh to see the latest.
View
8 django/contrib/formtools/wizard/storage/base.py
@@ -69,7 +69,9 @@ def get_step_files(self, step):
wizard_files = self.data[self.step_files_key].get(step, {})
if wizard_files and not self.file_storage:
- raise NoFileStorageConfigured
+ raise NoFileStorageConfigured(
+ "You need to define 'file_storage' in your "
+ "wizard view in order to handle file uploads.")
files = {}
for field, field_dict in wizard_files.iteritems():
@@ -82,7 +84,9 @@ def get_step_files(self, step):
def set_step_files(self, step, files):
if files and not self.file_storage:
- raise NoFileStorageConfigured
+ raise NoFileStorageConfigured(
+ "You need to define 'file_storage' in your "
+ "wizard view in order to handle file uploads.")
if step not in self.data[self.step_files_key]:
self.data[self.step_files_key][step] = {}
View
4 django/contrib/formtools/wizard/views.py
@@ -173,7 +173,9 @@ def get_initkwargs(cls, form_list, initial_dict=None,
for field in form.base_fields.itervalues():
if (isinstance(field, forms.FileField) and
not hasattr(cls, 'file_storage')):
- raise NoFileStorageConfigured
+ raise NoFileStorageConfigured(
+ "You need to define 'file_storage' in your " \
+ "wizard view in order to handle file uploads.")
# build the kwargs for the wizardview instances
kwargs['form_list'] = init_form_list
View
24 docs/ref/contrib/formtools/form-wizard.txt
@@ -433,6 +433,20 @@ Advanced ``WizardView`` methods
context = self.get_context_data(form=form, **kwargs)
return self.render_to_response(context)
+.. method:: WizardView.get_cleaned_data_for_step(step)
+
+ This method returns the cleaned data for a given ``step``. Before returning
+ the cleaned data, the stored values are being revalidated through the
+ form. If the data doesn't validate, ``None`` will be returned.
+
+.. method:: WizardView.get_all_cleaned_data()
+
+ This method returns a merged dictionary of all form steps' ``cleaned_data``
+ dictionaries. If a step contains a ``FormSet``, the key will be prefixed
+ with ``formset-`` and contain a list of the formset's ``cleaned_data``
+ dictionaries.
+
+
Providing initial data for the forms
====================================
@@ -474,6 +488,16 @@ This storage will temporarily store the uploaded files for the wizard. The
:attr:`file_storage` attribute should be a
:class:`~django.core.files.storage.Storage` subclass.
+Django provides a builtin storage class (see :ref:`the built-in
+filesystem storage class <builtin-fs-storage>`)::
+
+ from django.conf import settings
+ from django.core.files.storage import FileSystemStorage
+
+ class CustomWizardView(WizardView):
+ ...
+ file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT, 'photos'))
+
.. warning::
Please remember to take care of removing old files as the
View
2  docs/topics/files.txt
@@ -139,6 +139,8 @@ useful -- you can use the global default storage system::
See :doc:`/ref/files/storage` for the file storage API.
+.. _builtin-fs-storage:
+
The built-in filesystem storage class
-------------------------------------
Something went wrong with that request. Please try again.