Previous topic

Session Wizard

Next topic

Step

This Page

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 done method.

New in version 0.1.

Parameters:
  • steps – Provides a list of Step objects 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)

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 HttpRequest object 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 HttpResponse object.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
get_after(request, step)[source]

Returns the next Step in the sequence after the provided Step. This function will return None if there is no next step.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The Step to use as an index for finding the next Step
get_before(request, step)[source]

Returns the previous Step in the sequence after the provided Step. This function will return None if there is no previous step.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The Step to use as an index for finding the next Step
get_cleaned_data(request, step)[source]

Returns the cleaned form data for the provided step.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The Step to use to pull the cleaned form data.
get_form_data(request)

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 HttpRequest object that carries along with it the session used to access the wizard state.
get_step(request, slug)[source]

Returns the Step that matches the provided slug.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • slug – The unique identifier for a particular Step in the sequence.
get_steps(request)[source]

Returns the list of :class:`Step`s used in this wizard sequence.

Parameters:
  • request – A HttpRequest object 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 HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The current Step that is being processed.
  • form – The Django Form object that is being processed.
initialize(request, wizard_state)

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 HttpRequest object for this request.
  • wizard_state

    The WizardState object representing the current state of the wizard. Extra information can be appended to the state so it can be available to Step‘s of the wizard.

    For example::
    if ‘profile’ not in wizard_state:
    wizard_state.profile = request.user.get_profile()
insert_after(request, *args, **kwargs)[source]

Inserts a new step into the wizard sequence after the provided step.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • current_step – The Step to use as an index for inserting a new step
  • step – The new Step to insert.
insert_before(request, *args, **kwargs)[source]

Inserts a new step into the wizard sequence before the provided step.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • current_step – The Step to use as an index for inserting a new step
  • step – The new Step to insert.
process_GET(request, step)[source]

Renders the Form for the requested Step

process_POST(request, step)[source]

Processes the current Step and either send a redirect to the next Step in the sequence or finished the wizard process by calling self.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 HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The current Step that is being processed.
  • form – The Django Form object that is being processed.
process_step(request, step, form)[source]

Hook for modifying the SessionWizard‘s internal state, given a fully validated Form object. The Form is 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 HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The current Step that is being processed.
  • form – The Django Form object that is being processed.
remove_step(request, *args, **kwargs)[source]

Removes step from the wizard sequence.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The Step to remove.
render_form(request, step, form, context)[source]

Renders a form with the provided context and returns a HttpResponse object. This can be overridden to provide custom rendering to the client or using a different template engine.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The current Step that is being processed.
  • form – The Django Form object that is being processed.
  • context – The default context that templates can use which also contains any extra context created in the process_show_form hook.
set_cleaned_data(request, *args, **kwargs)[source]

Sets the cleaned form data for the provided step.

Parameters:
  • request – A HttpRequest object that carries along with it the session used to access the wizard state.
  • step – The Step to use to store the cleaned form data.
  • data – The cleaned Form data to store.