Sophie

Sophie

distrib > Arklinux > devel > i586 > media > main > by-pkgid > 5fcb1fedf34660bc240dc59b7bfcebc4 > files > 341

django-doc-1.2.3-1ark.noarch.rpm


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Form wizard &mdash; Django v1.2 documentation</title>
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="top" title="Django v1.2 documentation" href="../../../index.html" />
    <link rel="up" title="django.contrib.formtools" href="index.html" />
    <link rel="next" title="GeoDjango" href="../gis/index.html" />
    <link rel="prev" title="Form preview" href="form-preview.html" />
 
<script type="text/javascript" src="../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>

  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django v1.2 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="form-preview.html" title="Form preview">previous</a> 
     |
    <a href="../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="../gis/index.html" title="GeoDjango">next</a> &raquo;</div>
    </div>
    
    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-formtools-form-wizard">
            
  <div class="section" id="s-module-django.contrib.formtools.wizard">
<span id="s-form-wizard"></span><span id="module-django.contrib.formtools.wizard"></span><span id="form-wizard"></span><h1>Form wizard<a class="headerlink" href="#module-django.contrib.formtools.wizard" title="Permalink to this headline">¶</a></h1>
<div class="versionadded">
<span class="title">New in Django 1.0:</span> <a class="reference internal" href="../../../releases/1.0.html"><em>Please, see the release notes</em></a></div>
<p>Django comes with an optional &#8220;form wizard&#8221; application that splits
<a class="reference internal" href="../../../topics/forms/index.html"><em>forms</em></a> across multiple Web pages. It maintains
state in hashed HTML <tt class="samp docutils literal"><span class="pre">&lt;input</span> <span class="pre">type=&quot;hidden&quot;&gt;</span></tt> fields, and the data isn&#8217;t
processed server-side until the final form is submitted.</p>
<p>You might want to use this if you have a lengthy form that would be too
unwieldy for display on a single page. The first page might ask the user for
core information, the second page might ask for less important information,
etc.</p>
<p>The term &#8220;wizard,&#8221; in this context, is <a class="reference external" href="http://en.wikipedia.org/wiki/Wizard_%28software%29">explained on Wikipedia</a>.</p>
<div class="section" id="s-how-it-works">
<span id="how-it-works"></span><h2>How it works<a class="headerlink" href="#how-it-works" title="Permalink to this headline">¶</a></h2>
<p>Here&#8217;s the basic workflow for how a user would use a wizard:</p>
<ol class="arabic simple">
<li>The user visits the first page of the wizard, fills in the form and
submits it.</li>
<li>The server validates the data. If it&#8217;s invalid, the form is displayed
again, with error messages. If it&#8217;s valid, the server calculates a
secure hash of the data and presents the user with the next form,
saving the validated data and hash in <tt class="samp docutils literal"><span class="pre">&lt;input</span> <span class="pre">type=&quot;hidden&quot;&gt;</span></tt>
fields.</li>
<li>Step 1 and 2 repeat, for every subsequent form in the wizard.</li>
<li>Once the user has submitted all the forms and all the data has been
validated, the wizard processes the data &#8211; saving it to the database,
sending an e-mail, or whatever the application needs to do.</li>
</ol>
</div>
<div class="section" id="s-usage">
<span id="usage"></span><h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p>This application handles as much machinery for you as possible. Generally, you
just have to do these things:</p>
<ol class="arabic simple">
<li>Define a number of <a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> classes &#8211; one per wizard
page.</li>
<li>Create a <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard" title="django.contrib.formtools.wizard.FormWizard"><tt class="xref py py-class docutils literal"><span class="pre">FormWizard</span></tt></a> class that specifies what to do once all of
your forms have been submitted and validated. This also lets you
override some of the wizard&#8217;s behavior.</li>
<li>Create some templates that render the forms. You can define a single,
generic template to handle every one of the forms, or you can define a
specific template for each form.</li>
<li>Point your URLconf at your <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard" title="django.contrib.formtools.wizard.FormWizard"><tt class="xref py py-class docutils literal"><span class="pre">FormWizard</span></tt></a> class.</li>
</ol>
</div>
<div class="section" id="s-defining-form-classes">
<span id="defining-form-classes"></span><h2>Defining <tt class="docutils literal"><span class="pre">Form</span></tt> classes<a class="headerlink" href="#defining-form-classes" title="Permalink to this headline">¶</a></h2>
<p>The first step in creating a form wizard is to create the
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> classes.  These should be standard
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">django.forms.Form</span></tt></a> classes, covered in the <a class="reference internal" href="../../../topics/forms/index.html"><em>forms documentation</em></a>.  These classes can live anywhere in your codebase, but
convention is to put them in a file called <tt class="file docutils literal"><span class="pre">forms.py</span></tt> in your
application.</p>
<p>For example, let&#8217;s write a &#8220;contact form&#8221; wizard, where the first page&#8217;s form
collects the sender&#8217;s e-mail address and subject, and the second page collects
the message itself. Here&#8217;s what the <tt class="file docutils literal"><span class="pre">forms.py</span></tt> might look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>

