Skip to content

Commit

Permalink
Fixed #9147 -- Added FormPreview.process_preview customization hook…
Browse files Browse the repository at this point in the history
…. Thanks, bthomas and thalin.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12486 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jbronn committed Feb 22, 2010
1 parent 9810178 commit a9b2ac2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions django/contrib/formtools/preview.py
Expand Up @@ -60,6 +60,7 @@ def preview_post(self, request):
f = self.form(request.POST, auto_id=AUTO_ID)
context = {'form': f, 'stage_field': self.unused_name('stage'), 'state': self.state}
if f.is_valid():
self.process_preview(request, f, context)
context['hash_field'] = self.unused_name('hash')
context['hash_value'] = self.security_hash(request, f)
return render_to_response(self.preview_template, context, context_instance=RequestContext(request))
Expand Down Expand Up @@ -96,6 +97,13 @@ def parse_params(self, *args, **kwargs):
"""
pass

def process_preview(self, request, form, context):
"""
Given a validated form, performs any extra processing before displaying
the preview page, and saves any extra data in context.
"""
pass

def security_hash(self, request, form):
"""
Calculates the security hash for the given HttpRequest and Form instances.
Expand Down
13 changes: 13 additions & 0 deletions docs/ref/contrib/formtools/form-preview.txt
Expand Up @@ -108,3 +108,16 @@ These values can be overridden for a particular form preview by setting
:attr:`~django.contrib.formtools.FormPreview.form_template` attributes on the
FormPreview subclass. See :file:`django/contrib/formtools/templates` for the
default templates.

Advanced ``FormPreview`` methods
================================

.. versionadded:: 1.2

.. method:: FormPreview.process_preview

Given a validated form, performs any extra processing before displaying the
preview page, and saves any extra data in context.

By default, this method is empty. It is called after the form is validated,
but before the context is modified with hash information and rendered.
4 changes: 2 additions & 2 deletions docs/ref/contrib/formtools/form-wizard.txt
Expand Up @@ -199,8 +199,8 @@ wizard takes a list of your :class:`~django.forms.Form` objects as arguments::
(r'^contact/$', ContactWizard([ContactForm1, ContactForm2])),
)

Advanced FormWizard methods
===========================
Advanced ``FormWizard`` methods
===============================

.. class:: FormWizard

Expand Down

0 comments on commit a9b2ac2

Please sign in to comment.