

_V+                 @   s  d  d l  Z  d  d l Z d  d l 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 m Z m Z d  d	 l m Z m Z m Z e j d
  Z Gd d   d e  Z Gd d   d e j e e   Z Gd d   d e e  Z Gd d   d e  Z Gd d   d e e  Z  Gd d   d e e   Z! Gd d   d e e  Z" Gd d   d e e"  Z# Gd d   d e e  Z$ Gd d   d e e$  Z% Gd d    d  e&  Z' Gd! d"   d" e' e  Z( Gd# d$   d$ e e(  Z) d S)%    N)ImproperlyConfigured)models)HttpResponseRedirect)six)RemovedInDjango110Warning)
force_text)ContextMixinTemplateResponseMixinView)BaseDetailViewSingleObjectMixin!SingleObjectTemplateResponseMixinz%\([^\)]+\)c                   s"   e  Z d  Z   f d d   Z   S)FormMixinBasec                s   | j  d      r t j    r y t j   d   Wq t k
 r t j d | d | f t d d d    f d d  } | | d <Yq Xn  t t	 |   j
 |  | | |  S)Nget_formzR`%s.%s.get_form` method must define a default value for its `form_class` argument.
__module__
stacklevel   c                s+   | d  k r |  j    } n    |  d | S)N
form_class)get_form_class)selfr   )r    ;/tmp/pip-build-ghmbqnp_/Django/django/views/generic/edit.pyget_form_with_form_class    s    z7FormMixinBase.__new__.<locals>.get_form_with_form_class)getinspectZ
isfunctionZgetcallargs	TypeErrorwarningswarnr   superr   __new__)clsnamebasesattrsr   )	__class__)r   r   r      s    zFormMixinBase.__new__)__name__r   __qualname__r   r   r   )r$   r   r      s   r   c                   s   e  Z d  Z d Z i  Z d Z d Z d Z d d   Z d d   Z	 d d   Z
 d d	 d
  Z d d   Z d d   Z d d   Z d d   Z   f d d   Z   S)	FormMixinzM
    A mixin that provides a way to show and handle a form in a request.
    Nc             C   s   |  j  j   S)zI
        Returns the initial data to use for forms on this view.
        )initialcopy)r   r   r   r   get_initial2   s    zFormMixin.get_initialc             C   s   |  j  S)zB
        Returns the prefix to use for forms on this view
        )prefix)r   r   r   r   