<span class="k">class</span> <span class="nc">ContactForm1</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">subject</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>
    <span class="n">sender</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">EmailField</span><span class="p">()</span>

<span class="k">class</span> <span class="nc">ContactForm2</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">message</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">Textarea</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>Important limitation:</strong> Because the wizard uses HTML hidden fields to store
data between pages, you may not include a <a class="reference internal" href="../../forms/fields.html#django.forms.FileField" title="django.forms.FileField"><tt class="xref py py-class docutils literal"><span class="pre">FileField</span></tt></a>
in any form except the last one.</p>
</div>
<div class="section" id="s-creating-a-formwizard-class">
<span id="creating-a-formwizard-class"></span><h2>Creating a <tt class="docutils literal"><span class="pre">FormWizard</span></tt> class<a class="headerlink" href="#creating-a-formwizard-class" title="Permalink to this headline">¶</a></h2>
<p>The next step is to create a
<a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard" title="django.contrib.formtools.wizard.FormWizard"><tt class="xref py py-class docutils literal"><span class="pre">django.contrib.formtools.wizard.FormWizard</span></tt></a> subclass.  As with your
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> classes, this <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard" title="django.contrib.formtools.wizard.FormWizard"><tt class="xref py py-class docutils literal"><span class="pre">FormWizard</span></tt></a> class can live
anywhere in your codebase, but convention is to put it in <tt class="file docutils literal"><span class="pre">forms.py</span></tt>.</p>
<p>The only requirement on this subclass is that it implement a
<a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard.done" title="django.contrib.formtools.wizard.FormWizard.done"><tt class="xref py py-meth docutils literal"><span class="pre">done()</span></tt></a> method.</p>
<dl class="method">
<dt id="django.contrib.formtools.wizard.FormWizard.done">
<tt class="descclassname">FormWizard.</tt><tt class="descname">done</tt>()<a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard.done" title="Permalink to this definition">¶</a></dt>
<dd><p>This method specifies what should happen when the data for <em>every</em> form is
submitted and validated.  This method is passed two arguments:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">request</span></tt> -- an <a class="reference internal" href="../../request-response.html#django.http.HttpRequest" title="django.http.HttpRequest"><tt class="xref py py-class docutils literal"><span class="pre">HttpRequest</span></tt></a> object</li>
<li><tt class="docutils literal"><span class="pre">form_list</span></tt> -- a list of <a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> classes</li>
</ul>
</dd></dl>

<p>In this simplistic example, rather than perform any database operation, the
method simply renders a template of the validated data:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.shortcuts</span> <span class="kn">import</span> <span class="n">render_to_response</span>
<span class="kn">from</span> <span class="nn">django.contrib.formtools.wizard</span> <span class="kn">import</span> <span class="n">FormWizard</span>

