
    k"g#                     v   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  G d de	      Z G d	 d
ee      Z G d de      Z G d dee      Z G d de
e      Z G d dee      Z G d dee      Z G d dee      Z G d dee      Z G d d      Z G d deee      Z G d dee      Zy)     )ImproperlyConfigured)Form)models)HttpResponseRedirect)ContextMixinTemplateResponseMixinView)BaseDetailViewSingleObjectMixin!SingleObjectTemplateResponseMixinc                   d     e Zd ZdZi ZdZdZdZd Zd Z	d Z
ddZd Zd Zd	 Zd
 Z fdZ xZS )	FormMixinz5Provide a way to show and handle a form in a request.Nc                 6    | j                   j                         S )z6Return the initial data to use for forms on this view.)initialcopyselfs    R/var/www/html/djangosite/lib/python3.12/site-packages/django/views/generic/edit.pyget_initialzFormMixin.get_initial   s    ||  ""    c                     | j                   S )z#Return the prefix to use for forms.)prefixr   s    r   
get_prefixzFormMixin.get_prefix   s    {{r   c                     | j                   S )zReturn the form class to use.)
form_classr   s    r   get_form_classzFormMixin.get_form_class   s    r   c                 R    || j                         } |di | j                         S )z7Return an instance of the form to be used in this view. )r   get_form_kwargs)r   r   s     r   get_formzFormMixin.get_form!   s-    ,,.J3D00233r   c                     | j                         | j                         d}| j                  j                  dv r<|j	                  | j                  j
                  | j                  j                  d       |S )8Return the keyword arguments for instantiating the form.)r   r   )POSTPUT)datafiles)r   r   requestmethodupdater#   FILES)r   kwargss     r   r   zFormMixin.get_form_kwargs'   sg     '')oo'

 <</1MM LL--!\\// r   c                 Z    | j                   st        d      t        | j                         S )<Return the URL to redirect to after processing a valid form.-No URL to redirect to. Provide a success_url.)success_urlr   strr   s    r   get_success_urlzFormMixin.get_success_url7   s(    &'VWW4##$$r   c                 4    t        | j                               S )z3If the form is valid, redirect to the supplied URL.)r   r1   r   forms     r   
form_validzFormMixin.form_valid=   s    #D$8$8$:;;r   c                 D    | j                  | j                  |            S )z0If the form is invalid, render the invalid form.)r4   render_to_responseget_context_datar3   s     r   form_invalidzFormMixin.form_invalidA   s!    &&t'<'<$'<'GHHr   c                 P    d|vr| j                         |d<   t        |   di |S )z&Insert the form into the context dict.r4   r   )r    superr9   r   r+   	__class__s     r   r9   zFormMixin.get_context_dataE   s-    !]]_F6Nw'1&11r   N)__name__
__module____qualname____doc__r   r   r/   r   r   r   r   r    r   r1   r5   r:   r9   __classcell__r>   s   @r   r   r      sM    ?GJKF#4 %<I2 2r   r   c                   <     e Zd ZdZdZd Z fdZd Z fdZ xZ	S )ModelFormMixinz:Provide a way to show and handle a ModelForm in a request.Nc                    | j                   | j                  rt        d      | j                  r| j                  S | j                  | j                  }n>t	        | dd      | j
                  j                  }n| j                         j                  }| j                   "t        d| j                  j                  z        t        j                  || j                         S )z*Return 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)rJ   r   r   modelgetattrrI   r>   get_querysetr@   model_formsmodelform_factory)r   rK   s     r   r   zModelFormMixin.get_form_classQ   s    ;;"t&M  ????"zz%

x.: -- ))+11{{"*<>Bnn>U>UV 
 00t{{KKr   c                 v    t         |          }t        | d      r|j                  d| j                  i       |S )r"   rI   instance)r<   r   hasattrr)   rI   r=   s     r   r   zModelFormMixin.get_form_kwargsn   s4    (*4"MM:t{{34r   c                     | j                   r2 | j                   j                  di | j                  j                  }|S 	 | j                  j	                         }|S # t
        $ r t        d      w xY w)r-   z^No URL to redirect to.  Either provide a url or define a get_absolute_url method on the Model.r   )r/   formatrI   __dict__get_absolute_urlAttributeErrorr   )r   urls     r   r1   zModelFormMixin.get_success_urlu   sx    )$""))ADKK,@,@AC 
kk224 
 " *? s    A A1c                 L    |j                         | _        t        |   |      S )z0If the form is valid, save the associated model.)saverI   r<   r5   )r   r4   r>   s     r   r5   zModelFormMixin.form_valid   s     iikw!$''r   )
