ó
:ÏOc           @   sv   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 Z d e f d	 „  ƒ  YZ d
 S(   s    
Formtools Preview application.
iÿÿÿÿ(   t   Http404(   t   render_to_response(   t   RequestContext(   t   constant_time_compare(   t	   form_hmacs   formtools_%st   FormPreviewc           B   s›   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   formtools/preview.htmls   formtools/form.htmlc         C   s   | i  |  _  |  _ d  S(   N(   t   formt   state(   t   selfR   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyt   __init__   s    c         O   s   i d d 6d d 6j  | j j  |  j d ƒ ƒ d ƒ } |  j | | Ž  y$ t |  | d | j j ƒ  ƒ } Wn t k
 r‚ t ‚ n X| | ƒ S(   Nt   previewt   1t   postt   2t   staget   _(	   t   gett   POSTt   unused_namet   parse_paramst   getattrt   methodt   lowert   AttributeErrorR    (   R   t   requestt   argst   kwargsR   R   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyt   __call__   s    5$
c         C   s=   x6 y |  j  j | } Wn t k
 r+ Pn X| d 7} q | S(   s  
        Given a first-choice name, adds an underscore to the name until it
        reaches a name that isn't claimed by any field in the form.

        This is calculated rather than being hard-coded so that no field names
        are off-limits for use in the form.
        R   (   R   t   base_fieldst   KeyError(   R   t   namet   f(    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR       s    c         C   sO   |  j  d |  j ƒ  d |  j | ƒ ƒ } t |  j |  j | | ƒ d t | ƒ ƒS(   s   Displays the formt   auto_idt   initialt   context_instance(   R   t   get_auto_idt   get_initialR   t   form_templatet   get_contextR   (   R   R   R   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyt   preview_get0   s    '	c         C   s´   |  j  | j d |  j ƒ  ƒ} |  j | | ƒ } | j ƒ  r” |  j | | | ƒ |  j d ƒ | d <|  j | | ƒ | d <t |  j	 | d t
 | ƒ ƒSt |  j | d t
 | ƒ ƒSd S(   sT   Validates the POST data. If valid, displays the preview page. Else, redisplays form.R    t   hasht
   hash_fieldt
   hash_valueR"   N(   R   R   R#   R&   t   is_validt   process_previewR   t   security_hashR   t   preview_templateR   R%   (   R   R   R   t   context(    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyt   preview_post7   s    c         C   s   |  j  | | ƒ } t | | ƒ S(   N(   R-   R   (   R   t   tokenR   R   t   expected(    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyt   _check_security_hashC   s    c         C   s£   |  j  | j d |  j ƒ  ƒ} | j ƒ  rw |  j | j j |  j d ƒ d ƒ | | ƒ sd |  j | ƒ S|  j | | j	 ƒ St
 |  j |  j | | ƒ d t | ƒ ƒSd S(   sG   Validates the POST data. If valid, calls done(). Else, redisplays form.R    R(   t    R"   N(   R   R   R#   R+   R3   R   R   t   failed_hasht   donet   cleaned_dataR   R%   R&   R   (   R   R   R   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyt	   post_postG   s    !	c         C   s   t  S(   sŒ   
        Hook to override the ``auto_id`` kwarg for the form. Needed when
        rendering two form previews in the same template.
        (   t   AUTO_ID(   R   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR#   V   s    c         C   s   i  S(   s¤   
        Takes a request argument and returns a dictionary to pass to the form's
        ``initial`` kwarg when the form is being created from an HTTP get.
        (    (   R   R   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR$   ]   s    c         C   s%   i | d 6|  j  d ƒ d 6|  j d 6S(   s   Context for template rendering.R   R   t   stage_fieldR   (   R   R   (   R   R   R   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR&   d   s    c         O   s   d S(   s  
        Given captured args and kwargs from the URLconf, saves something in
        self.state and/or raises Http404 if necessary.

        For example, this URLconf captures a user_id variable:

            (r'^contact/(?P<user_id>\d{1,6})/$', MyFormPreview(MyForm)),

        In this case, the kwargs variable in parse_params would be
        {'user_id': 32} for a request to '/contact/32/'. You can use that
        user_id to make sure it's a valid user and/or save it for later, for
        use in done().
        N(    (   R   R   R   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR   i   s    c         C   s   d S(   s˜   
        Given a validated form, performs any extra processing before displaying
        the preview page, and saves any extra data in context.
        N(    (   R   R   R   R/   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR,   y   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   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR-   €   s    c         C   s   |  j  | ƒ S(   s@   Returns an HttpResponse in the case of an invalid security hash.(   R0   (   R   R   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR5   ‰   s    c         C   s   t  d |  j j ƒ ‚ d S(   sc   
        Does something with the cleaned_data and returns an
        HttpResponseRedirect.
        s4   You must define a done() method on your %s subclass.N(   t   NotImplementedErrort	   __class__t   __name__(   R   R   R7   (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR6      s    (   R=   t
   __module__R.   R%   R	   R   R   R'   R0   R3   R8   R#   R$   R&   R   R,   R-   R5   R6   (    (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyR      s"   																N(   t   __doc__t   django.httpR    t   django.shortcutsR   t   django.template.contextR   t   django.utils.cryptoR   t   django.contrib.formtools.utilsR   R9   t   objectR   (    (    (    s9   ../Django//lib/python/django/contrib/formtools/preview.pyt   <module>   s   