Skip to content

Commit a9b2ac2

Browse files
committed
Fixed #9147 -- Added FormPreview.process_preview customization hook. Thanks, bthomas and thalin.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12486 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 9810178 commit a9b2ac2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

django/contrib/formtools/preview.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def preview_post(self, request):
6060
f = self.form(request.POST, auto_id=AUTO_ID)
6161
context = {'form': f, 'stage_field': self.unused_name('stage'), 'state': self.state}
6262
if f.is_valid():
63+
self.process_preview(request, f, context)
6364
context['hash_field'] = self.unused_name('hash')
6465
context['hash_value'] = self.security_hash(request, f)
6566
return render_to_response(self.preview_template, context, context_instance=RequestContext(request))
@@ -96,6 +97,13 @@ def parse_params(self, *args, **kwargs):
9697
"""
9798
pass
9899

100+
def process_preview(self, request, form, context):
101+
"""
102+
Given a validated form, performs any extra processing before displaying
103+
the preview page, and saves any extra data in context.
104+
"""
105+
pass
106+
99107
def security_hash(self, request, form):
100108
"""
101109
Calculates the security hash for the given HttpRequest and Form instances.

docs/ref/contrib/formtools/form-preview.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,16 @@ These values can be overridden for a particular form preview by setting
108108
:attr:`~django.contrib.formtools.FormPreview.form_template` attributes on the
109109
FormPreview subclass. See :file:`django/contrib/formtools/templates` for the
110110
default templates.
111+
112+
Advanced ``FormPreview`` methods
113+
================================
114+
115+
.. versionadded:: 1.2
116+
117+
.. method:: FormPreview.process_preview
118+
119+
Given a validated form, performs any extra processing before displaying the
120+
preview page, and saves any extra data in context.
121+
122+
By default, this method is empty. It is called after the form is validated,
123+
but before the context is modified with hash information and rendered.

docs/ref/contrib/formtools/form-wizard.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ wizard takes a list of your :class:`~django.forms.Form` objects as arguments::
199199
(r'^contact/$', ContactWizard([ContactForm1, ContactForm2])),
200200
)
201201

202-
Advanced FormWizard methods
203-
===========================
202+
Advanced ``FormWizard`` methods
203+
===============================
204204

205205
.. class:: FormWizard
206206

0 commit comments

Comments
 (0)