r@   rA   rB   rC   rJ   r   r   r1   r5   rD   rE   s   @r   rG   rG   L   s%    DFL:( (r   rG   c                   "    e Zd ZdZd Zd Zd Zy)ProcessFormViewz.Render a form on GET and processes it on POST.c                 @    | j                  | j                               S )z=Handle GET requests: instantiate a blank version of the form.r7   r   r'   argsr+   s       r   getzProcessFormView.get   s    &&t'<'<'>??r   c                     | j                         }|j                         r| j                  |      S | j                  |      S )z
        Handle POST requests: instantiate a form instance with the passed
        POST variables and then check if it's valid.
        )r    is_validr5   r:   r   r'   r_   r+   r4   s        r   postzProcessFormView.post   s8    
 }}==???4(($$T**r   c                 &     | j                   |i |S r?   )rd   )r   r_   r+   s      r   putzProcessFormView.put   s    tyy$)&))r   N)r@   rA   rB   rC   r`   rd   rf   r   r   r   r\   r\      s    8@	+*r   r\   c                       e Zd ZdZy)BaseFormViewz"A base view for displaying a form.Nr@   rA   rB   rC   r   r   r   rh   rh      s    ,r   rh   c                       e Zd ZdZy)FormViewz?A view for displaying a form and rendering a template response.Nri   r   r   r   rk   rk      s    Ir   rk   c                   ,     e Zd ZdZ fdZ fdZ xZS )BaseCreateViewz
    Base view for creating a new object instance.

    Using this base class requires subclassing to provide a response mixin.
    c                 8    d | _         t        |   |g|i |S r?   )rI   r<   r`   r   r'   r_   r+   r>   s       r   r`   zBaseCreateView.get   s#    w{74T4V44r   c                 8    d | _         t        |   |g|i |S r?   )rI   r<   rd   ro   s       r   rd   zBaseCreateView.post   s#    w|G5d5f55r   r@   rA   rB   rC   r`   rd   rD   rE   s   @r   rm   rm          56 6r   rm   c                       e Zd ZdZdZy)
CreateViewzQ
    View for creating a new object, with a response rendered by a template.
    _formNr@   rA   rB   rC   template_name_suffixr   r   r   rt   rt      s     #r   rt   c                   ,     e Zd ZdZ fdZ fdZ xZS )BaseUpdateViewz
    Base view for updating an existing object.

    Using this base class requires subclassing to provide a response mixin.
    c                 T    | j                         | _        t        |   |g|i |S r?   )
get_objectrI   r<   r`   ro   s       r   r`   zBaseUpdateView.get   s*    oo'w{74T4V44r   c                 T    | j                         | _        t        |   |g|i |S r?   )r{   rI   r<   rd   ro   s       r   rd   zBaseUpdateView.post   s*    oo'w|G5d5f55r   rq   rE   s   @r   ry   ry      rr   r   ry   c                       e Zd ZdZdZy)
UpdateViewzDView for updating an object, with a response rendered by a template.ru   Nrv   r   r   r   r~   r~      s    N"r   r~   c                   &    e Zd ZdZdZd Zd Zd Zy)DeletionMixinz&Provide the ability to delete objects.Nc                     | j                         | _        | j                         }| j                  j                          t	        |      S )zn
        Call the delete() method on the fetched object and then redirect to the
        success URL.
        )r{   rI   r1   deleter   )r   r'   r_   r+   r/   s        r   r   zDeletionMixin.delete   s;    
 oo'**,#K00r   c                 .     | j                   |g|i |S r?   )r   r^   s       r   rd   zDeletionMixin.post   s    t{{74T4V44r   c                     | j                   r0 | j                   j                  di | j                  j                  S t	        d      )Nr.   r   )r/   rT   rI   rU   r   r   s    r   r1   zDeletionMixin.get_success_url   s=    *4##**BT[[-A-ABB&'VWWr   )r@   rA   rB   rC   r/   r   rd   r1   r   r   r   r   r      s    0K15Xr   r   c                        e Zd ZdZeZd Zd Zy)BaseDeleteViewzx
    Base view for deleting an object.

    Using this base class requires subclassing to provide a response mixin.
    c                     | j                         | _        | j                         }|j                         r| j	                  |      S | j                  |      S r?   )r{   rI   r    rb   r5   r:   rc   s        r   rd   zBaseDeleteView.post   sF    
 oo'}}==???4(($$T**r   c                 l    | j                         }| j                  j                          t        |      S r?   )r1   rI   r   r   )r   r4   r/   s      r   r5   zBaseDeleteView.form_valid  s+    **,#K00r   N)r@   rA   rB   rC   r   r   rd   r5   r   r   r   r   r      s     J
+1r   r   c                       e Zd ZdZdZy)
DeleteViewzs
    View for deleting an object retrieved with self.get_object(), with a
    response rendered by a template.
    _confirm_deleteNrv   r   r   r   r   r     s    
 -r   r   N)django.core.exceptionsr   django.formsr   r   rN   django.httpr   django.views.generic.baser   r   r	   django.views.generic.detailr
   r   r   r   rG   r\   rh   rk   rm   rt   ry   r~   r   r   r   r   r   r   <module>r      s    7  . , O O <2 <2~:(Y 1 :(z*d *0-9o -J$l J6^_ 6 #2N #6^_ 6 #2N #X X41]I~ 16-2N -r   