<span class="k">class</span> <span class="nc">ContactWizard</span><span class="p">(</span><span class="n">FormWizard</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">done</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">form_list</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">&#39;done.html&#39;</span><span class="p">,</span> <span class="p">{</span>
            <span class="s">&#39;form_data&#39;</span><span class="p">:</span> <span class="p">[</span><span class="n">form</span><span class="o">.</span><span class="n">cleaned_data</span> <span class="k">for</span> <span class="n">form</span> <span class="ow">in</span> <span class="n">form_list</span><span class="p">],</span>
        <span class="p">})</span>
</pre></div>
</div>
<p>Note that this method will be called via <tt class="docutils literal"><span class="pre">POST</span></tt>, so it really ought to be a
good Web citizen and redirect after processing the data. Here's another
example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">HttpResponseRedirect</span>
<span class="kn">from</span> <span class="nn">django.contrib.formtools.wizard</span> <span class="kn">import</span> <span class="n">FormWizard</span>

<span class="k">class</span> <span class="nc">ContactWizard</span><span class="p">(</span><span class="n">FormWizard</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">done</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">form_list</span><span class="p">):</span>
        <span class="n">do_something_with_the_form_data</span><span class="p">(</span><span class="n">form_list</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span><span class="s">&#39;/page-to-redirect-to-when-done/&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>See the section <a class="reference internal" href="#advanced-formwizard-methods">Advanced FormWizard methods</a> below to learn about more
<a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard" title="django.contrib.formtools.wizard.FormWizard"><tt class="xref py py-class docutils literal"><span class="pre">FormWizard</span></tt></a> hooks.</p>
</div>
<div class="section" id="s-creating-templates-for-the-forms">
<span id="creating-templates-for-the-forms"></span><h2>Creating templates for the forms<a class="headerlink" href="#creating-templates-for-the-forms" title="Permalink to this headline">¶</a></h2>
<p>Next, you'll need to create a template that renders the wizard's forms. By
default, every form uses a template called <tt class="file docutils literal"><span class="pre">forms/wizard.html</span></tt>. (You can
change this template name by overriding <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard.get_template" title="django.contrib.formtools.wizard.FormWizard.get_template"><tt class="xref py py-meth docutils literal"><span class="pre">get_template()</span></tt></a>,
which is documented below. This hook also allows you to use a different
template for each form.)</p>
<p>This template expects the following context:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">step_field</span></tt> -- The name of the hidden field containing the step.</li>
<li><tt class="docutils literal"><span class="pre">step0</span></tt> -- The current step (zero-based).</li>
<li><tt class="docutils literal"><span class="pre">step</span></tt> -- The current step (one-based).</li>
<li><tt class="docutils literal"><span class="pre">step_count</span></tt> -- The total number of steps.</li>
<li><tt class="docutils literal"><span class="pre">form</span></tt> -- The <a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> instance for the current step
(either empty or with errors).</li>
<li><tt class="docutils literal"><span class="pre">previous_fields</span></tt> -- 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 <a class="reference internal" href="../../templates/builtins.html#std:templatefilter-safe"><tt class="xref std std-tfilter docutils literal"><span class="pre">safe</span></tt></a> template filter,
to prevent auto-escaping, because it's raw HTML.</li>
</ul>
<p>You can supply extra context to this template in two ways:</p>
<ul class="simple">
<li>Set the <tt class="xref py py-attr docutils literal"><span class="pre">extra_context</span></tt> attribute on your
<a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard" title="django.contrib.formtools.wizard.FormWizard"><tt class="xref py py-class docutils literal"><span class="pre">FormWizard</span></tt></a> subclass to a dictionary.</li>
<li>Pass a dictionary as a parameter named <tt class="docutils literal"><span class="pre">extra_context</span></tt> to your wizard's
URL pattern in your URLconf.  See <a class="reference internal" href="#hooking-wizard-into-urlconf"><em>Hooking the wizard into a URLconf</em></a>.</li>
</ul>
<p>Here's a full example template:</p>
<div class="highlight-html+django"><div class="highlight"><pre><span class="cp">{%</span> <span class="k">extends</span> <span class="s2">&quot;base.html&quot;</span> <span class="cp">%}</span>

<span class="cp">{%</span> <span class="k">block</span> <span class="nv">content</span> <span class="cp">%}</span>
<span class="nt">&lt;p&gt;</span>Step <span class="cp">{{</span> <span class="nv">step</span> <span class="cp">}}</span> of <span class="cp">{{</span> <span class="nv">step_count</span> <span class="cp">}}</span><span class="nt">&lt;/p&gt;</span>
<span class="nt">&lt;form</span> <span class="na">action=</span><span class="s">&quot;.&quot;</span> <span class="na">method=</span><span class="s">&quot;post&quot;</span><span class="nt">&gt;</span><span class="cp">{%</span> <span class="k">csrf_token</span> <span class="cp">%}</span>
<span class="nt">&lt;table&gt;</span>
<span class="cp">{{</span> <span class="nv">form</span> <span class="cp">}}</span>
<span class="nt">&lt;/table&gt;</span>
<span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;hidden&quot;</span> <span class="na">name=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">step_field</span> <span class="cp">}}</span><span class="s">&quot;</span> <span class="na">value=</span><span class="s">&quot;</span><span class="cp">{{</span> <span class="nv">step0</span> <span class="cp">}}</span><span class="s">&quot;</span> <span class="nt">/&gt;</span>
<span class="cp">{{</span> <span class="nv">previous_fields</span><span class="o">|</span><span class="nf">safe</span> <span class="cp">}}</span>
<span class="nt">&lt;input</span> <span class="na">type=</span><span class="s">&quot;submit&quot;</span><span class="nt">&gt;</span>
<span class="nt">&lt;/form&gt;</span>
<span class="cp">{%</span> <span class="k">endblock</span> <span class="cp">%}</span>
</pre></div>
</div>
<p>Note that <tt class="docutils literal"><span class="pre">previous_fields</span></tt>, <tt class="docutils literal"><span class="pre">step_field</span></tt> and <tt class="docutils literal"><span class="pre">step0</span></tt> are all required
for the wizard to work properly.</p>
</div>
<div class="section" id="s-hooking-the-wizard-into-a-urlconf">
<span id="s-hooking-wizard-into-urlconf"></span><span id="hooking-the-wizard-into-a-urlconf"></span><span id="hooking-wizard-into-urlconf"></span><h2>Hooking the wizard into a URLconf<a class="headerlink" href="#hooking-the-wizard-into-a-urlconf" title="Permalink to this headline">¶</a></h2>
<p>Finally, we need to specify which forms to use in the wizard, and then
deploy the new <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard" title="django.contrib.formtools.wizard.FormWizard"><tt class="xref py py-class docutils literal"><span class="pre">FormWizard</span></tt></a> object a URL in <tt class="docutils literal"><span class="pre">urls.py</span></tt>. The
wizard takes a list of your <a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> objects as
arguments when you instantiate the Wizard:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.conf.urls.defaults</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">mysite.testapp.forms</span> <span class="kn">import</span> <span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span><span class="p">,</span> <span class="n">ContactWizard</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="p">(</span><span class="s">r&#39;^contact/$&#39;</span><span class="p">,</span> <span class="n">ContactWizard</span><span class="p">([</span><span class="n">ContactForm1</span><span class="p">,</span> <span class="n">ContactForm2</span><span class="p">])),</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="s-advanced-formwizard-methods">
<span id="advanced-formwizard-methods"></span><h2>Advanced <tt class="docutils literal"><span class="pre">FormWizard</span></tt> methods<a class="headerlink" href="#advanced-formwizard-methods" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="django.contrib.formtools.wizard.FormWizard">
<em class="property">class </em><tt class="descname">FormWizard</tt><a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard" title="Permalink to this definition">¶</a></dt>
<dd><p>Aside from the <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard.done" title="django.contrib.formtools.wizard.FormWizard.done"><tt class="xref py py-meth docutils literal"><span class="pre">done()</span></tt></a> method, <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard" title="django.contrib.formtools.wizard.FormWizard"><tt class="xref py py-class docutils literal"><span class="pre">FormWizard</span></tt></a> offers a few
advanced method hooks that let you customize how your wizard works.</p>
<p>Some of these methods take an argument <tt class="docutils literal"><span class="pre">step</span></tt>, which is a zero-based
counter representing the current step of the wizard. (E.g., the first form
is <tt class="docutils literal"><span class="pre">0</span></tt> and the second form is <tt class="docutils literal"><span class="pre">1</span></tt>.)</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.FormWizard.prefix_for_step">
<tt class="descclassname">FormWizard.</tt><tt class="descname">prefix_for_step</tt>()<a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard.prefix_for_step" title="Permalink to this definition">¶</a></dt>
<dd><p>Given the step, returns a form prefix to use.  By default, this simply uses
the step itself. For more, see the <a class="reference internal" href="../../forms/api.html#form-prefix"><em>form prefix documentation</em></a>.</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">prefix_for_step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="p">):</span>
    <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">step</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.FormWizard.render_hash_failure">
<tt class="descclassname">FormWizard.</tt><tt class="descname">render_hash_failure</tt>()<a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard.render_hash_failure" title="Permalink to this definition">¶</a></dt>
<dd><p>Renders a template if the hash check fails. It's rare that you'd need to
override this.</p>
<p>Default implementation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">render_hash_failure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">step</span><span class="p">):</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_form</span><span class="p">(</span><span class="n">step</span><span class="p">),</span> <span class="n">request</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span>
        <span class="n">context</span><span class="o">=</span><span class="p">{</span><span class="s">&#39;wizard_error&#39;</span><span class="p">:</span>
                     <span class="s">&#39;We apologize, but your form has expired. Please&#39;</span>
                     <span class="s">&#39; continue filling out the form from this page.&#39;</span><span class="p">})</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.FormWizard.security_hash">
<tt class="descclassname">FormWizard.</tt><tt class="descname">security_hash</tt>()<a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard.security_hash" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates the security hash for the given request object and
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> instance.</p>
<p>By default, this uses an MD5 hash of the form data and your
<a class="reference internal" href="../../settings.html#std:setting-SECRET_KEY"><tt class="xref std std-setting docutils literal"><span class="pre">SECRET_KEY</span></tt></a> setting. It's rare that somebody would need to
override this.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">security_hash</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">form</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">my_hash_function</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">form</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.FormWizard.parse_params">
<tt class="descclassname">FormWizard.</tt><tt class="descname">parse_params</tt>()<a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard.parse_params" title="Permalink to this definition">¶</a></dt>
<dd><p>A hook for saving state from the request object and <tt class="docutils literal"><span class="pre">args</span></tt> / <tt class="docutils literal"><span class="pre">kwargs</span></tt>
that were captured from the URL by your URLconf.</p>
<p>By default, this does nothing.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">parse_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">my_state</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.FormWizard.get_template">
<tt class="descclassname">FormWizard.</tt><tt class="descname">get_template</tt>()<a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard.get_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the name of the template that should be used for the given step.</p>
<p>By default, this returns <tt class="file docutils literal"><span class="pre">'forms/wizard.html'</span></tt>, regardless of step.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_template</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="p">):</span>
    <span class="k">return</span> <span class="s">&#39;myapp/wizard_</span><span class="si">%s</span><span class="s">.html&#39;</span> <span class="o">%</span> <span class="n">step</span>
