| 3 | | |
|---|
| 4 | | This is an abstraction of the following workflow: |
|---|
| 5 | | |
|---|
| 6 | | "Display an HTML form, force a preview, then do something with the submission." |
|---|
| 7 | | |
|---|
| 8 | | Given a django.newforms.Form object that you define, this takes care of the |
|---|
| 9 | | following: |
|---|
| 10 | | |
|---|
| 11 | | * Displays the form as HTML on a Web page. |
|---|
| 12 | | * Validates the form data once it's submitted via POST. |
|---|
| 13 | | * If it's valid, displays a preview page. |
|---|
| 14 | | * If it's not valid, redisplays the form with error messages. |
|---|
| 15 | | * At the preview page, if the preview confirmation button is pressed, calls |
|---|
| 16 | | a hook that you define -- a done() method. |
|---|
| 17 | | |
|---|
| 18 | | The framework enforces the required preview by passing a shared-secret hash to |
|---|
| 19 | | the preview page. If somebody tweaks the form parameters on the preview page, |
|---|
| 20 | | the form submission will fail the hash comparison test. |
|---|
| 21 | | |
|---|
| 22 | | Usage |
|---|
| 23 | | ===== |
|---|
| 24 | | |
|---|
| 25 | | Subclass FormPreview and define a done() method: |
|---|
| 26 | | |
|---|
| 27 | | def done(self, request, cleaned_data): |
|---|
| 28 | | # ... |
|---|
| 29 | | |
|---|
| 30 | | This method takes an HttpRequest object and a dictionary of the form data after |
|---|
| 31 | | it has been validated and cleaned. It should return an HttpResponseRedirect. |
|---|
| 32 | | |
|---|
| 33 | | Then, just instantiate your FormPreview subclass by passing it a Form class, |
|---|
| 34 | | and pass that to your URLconf, like so: |
|---|
| 35 | | |
|---|
| 36 | | (r'^post/$', MyFormPreview(MyForm)), |
|---|
| 37 | | |
|---|
| 38 | | The FormPreview class has a few other hooks. See the docstrings in the source |
|---|
| 39 | | code below. |
|---|
| 40 | | |
|---|
| 41 | | The framework also uses two templates: 'formtools/preview.html' and |
|---|
| 42 | | 'formtools/form.html'. You can override these by setting 'preview_template' and |
|---|
| 43 | | 'form_template' attributes on your FormPreview subclass. See |
|---|
| 44 | | django/contrib/formtools/templates for the default templates. |
|---|