wizards.py

This module contains the subclassed WizardView which allows filling in a list of forms.

The wizard uses a apps.questionnaire.storage.DatabaseStorage instance to store the filled in information.

In short the wizard uses the following internal procedure for displaying forms and saving data:

  1. The wizard view is called with a questionnaire_request.id. The corresponding questionnaire_request is used to get the associated requeststeps. From these steps the models are used to get the full list of forms for the wizard.
  2. By using the step queryparameter (or by default the first step) the corresponding form is selected to be rendered. From the storage the cleaned data or unclean data is used to initialize the form with data.
  3. After an HTML post the form is checked for validation. If it validates the clean_data is saved as cleaned-data, else it is stored as unclean data.
  4. When the last form has been posted all clean data is retrieved from the storage instance and used to initalize & save instances of the models which are coupled to the forms.

Class definitions:

class apps.questionnaire.wizards.QuestionnaireWizard(**kwargs)[source]

Bases: formtools.wizard.views.WizardView

Questionnaire Wizard view class Used for all questionnaires

init_form_list(form_list)[source]

Re-executes the below code after the form_list is updated with the forms based on the models coupled to the questionnaires for the questionnaire_request

Args:
-form_list: the list of forms
Returns:
The computed form list which is dict of forms with a zero based counter
strip_initial_data(step, posted_data)[source]

Helper function for stripping posted data to be usable as initial_data

Args:
  • step: the step key
  • posted_data: the posted_data in dict form
Returns:
The initial data based on the post_data
get_form_initial(step)[source]

Get the initial data to initialize the form with

Args:
  • step: is the step key
Returns:
The initial data for a form based on the step key
get_prefix(*args, **kwargs)[source]

The questionnaire_request_id is used as prefix for storing data in the storage instance

Note

This is not really necessary since the storage instance is also coupled to the questionnaire_request

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

Initialize the form_list by getting all forms for the models for each request_step coupled to the questionnaire_requests

Args:
  • request: the request instance
get_form_list()[source]

Override of the baseclass method to insert custom condition testing on the forms.

Returns:
A list of forms exluding the forms for which the condition returns False
post(request, *args, **kwargs)[source]

Processes the post_data when a form is posted, is also called when the next or back button or save_and_exit is clicked. Allows saving partially filled (invalid) forms.

Args:
  • request: the request instance
Returns:
The response of the post method of the superclass
get(request, *args, **kwargs)[source]

The get function either loads the first form or the form corresponding to the step querystring parameter

Args:
  • request: the request instance
Returns:
The response of the render_goto_step function
get_form_kwargs(step=None)[source]

Adds the patient as default kwargs

Args:
  • step: the step key (default = None)
Returns:
A form kwargs dict.
process_step(form)[source]

Processes a valid form step by returning the data and remove unclean_data if present. This function is called in the post method.

Args:
  • form: the form to process
Returns:
The form step data for the given form
get_template_names()[source]
Returns:
The default wizard template name
get_cleaned_data_for_form_class(form_class)[source]

Helper function for getting the cleaned_data for a form class

Args:
  • form_class: the form_class to get the cleaned_data for
Returns:
The cleaned data for the form step or None
get_context_data(form, **kwargs)[source]

Adds extra context data for rendering the template

Args:
  • form: the form to include and get the context for
Returns:
A dict with the context to use for rendering the template
done(form_list, **kwargs)[source]

Save all gathered data and redirect to the finished page Called when the all forms are valid and the last form is posted.

Args:
  • form_list: the list with all processed forms
Returns:
Redirect to ‘finished url’