ó
ø¢TQc           @   s°   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d	 l m Z d d
 l m Z d e f d „  ƒ  YZ d S(   s²   
FormWizard class -- implements a multi-page form, validating between each
step and storing the form's state as HTML hidden fields so that no state is
stored on the server side.
iÿÿÿÿ(   t   HiddenInput(   t   Http404(   t   render_to_response(   t   RequestContext(   t   constant_time_compare(   t   ugettext_lazy(   t   method_decorator(   t   csrf_protect(   t	   form_hmact
   FormWizardc           B   s¿   e  Z d  Z d d „ Z d „  Z d d „ Z d „  Z d „  Z e	 e
 ƒ d „  ƒ Z d d „ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z RS(   t   wizard_stepc         C   sK   | |  _  | p i  |  _ i  |  _ d |  _ d d l } | j d t ƒ d S(   s   
        Start a new wizard with a list of forms.

        form_list should be a list of Form classes (not instances).
        i    iÿÿÿÿNsx   Old-style form wizards have been deprecated; use the class-based views in django.contrib.formtools.wizard.views instead.(   t	   form_listt   initialt   extra_contextt   stept   warningst   warnt   DeprecationWarning(   t   selfR   R   R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyt   __init__   s    
		c         C   s   d |  j  |  j |  j f S(   Ns'   step: %d
form_list: %s
initial_data: %s(   R   R   R   (   R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyt   __repr__,   s    c         C   sZ   | |  j  ƒ  k r% t d | ƒ ‚ n  |  j | | d |  j | ƒ d |  j j | d ƒ ƒS(   s@   Helper method that returns the Form instance for the given step.s   Step %s does not existt   prefixR   N(   t	   num_stepsR   R   t   prefix_for_stepR   t   gett   None(   R   R   t   data(    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyt   get_form/   s    c         C   s   t  |  j ƒ S(   s/   Helper method that returns the number of steps.(   t   lenR   (   R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR   6   s    c         C   s   |  j  | | ƒ } t | | ƒ S(   N(   t   security_hashR   (   R   t   tokent   requestt   formt   expected(    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyt   _check_security_hash=   s    c   
      O   s®  d | k r# |  j  j | d ƒ n  |  j | | | Ž } |  j | | | Ž g  } x  t | ƒ D]’ } |  j | | j ƒ } |  j | j j d | d ƒ | | ƒ s± |  j	 | | ƒ S| j
 ƒ  sÐ |  j | | | ƒ S|  j | | | ƒ | j | ƒ q^ W| j d k r|  j | | j ƒ } n |  j | ƒ } | j
 ƒ  r›|  j | | | ƒ | d }	 |	 |  j ƒ  k r||  j | | | g ƒ S|  j |	 ƒ } |	 |  _ } n  |  j | | | ƒ S(   sk   
        Main method that does all the hard work, conforming to the Django view
        interface.
        R   s   hash_%dt    t   POSTi   (   R   t   updatet   get_current_or_first_stept   parse_paramst   rangeR   R$   R"   R   t   render_hash_failuret   is_validt   render_revalidation_failuret   process_stept   appendt   methodR   t   doneR   t   render(
   R   R   t   argst   kwargst   current_stept   previous_form_listt   it   fR    t	   next_step(    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyt   __call__A   s2    
c      	   C   sÍ   | j  } g  } | r« t ƒ  } xŠ t | ƒ D]y } |  j | | ƒ }	 d | }
 | j g  |	 D] } | j ƒ  ^ qZ ƒ | j | j |
 | j |
 |  j	 | |	 ƒ ƒ ƒ ƒ q+ Wn  |  j
 | | d j | ƒ | | ƒ S(   s9   Renders the given Form object, returning an HttpResponse.s   hash_%sR#   (   R$   R    R(   R   t   extendt	   as_hiddenR-   R0   R   R   t   render_templatet   join(   R   R    R   R   t   contextt   old_datat   prev_fieldst   hiddenR5   t   old_formt	   hash_namet   bf(    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR0      s    		
&8c         C   s
   t  | ƒ S(   s-   Given the step, returns a Form prefix to use.(   t   str(   R   R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR   ‘   s    c         C   s/   |  j  |  j | ƒ | | d i t d ƒ d 6ƒS(   s6  
        Hook for rendering a template if a hash check failed.

        step is the step that failed. Any previous step is guaranteed to be
        valid.

        This default implementation simply renders the form for the given step,
        but subclasses may want to display an error message, etc.
        R=   s]   We apologize, but your form has expired. Please continue filling out the form from this page.t   wizard_error(   R0   R   t   _(   R   R   R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR)   •   s    
c         C   s   |  j  | | | ƒ S(   sÑ   
        Hook for rendering a template if final revalidation failed.

        It is highly unlikely that this point would ever be reached, but See
        the comment in __call__() for an explanation.
        (   R0   (   R   R   R   R    (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR+   ¡   s    c         C   s
   t  | ƒ S(   sÌ   
        Calculates the security hash for the given HttpRequest and Form instances.

        Subclasses may want to take into account request-specific information,
        such as the IP address.
        (   R   (   R   R   R    (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR   ª   s    c         O   sH   | j  s d Sy" t | j  j |  j d ƒ ƒ } Wn t k
 rC d SX| S(   s6  
        Given the request object and whatever *args and **kwargs were passed to
        __call__(), returns the current step (which is zero-based).

        Note that the result should not be trusted. It may even be a completely
        invalid number. It's not the job of this method to validate it.
        i    (   R$   t   intR   t   step_field_namet
   ValueError(   R   R   R1   R2   R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR&   ³   s    	"c         O   s   d S(   sÓ   
        Hook for setting some state, given the request object and whatever
        *args and **kwargs were passed to __call__(), sets some state.

        This is called at the beginning of __call__().
        N(    (   R   R   R1   R2   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR'   Ã   s    c         C   s   d S(   sß   
        Hook for specifying the name of the template to use for a given step.

        Note that this can return a tuple of template names if you'd like to
        use the template system's select_template() hook.
        s   forms/wizard.html(    (   R   R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyt   get_templateÌ   s    c         C   su   | p	 i  } | j  |  j ƒ t |  j | ƒ t | d |  j d | d | d d |  j ƒ  d | d | ƒd t | ƒ ƒS(	   s?  
        Renders the template for the given step, returning an HttpResponse object.

        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 get_template() instead.

        The template will be rendered with the following context:
            step_field -- The name of the hidden field containing the step.
            step0      -- The current step (zero-based).
            step       -- The current step (one-based).
            step_count -- The total number of steps.
            form       -- The Form instance for the current step (either empty
                          or with errors).
            previous_fields -- 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 "safe" template filter, to prevent
                          auto-escaping, because it's raw HTML.
        t
   step_fieldt   step0R   i   t
   step_countR    t   previous_fieldst   context_instance(   R%   R   R   RJ   t   dictRH   R   R   (   R   R   R    RN   R   R=   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR;   Õ   s    	
	c         C   s   d S(   sÛ  
        Hook for modifying the FormWizard's internal state, given a fully
        validated Form object. The Form is guaranteed to have clean, valid
        data.

        This method should *not* modify any of that data. Rather, it might want
        to set self.extra_context or dynamically alter self.form_list, based on
        previously submitted forms.

        Note that this method is called every time a page is rendered for *all*
        submitted steps.
        N(    (   R   R   R    R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR,   õ   s    c         C   s   t  d |  j j ƒ ‚ d S(   sÔ   
        Hook for doing something with the validated data. This is responsible
        for the final processing.

        form_list is a list of Form instances, each containing clean, valid
        data.
        sA   Your %s class has not defined a done() method, which is required.N(   t   NotImplementedErrort	   __class__t   __name__(   R   R   R   (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR/     s    N(   RS   t
   __module__RH   R   R   R   R   R   R"   R   R   R8   R0   R   R)   R+   R   R&   R'   RJ   R;   R,   R/   (    (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyR	      s$   			@											 	N(   t   __doc__t   django.formsR    t   django.httpR   t   django.shortcutsR   t   django.template.contextR   t   django.utils.cryptoR   t   django.utils.translationR   RF   t   django.utils.decoratorsR   t   django.views.decorators.csrfR   t   django.contrib.formtools.utilsR   t   objectR	   (    (    (    s?   ../Django//lib/python/django/contrib/formtools/wizard/legacy.pyt   <module>   s   