</pre></div>
</div>
<p>If <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard.get_template" title="django.contrib.formtools.wizard.FormWizard.get_template"><tt class="xref py py-meth docutils literal"><span class="pre">get_template()</span></tt></a> returns a list of strings, then the
wizard will use the template system's
<a class="reference internal" href="../../templates/api.html#django.template.loader.select_template" title="django.template.loader.select_template"><tt class="xref py py-func docutils literal"><span class="pre">select_template()</span></tt></a> function.
This means the system will use the first template that exists on the
filesystem. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">get_template</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">step</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">[</span><span class="s">&#39;myapp/wizard_</span><span class="si">%s</span><span class="s">.html&#39;</span> <span class="o">%</span> <span class="n">step</span><span class="p">,</span> <span class="s">&#39;myapp/wizard.html&#39;</span><span class="p">]</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.FormWizard.render_template">
<tt class="descclassname">FormWizard.</tt><tt class="descname">render_template</tt>()<a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard.render_template" title="Permalink to this definition">¶</a></dt>
<dd><p>Renders the template for the given step, returning an
<a class="reference internal" href="../../request-response.html#django.http.HttpResponse" title="django.http.HttpResponse"><tt class="xref py py-class docutils literal"><span class="pre">HttpResponse</span></tt></a> object.</p>
<p>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 <a class="reference internal" href="#django.contrib.formtools.wizard.FormWizard.get_template" title="django.contrib.formtools.wizard.FormWizard.get_template"><tt class="xref py py-meth docutils literal"><span class="pre">get_template()</span></tt></a> instead.</p>
<p>The template will be rendered with the context documented in the
&quot;Creating templates for the forms&quot; section above.</p>
</dd></dl>

