Ticket #9583: django_formwizard_hash.patch

File django_formwizard_hash.patch, 1.7 KB (added by Ryan Williams, 16 years ago)

Patch to allow customisation of FormWizard hash field name.

  • django/contrib/formtools/wizard.py

     
    5962            raise Http404('Step %s does not exist' % current_step)
    6063
    6164        # For each previous step, verify the hash and process.
    62         # TODO: Move "hash_%d" to a method to make it configurable.
    6365        for i in range(current_step):
    6466            form = self.get_form(i, request.POST)
    65             if request.POST.get("hash_%d" % i, '') != self.security_hash(request, form):
     67            if request.POST.get(self.hash_field_for_step(i), '') != self.security_hash(request, form):
    6668                return self.render_hash_failure(request, i)
    6769            self.process_step(request, form, i)
    6870
     
    106108            # Collect all data from previous steps and render it as HTML hidden fields.
    107109            for i in range(step):
    108110                old_form = self.get_form(i, old_data)
    109                 hash_name = 'hash_%s' % i
     111                hash_name = self.hash_field_for_step(i)
    110112                prev_fields.extend([bf.as_hidden() for bf in old_form])
    111113                prev_fields.append(hidden.render(hash_name, old_data.get(hash_name, self.security_hash(request, old_form))))
    112114        return self.render_template(request, form, ''.join(prev_fields), step, context)
     
    117119        "Given the step, returns a Form prefix to use."
    118120        return str(step)
    119121
     122    def hash_field_for_step(self, step):
     123        "Given the step, returns the name of the hash field to use"
     124        return 'hash_%s' % str(step)
     125
    120126    def render_hash_failure(self, request, step):
    121127        """
    122128        Hook for rendering a template if a hash check failed.
Back to Top