fobi.wizard.views package

Submodules

fobi.wizard.views.dynamic module

class fobi.wizard.views.dynamic.DynamicWizardView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

The WizardView is used to create multi-page forms.

Handles all the storage and validation stuff. The wizard is based on Django’s generic class based views.

classmethod as_view(*args, **kwargs)[source]

As view.

This method is used within urls.py to create unique wizardview instances for every request. We need to override this method because we add some kwargs which are needed to make the wizardview usable.

compute_form_list(form_list=None, *args, **kwargs)[source]

Compute the forms list.

condition_dict = None
dispatch(request, *args, **kwargs)[source]

Dispatch.

This method gets called by the routing engine. The first argument is request which contains a HttpRequest instance. The request is stored in self.request for later use. The storage instance is stored in self.storage.

After processing the request using the dispatch method, the response gets updated by the storage engine (for example add cookies).

done(form_list, **kwargs)[source]

Done.

This method must be overridden by a subclass to process to form data after processing all steps.

get(request, *args, **kwargs)[source]

GET requests.

This method handles GET requests.

If a GET request reaches this point, the wizard assumes that the user just starts at the first step or wants to restart the process. The data of the wizard will be resetted before rendering the first step

get_all_cleaned_data()[source]

Get all cleaned data.

Returns a merged dictionary of all step cleaned_data dictionaries. If a step contains a FormSet, the key will be prefixed with ‘formset-‘ and contain a list of the formset cleaned_data dictionaries.

get_cleaned_data_for_step(step)[source]

Get clean data for step.

Returns the cleaned data for a given step. Before returning the cleaned data, the stored values are revalidated through the form. If the data doesn’t validate, None will be returned.

get_context_data(form, **kwargs)[source]

Get context data.

Returns the template context for a step. You can overwrite this method to add more data for all or some steps. This method returns a dictionary containing the rendered form step. Available template context variables are:

  • all extra data stored in the storage backend
  • wizard - a dictionary representation of the wizard instance

Example:

class MyWizard(WizardView):
    def get_context_data(self, form, **kwargs):
        context = super(MyWizard, self).get_context_data(form=form,
                                                         **kwargs)
        if self.steps.current == 'my_step_name':
            context.update({'another_var': True})
        return context
get_form(step=None, data=None, files=None)[source]

Get the form.

Constructs the form for a given step. If no step is defined, the current step will be determined automatically.

The form will be initialized using the data argument to prefill the new form. If needed, instance or queryset (for ModelForm or ModelFormSet) will be added too.

get_form_initial(step)[source]

Get form initial

Returns a dictionary which will be passed to the form for step as initial. If no initial data was provided while initializing the form wizard, an empty dictionary will be returned.

get_form_instance(step)[source]

Get form instance.

Returns an object which will be passed to the form for step as instance. If no instance object was provided while initializing the form wizard, None will be returned.

get_form_kwargs(step=None)[source]

Get form kwargs.

Returns the keyword arguments for instantiating the form (or formset) on the given step.

get_form_list()[source]

Get form list.

This method returns a form_list based on the initial form list but checks if there is a condition method/value in the condition_list. If an entry exists in the condition list, it will call/read the value and respect the result. (True means add the form, False means ignore the form)

The form_list is always generated on the fly because condition methods could use data from other (maybe previous forms).

get_form_prefix(step=None, form=None)[source]

Get form prefix.

Returns the prefix which will be used when calling the actual form for the given step. step contains the step-name, form the form which will be called with the returned prefix.

If no step is given, the form_prefix will determine the current step automatically.

get_form_step_data(form)[source]

Get form step data.

Is used to return the raw form data. You may use this method to manipulate the data.

get_form_step_files(form)[source]

Get form step files.

Is used to return the raw form files. You may use this method to manipulate the data.

get_initial_wizard_data(*args, **kwargs)[source]

This should be implemented in your subclass.

You are supposed to return a dict with the dynamic properties, such as form_list or template_name.

classmethod get_initkwargs(form_list=None, initial_dict=None, instance_dict=None, condition_dict=None, *args, **kwargs)[source]

Create a dict with all needed parameters.

For the form wizard instances.
  • form_list - is a list of forms. The list entries can be single form classes or tuples of (step_name, form_class). If you pass a list of forms, the wizardview will convert the class list to (zero_based_counter, form_class). This is needed to access the form for a specific step.
  • initial_dict - contains a dictionary of initial data dictionaries. The key should be equal to the step_name in the form_list (or the str of the zero based counter - if no step_names added in the form_list)
  • instance_dict - contains a dictionary whose values are model instances if the step is based on a ModelForm and querysets if the step is based on a ModelFormSet. The key should be equal to the step_name in the form_list. Same rules as for initial_dict apply.
  • condition_dict - contains a dictionary of boolean values or callables. If the value of for a specific step_name is callable it will be called with the wizardview instance as the only argument. If the return value is true, the step’s form will be used.
get_next_step(step=None)[source]

Get next step.

Returns the next step after the given step. If no more steps are available, None will be returned. If the step argument is None, the current step will be determined automatically.

get_prefix(request, *args, **kwargs)[source]

Get prefix.

get_prev_step(step=None)[source]

Get previous step.

Returns the previous step before the given step. If there are no steps available, None will be returned. If the step argument is None, the current step will be determined automatically.

get_step_index(step=None)[source]

Get step index.

Returns the index for the given step name. If no step is given, the current step will be used to get the index.