<dl class="method">
<dt id="django.contrib.formtools.wizard.FormWizard.process_step">
<tt class="descclassname">FormWizard.</tt><tt class="descname">process_step</tt>()<a class="headerlink" href="#django.contrib.formtools.wizard.FormWizard.process_step" title="Permalink to this definition">¶</a></dt>
<dd><p>Hook for modifying the wizard's internal state, given a fully validated
<a class="reference internal" href="../../forms/api.html#django.forms.Form" title="django.forms.Form"><tt class="xref py py-class docutils literal"><span class="pre">Form</span></tt></a> object. The Form is guaranteed to have clean,
valid data.</p>
<p>This method should <em>not</em> modify any of that data. Rather, it might want to
set <tt class="docutils literal"><span class="pre">self.extra_context</span></tt> or dynamically alter <tt class="docutils literal"><span class="pre">self.form_list</span></tt>, based
on previously submitted forms.</p>
<p>Note that this method is called every time a page is rendered for <em>all</em>
submitted steps.</p>
<p>The function signature:</p>
<div class="highlight-python"><pre>def process_step(self, request, form, step):
    # ...</pre>
</div>
</dd></dl>

</div>
</div>


          </div>         
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Form wizard</a><ul>
<li><a class="reference internal" href="#how-it-works">How it works</a></li>
<li><a class="reference internal" href="#usage">Usage</a></li>
<li><a class="reference internal" href="#defining-form-classes">Defining <tt class="docutils literal"><span class="pre">Form</span></tt> classes</a></li>
<li><a class="reference internal" href="#creating-a-formwizard-class">Creating a <tt class="docutils literal"><span class="pre">FormWizard</span></tt> class</a></li>
<li><a class="reference internal" href="#creating-templates-for-the-forms">Creating templates for the forms</a></li>
<li><a class="reference internal" href="#hooking-the-wizard-into-a-urlconf">Hooking the wizard into a URLconf</a></li>
<li><a class="reference internal" href="#advanced-formwizard-methods">Advanced <tt class="docutils literal"><span class="pre">FormWizard</span></tt> methods</a></li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="form-preview.html">Form preview</a></li>
    
    
      <li>Next: <a href="../gis/index.html">GeoDjango</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../index.html">Django v1.2 documentation</a>
        
          <ul><li><a href="../../index.html">API Reference</a>
        
          <ul><li><a href="../index.html"><tt class="docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal docutils literal"><span class="pre">contrib</span></tt> packages</a>
        
          <ul><li><a href="index.html">django.contrib.formtools</a>
        
        <ul><li>Form wizard</li></ul>
        </li></ul></li></ul></li></ul>
      </li>
  </ul>  

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../../../_sources/ref/contrib/formtools/form-wizard.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Oct 20, 2010</p>
          </div> 
        
      
    </div>
    
    <div id="ft">
      <div class="nav">
    &laquo; <a href="form-preview.html" title="Form preview">previous</a> 
     |
    <a href="../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="../gis/index.html" title="GeoDjango">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>