get_prefix8   s    zFormMixin.get_prefixc             C   s   |  j  S)z<
        Returns the form class to use in this view
        )r   )r   r   r   r   r   >   s    zFormMixin.get_form_classc             C   s+   | d k r |  j    } n  | |  j     S)zJ
        Returns an instance of the form to be used in this view.
        N)r   get_form_kwargs)r   r   r   r   r   r   D   s    zFormMixin.get_formc             C   s`   i |  j    d 6|  j   d 6} |  j j d k r\ | j i |  j j d 6|  j j d 6 n  | S)zK
        Returns the keyword arguments for instantiating the form.
        r(   r+   POSTPUTdatafiles)zPOSTzPUT)r*   r,   requestmethodupdater.   ZFILES)r   kwargsr   r   r   r-   L   s    	zFormMixin.get_form_kwargsc             C   s+   |  j  r t |  j   } n t d   | S)z3
        Returns the supplied success URL.
        z-No URL to redirect to. Provide a success_url.)success_urlr   r   )r   urlr   r   r   get_success_url\   s
    		zFormMixin.get_success_urlc             C   s   t  |  j    S)zE
        If the form is valid, redirect to the supplied URL.
        )r   r8   )r   formr   r   r   
form_validh   s    zFormMixin.form_validc             C   s   |  j  |  j d |   S)zr
        If the form is invalid, re-render the context data with the
        data-filled form and errors.
        r9   )render_to_responseget_context_data)r   r9   r   r   r   form_invalidn   s    zFormMixin.form_invalidc                s5   d | k r |  j    | d <n  t t |   j |   S)z8
        Insert the form into the context dict.
        r9   )r   r   r'   r<   )r   r5   )r$   r   r   r<   u   s    zFormMixin.get_context_data)r%   r   r&   __doc__r(   r   r6   r+   r*   r,   r   r   r-   r8   r:   r=   r<   r   r   )r$   r   r'   (   s   r'   c                   sX   e  Z d  Z d Z d Z d d   Z   f d d   Z d d   Z   f d	 d
   Z   S)ModelFormMixinzR
    A mixin that provides a way to show and handle a modelform in a request.
    Nc             C   s   |  j  d k	 r' |  j r' t d   n  |  j r7 |  j S|  j d k	 rR |  j } n< t |  d  r |  j d k	 r |  j j } n |  j   j } |  j  d k r t d |  j j   n  t	 j
 | d |  j  Sd S)z=
        Returns the form class to use in this view.
        Nz;Specifying both 'fields' and 'form_class' is not permitted.objectzUUsing ModelFormMixin (base class of %s) without the 'fields' attribute is prohibited.fields)rA   r   r   modelhasattrr@   r$   Zget_querysetr%   model_formsZmodelform_factory)r   rB   r   r   r   r      s    	zModelFormMixin.get_form_classc                sB   t  t |   j   } t |  d  r> | j i |  j d 6 n  | S)zK
        Returns the keyword arguments for instantiating the form.
        r@   instance)r   r?   r-   rC   r4   r@   )r   r5   )r$   r   r   r-      s    zModelFormMixin.get_form_kwargsc             C   s   |  j  rt t |  j   |  _  t j |  j   rY t j d t d d |  j  |  j j } q |  j  j	 |  j j   } n4 y |  j j
   } Wn t k
 r t d   Yn X| S)z+
        Returns the supplied URL.
        zh%()s placeholder style in success_url is deprecated. Please replace them by the {} Python format syntax.r   r   z^No URL to redirect to.  Either provide a url or define a get_absolute_url method on the Model.)r6   r   PERCENT_PLACEHOLDER_REGEXsearchr   r   r   r@   __dict__formatZget_absolute_urlAttributeErrorr   )r   r7   r   r   r   r8      s    	zModelFormMixin.get_success_urlc                s%   | j    |  _ t t |   j |  S)zB
        If the form is valid, save the associated model.
        )saver@   r   r?   r:   )r   r9   )r$   r   r   r:      s    zModelFormMixin.form_valid)	r%   r   r&   r>   rA   r   r-   r8   r:   r   r   )r$   r   r?   ~   s   	r?   c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	ProcessFormViewzF
    A mixin that renders a form on GET and processes it on POST.
    c             O   s   |  j  |  j    S)zT
        Handles GET requests and instantiates a blank version of the form.
        )r;   r<   )r   r2   argsr5   r   r   r   r      s    zProcessFormView.getc             O   s6   |  j    } | j   r% |  j |  S|  j |  Sd S)z
        Handles POST requests, instantiating a form instance with the passed
        POST variables and then checked for validity.
        N)r   Zis_validr:   r=   )r   r2   rM   r5   r9   r   r   r   post   s    zProcessFormView.postc             O   s   |  j  | |   S)N)rN   )r   rM   r5   r   r   r   put   s    zProcessFormView.putN)r%   r   r&   r>   r   rN   rO   r   r   r   r   rL      s   rL   c               @   s   e  Z d  Z d Z d S)BaseFormViewz+
    A base view for displaying a form
    N)r%   r   r&   r>   r   r   r   r   rP      s   rP   c               @   s   e  Z d  Z d Z d S)FormViewzJ
    A view for displaying a form, and rendering a template response.
    N)r%   r   r&   r>   r   r   r   r   rQ      s   rQ   c                   s:   e  Z d  Z d Z   f d d   Z   f d d   Z   S)BaseCreateViewz
    Base view for creating an new object instance.

    Using this base class requires subclassing to provide a response mixin.
    c                s%   d  |  _  t t |   j | | |  S)N)r@   r   rR   r   )r   r2   rM   r5   )r$   r   r   r      s    	zBaseCreateView.getc                s%   d  |  _  t t |   j | | |  S)N)r@   r   rR   rN   )r   r2   rM   r5   )r$   r   r   rN      s    	zBaseCreateView.post)r%   r   r&   r>   r   rN   r   r   )r$   r   rR      s   rR   c               @   s   e  Z d  Z d Z d Z d S)
CreateViewz\
    View for creating a new object instance,
    with a response rendered by template.
    _formN)r%   r   r&   r>   template_name_suffixr   r   r   r   rS     s   rS   c                   s:   e  Z d  Z d Z   f d d   Z   f d d   Z   S)BaseUpdateViewz
    Base view for updating an existing object.

    Using this base class requires subclassing to provide a response mixin.
    c                s+   |  j    |  _ t t |   j | | |  S)N)
get_objectr@   r   rV   r   )r   r2   rM   r5   )r$   r   r   r     s    zBaseUpdateView.getc                s+   |  j    |  _ t t |   j | | |  S)N)rW   r@   r   rV   rN   )r   r2   rM   r5   )r$   r   r   rN     s    zBaseUpdateView.post)r%   r   r&   r>   r   rN   r   r   )r$   r   rV     s   rV   c               @   s   e  Z d  Z d Z d Z d S)
UpdateViewzP
    View for updating an object,
    with a response rendered by template.
    rT   N)r%   r   r&   r>   rU   r   r   r   r   rX     s   rX   c               @   s@   e  Z d  Z d Z d Z d d   Z d d   Z d d   Z d S)	DeletionMixinz9
    A mixin providing the ability to delete objects
    Nc             O   s2   |  j    |  _ |  j   } |  j j   t |  S)zp
        Calls the delete() method on the fetched object and then
        redirects to the success URL.
        )rW   r@   r8   deleter   )r   r2   rM   r5   r6   r   r   r   rZ   (  s    zDeletionMixin.deletec             O   s   |  j  | | |  S)N)rZ   )r   r2   rM   r5   r   r   r   rN   3  s    zDeletionMixin.postc             C   s}   |  j  rm t |  j   |  _  t j |  j   rT t j d t d d |  j  |  j j S|  j  j	 |  j j   Sn t
 d   d  S)Nzh%()s placeholder style in success_url is deprecated. Please replace them by the {} Python format syntax.r   r   z-No URL to redirect to. Provide a success_url.)r6   r   rF   rG   r   r   r   r@   rH   rI   r   )r   r   r   r   r8   6  s    	zDeletionMixin.get_success_url)r%   r   r&   r>   r6   rZ   rN   r8   r   r   r   r   rY   "  s
   rY   c               @   s   e  Z d  Z d Z d S)BaseDeleteViewzx
    Base view for deleting an object.

    Using this base class requires subclassing to provide a response mixin.
    N)r%   r   r&   r>   r   r   r   r   r[   H  s   r[   c               @   s   e  Z d  Z d Z d Z d S)
DeleteViewzs
    View for deleting an object retrieved with `self.get_object()`,
    with a response rendered by template.
    Z_confirm_deleteN)r%   r   r&   r>   rU   r   r   r   r   r\   P  s   r\   )*r   rer   Zdjango.core.exceptionsr   Zdjango.formsr   rD   Zdjango.httpr   Zdjango.utilsr   Zdjango.utils.deprecationr   Zdjango.utils.encodingr   Zdjango.views.generic.baser   r	   r
   Zdjango.views.generic.detailr   r   r   compilerF   typer   with_metaclassr'   r?   rL   rP   rQ   rR   rS   rV   rX   r@   rY   r[   r\   r   r   r   r   <module>   s0   "VO&