initial_dict = None
instance_dict = None
post(*args, **kwargs)[source]

POST requests.

This method handles POST requests.

The wizard will render either the current step (if form validation wasn’t successful), the next step (if the current step was stored successful) or the done view (if no more steps are available)

process_step(form)[source]

Process the step.

This method is used to post-process the form data. By default, it returns the raw form.data dictionary.

process_step_files(form)[source]

Process step files.

This method is used to post-process the form files. By default, it returns the raw form.files dictionary.

render(form=None, **kwargs)[source]

Render.

Returns a HttpResponse containing all needed context data.

render_done(form, **kwargs)[source]

Render done.

This method gets called when all forms passed. The method should also re-validate all steps to prevent manipulation. If any form fails to validate, render_revalidation_failure should get called. If everything is fine call done.

render_goto_step(goto_step, **kwargs)[source]

Render goto step.

This method gets called when the current step has to be changed. goto_step contains the requested step to go to.

render_next_step(form, **kwargs)[source]

Render next step.

This method gets called when the next step/form should be rendered. form contains the last/current form.

render_revalidation_failure(step, form, **kwargs)[source]

Render revalidation failure.

Gets called when a form doesn’t validate when rendering the done view. By default, it changes the current step to failing forms step and renders the form.

storage_name = None
template_name = 'formtools/wizard/wizard_form.html'
class fobi.wizard.views.dynamic.DynamicSessionWizardView(**kwargs)[source]

Bases: fobi.wizard.views.dynamic.DynamicWizardView

A WizardView with pre-configured SessionStorage backend.

storage_name = 'formtools.wizard.storage.session.SessionStorage'
class fobi.wizard.views.dynamic.DynamicCookieWizardView(**kwargs)[source]

Bases: fobi.wizard.views.dynamic.DynamicWizardView

A WizardView with pre-configured CookieStorage backend.

storage_name = 'formtools.wizard.storage.cookie.CookieStorage'
class fobi.wizard.views.dynamic.DynamicNamedUrlWizardView(**kwargs)[source]

Bases: fobi.wizard.views.dynamic.DynamicWizardView

A WizardView with URL named steps support.

done_step_name = None
get(*args, **kwargs)[source]

GET request.

This renders the form or, if needed, does the http redirects.

get_context_data(form, **kwargs)[source]

Get context data.

NamedUrlWizardView provides the url_name of this wizard in the context dict wizard.

classmethod get_initkwargs(*args, **kwargs)[source]

Get init kwargs.

We require a url_name to reverse URLs later. Additionally users can pass a done_step_name to change the URL name of the “done” view.

get_step_url(step)[source]

Get step URL.

post(*args, **kwargs)[source]

POST request.

Do a redirect if user presses the prev. step button. The rest of this is super’d from WizardView.

render_done(form, **kwargs)[source]

Render done.

When rendering the done view, we have to redirect first (if the URL name doesn’t fit).

render_goto_step(goto_step, **kwargs)[source]

Render goto step.

This method gets called when the current step has to be changed. goto_step contains the requested step to go to.

render_next_step(form, **kwargs)[source]

Render next step.

When using the NamedUrlWizardView, we have to redirect to update the browser’s URL to match the shown step.

render_revalidation_failure(failed_step, form, **kwargs)[source]

Render revalidation failure.

When a step fails, we have to redirect the user to the first failing step.

url_name = None
class fobi.wizard.views.dynamic.DynamicNamedUrlSessionWizardView(**kwargs)[source]

Bases: fobi.wizard.views.dynamic.DynamicNamedUrlWizardView

A NamedUrlWizardView with pre-configured SessionStorage backend.

storage_name = 'formtools.wizard.storage.session.SessionStorage'
class fobi.wizard.views.dynamic.DynamicNamedUrlCookieWizardView(**kwargs)[source]

Bases: fobi.wizard.views.dynamic.DynamicNamedUrlWizardView

A NamedUrlFormWizard with pre-configured CookieStorageBackend.

storage_name = 'formtools.wizard.storage.cookie.CookieStorage'

fobi.wizard.views.views module

class fobi.wizard.views.views.WizardView(**kwargs)[source]

Bases: formtools.wizard.views.WizardView, fobi.wizard.views.views.PatchGetMixin

Patched version of the original WizardView.

get(request, *args, **kwargs)[source]

GET requests.

This method handles GET requests.

If a GET request reaches this point, the wizard assumes that the user just starts at the first step or wants to restart the process. The data of the wizard will be resetted before rendering the first step.

class fobi.wizard.views.views.SessionWizardView(**kwargs)[source]

Bases: formtools.wizard.views.SessionWizardView, fobi.wizard.views.views.PatchGetMixin

A WizardView with pre-configured SessionStorage backend.

get(request, *args, **kwargs)[source]

GET requests.

This method handles GET requests.

If a GET request reaches this point, the wizard assumes that the user just starts at the first step or wants to restart the process. The data of the wizard will be resetted before rendering the first step.

class fobi.wizard.views.views.CookieWizardView(**kwargs)[source]

Bases: formtools.wizard.views.CookieWizardView, fobi.wizard.views.views.PatchGetMixin

A WizardView with pre-configured CookieStorage backend.

get(request, *args, **kwargs)[source]

GET requests.

This method handles GET requests.

If a GET request reaches this point, the wizard assumes that the user just starts at the first step or wants to restart the process. The data of the wizard will be resetted before rendering the first step.

Module contents