Package django :: Package contrib :: Package formtools :: Module wizard :: Class FormWizard
[hide private]
[frames] | no frames]

Class FormWizard

source code

object --+
         |
        FormWizard

Instance Methods [hide private]
 
__init__(self, form_list, initial=None)
form_list should be a list of Form classes (not instances).
source code
 
__repr__(self)
repr(x)
source code
 
get_form(self, step, data=None)
Helper method that returns the Form instance for the given step.
source code
 
num_steps(self)
Helper method that returns the number of steps.
source code
 
__call__(self, request, *args, **kwargs)
Main method that does all the hard work, conforming to the Django view interface.
source code
 
render(self, form, request, step, context=None)
Renders the given Form object, returning an HttpResponse.
source code
 
prefix_for_step(self, step)
Given the step, returns a Form prefix to use.
source code
 
render_hash_failure(self, request, step)
Hook for rendering a template if a hash check failed.
source code
 
render_revalidation_failure(self, request, step, form)
Hook for rendering a template if final revalidation failed.
source code
 
security_hash(self, request, form)
Calculates the security hash for the given HttpRequest and Form instances.
source code
 
determine_step(self, request, *args, **kwargs)
Given the request object and whatever *args and **kwargs were passed to __call__(), returns the current step (which is zero-based).
source code
 
parse_params(self, request, *args, **kwargs)
Hook for setting some state, given the request object and whatever *args and **kwargs were passed to __call__(), sets some state.
source code
 
get_template(self, step)
Hook for specifying the name of the template to use for a given step.
source code
 
render_template(self, request, form, previous_fields, step, context=None)
Renders the template for the given step, returning an HttpResponse object.
source code
 
process_step(self, request, form, step)
Hook for modifying the FormWizard's internal state, given a fully validated Form object.
source code
 
done(self, request, form_list)
Hook for doing something with the validated data.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Variables [hide private]
  extra_context = {}
  step_field_name = "wizard_step"
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, form_list, initial=None)
(Constructor)

source code 

form_list should be a list of Form classes (not instances).

Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

render_hash_failure(self, request, step)

source code 

Hook for rendering a template if a hash check failed.

step is the step that failed. Any previous step is guaranteed to be valid.

This default implementation simply renders the form for the given step, but subclasses may want to display an error message, etc.

render_revalidation_failure(self, request, step, form)

source code 

Hook for rendering a template if final revalidation failed.

It is highly unlikely that this point would ever be reached, but See the comment in __call__() for an explanation.

security_hash(self, request, form)

source code 

Calculates the security hash for the given HttpRequest and Form instances.

This creates a list of the form field names/values in a deterministic order, pickles the result with the SECRET_KEY setting and takes an md5 hash of that.

Subclasses may want to take into account request-specific information, such as the IP address.

determine_step(self, request, *args, **kwargs)

source code 

Given the request object and whatever *args and **kwargs were passed to __call__(), returns the current step (which is zero-based).

Note that the result should not be trusted. It may even be a completely invalid number. It's not the job of this method to validate it.

parse_params(self, request, *args, **kwargs)

source code 

Hook for setting some state, given the request object and whatever *args and **kwargs were passed to __call__(), sets some state.

This is called at the beginning of __call__().

get_template(self, step)

source code 

Hook for specifying the name of the template to use for a given step.

Note that this can return a tuple of template names if you'd like to use the template system's select_template() hook.

render_template(self, request, form, previous_fields, step, context=None)

source code 

Renders the template for the given step, returning an HttpResponse object.

Override this method if you want to add a custom context, return a
different MIME type, etc. If you only need to override the template
name, use get_template() instead.

The template will be rendered with the following context:
    step_field -- The name of the hidden field containing the step.
    step0      -- The current step (zero-based).
    step       -- The current step (one-based).
    step_count -- The total number of steps.
    form       -- The Form instance for the current step (either empty
                  or with errors).
    previous_fields -- A string representing every previous data field,
                  plus hashes for completed forms, all in the form of
                  hidden fields. Note that you'll need to run this
                  through the "safe" template filter, to prevent
                  auto-escaping, because it's raw HTML.

process_step(self, request, form, step)

source code 

Hook for modifying the FormWizard'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 to set self.extra_context or dynamically alter self.form_list, based on previously submitted forms.

Note that this method is called every time a page is rendered for *all* submitted steps.

done(self, request, form_list)

source code 

Hook for doing something with the validated data. This is responsible for the final processing.

form_list is a list of Form instances, each containing clean, valid data.