SessionWizard¶
-
class
merlin.wizards.session.SessionWizard(steps)[source]¶ This class allows for the ability to chop up a long form into sizable steps and process each step in sequence. It also provides the ability to go back to a previous step or move on to the next step in the sequence. When the wizard runs out of steps it calls a final function that finishes the form process. This class should be subclassed and the subclass should at a minimum override the
donemethod.New in version 0.1.
Parameters: steps – Provides a list of Stepobjects in the order in which the wizard should display them to the user. This list can be manipulated to add or remove steps as needed.-
cancel(request)[source]¶ Hook used to cancel a wizard. This will be called when slug is passed that matches “cancel”. By default the method will clear the session data.
Parameters: request – A HttpRequestobject for this request.
-
clear(request)[source]¶ Removes the internal wizard state from the session. This should be called right be for the return from a successful
done()call.
-
done(request)[source]¶ Responsible for processing the validated form data that the wizard collects from the user. This function should be overridden by the implementing subclass. This function needs to return a
HttpResponseobject.Parameters: request – A HttpRequestobject that carries along with it the session used to access the wizard state.
-
get_after(request, step)[source]¶ Returns the next
Stepin the sequence after the providedStep. This function will returnNoneif there is no next step.Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The
Stepto use as an index for finding the nextStep
- request – A
-
get_before(request, step)[source]¶ Returns the previous
Stepin the sequence after the providedStep. This function will returnNoneif there is no previous step.Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The
Stepto use as an index for finding the nextStep
- request – A
-
get_cleaned_data(request, step)[source]¶ Returns the cleaned form data for the provided step.
Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The
Stepto use to pull the cleaned form data.
- request – A
-
get_form_data(request)[source]¶ This will return the form_data dictionary that has been saved in the session. This will mainly be used in the done to query for the form_data that has been saved throughout the wizard process.
Parameters: request – A HttpRequestobject that carries along with it the session used to access the wizard state.
-
get_step(request, slug)[source]¶ Returns the
Stepthat matches the provided slug.Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - slug – The unique identifier for a particular
Stepin the sequence.
- request – A
-
get_steps(request)[source]¶ Returns the list of :class:`Step`s used in this wizard sequence.
Parameters: request – A HttpRequestobject that carries along with it the session used to access the wizard state.
-
get_template(request, step, form)[source]¶ Responsible for return the path to the template that should be used to render this current form.
Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The current
Stepthat is being processed. - form – The Django
Formobject that is being processed.
- request – A
-
initialize(request, wizard_state)[source]¶ Hook used to initialize the wizard subclass. This will be called for every request to the wizard before it processes the GET or POST.
Parameters: - request – A
HttpRequestobject for this request. - wizard_state –
The
WizardStateobject representing the current state of the wizard. Extra information can be appended to the state so it can be available toStep‘s of the wizard.- For example::
- if ‘profile’ not in wizard_state:
- wizard_state.profile = request.user.get_profile()
- request – A
-
insert_after(request, *args, **kwargs)[source]¶ Inserts a new step into the wizard sequence after the provided step.
Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - current_step – The
Stepto use as an index for inserting a new step - step – The new
Stepto insert.
- request – A
-
insert_before(request, *args, **kwargs)[source]¶ Inserts a new step into the wizard sequence before the provided step.
Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - current_step – The
Stepto use as an index for inserting a new step - step – The new
Stepto insert.
- request – A
-
process_POST(request, step)[source]¶ Processes the current
Stepand either send a redirect to the nextStepin the sequence or finished the wizard process by callingself.done
-
process_show_form(request, step, form)[source]¶ Hook used for providing extra context that can be used in the template used to render the current form.
Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The current
Stepthat is being processed. - form – The Django
Formobject that is being processed.
- request – A
-
process_step(request, step, form)[source]¶ Hook for modifying the
SessionWizard‘s internal state, given a fully validatedFormobject. TheFormis guaranteed to have clean, valid data.This method should not modify any of that data. Rather, it might want dynamically alter the step list, based on previously submitted forms.
Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The current
Stepthat is being processed. - form – The Django
Formobject that is being processed.
- request – A
-
remove_step(request, *args, **kwargs)[source]¶ Removes step from the wizard sequence.
Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The
Stepto remove.
- request – A
-
render_form(request, step, form, context)[source]¶ Renders a form with the provided context and returns a
HttpResponseobject. This can be overridden to provide custom rendering to the client or using a different template engine.Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The current
Stepthat is being processed. - form – The Django
Formobject that is being processed. - context – The default context that templates can use which also contains
any extra context created in the
process_show_formhook.
- request – A
-
set_cleaned_data(request, *args, **kwargs)[source]¶ Sets the cleaned form data for the provided step.
Parameters: - request – A
HttpRequestobject that carries along with it the session used to access the wizard state. - step – The
Stepto use to store the cleaned form data. - data – The cleaned
Formdata to store.
- request – A
-