
    h                      h   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      Z G d dee      Zy)    )ImproperlyConfigured)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    \/var/www/html/ranktracker/api/venv/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))++  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_url1   s(    &'VWW4##$$r   c                 4    t        | j                               S )z3If the form is valid, redirect to the supplied URL.)r   r0   r   forms     r   
form_validzFormMixin.form_valid7   s    #D$8$8$:;;r   c                 D    | j                  | j                  |            S )z0If the form is invalid, render the invalid form.)r3   render_to_responseget_context_datar2   s     r   form_invalidzFormMixin.form_invalid;   s!    &&t'<'<$'<'GHHr   c                 P    d|vr| j                         |d<   t        |   di |S )z&Insert the form into the context dict.r3   r   )r   superr8   r   r*   	__class__s     r   r8   zFormMixin.get_context_data?   s-    !]]_F6Nw'1&11r   N)__name__
__module____qualname____doc__r   r   r.   r   r   r   r   r   r   r0   r4   r9   r8   __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)rI   r   r   modelgetattrrH   r=   get_querysetr?   model_formsmodelform_factory)r   rJ   s     r   r   zModelFormMixin.get_form_classJ   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!   rH   instance)r;   r   hasattrr(   rH   r<   s     r   r   zModelFormMixin.get_form_kwargsg   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.   formatrH   __dict__get_absolute_urlAttributeErrorr   )r   urls     r   r0   zModelFormMixin.get_success_urln   s}    )$""))ADKK,@,@AC 
@kk224
 
	 " @*?@ @@s    A A1c                 L    |j                         | _        t        |   |      S )z0If the form is valid, save the associated model.)saverH   r;   r4   )r   r3   r=   s     r   r4   zModelFormMixin.form_valid{   s     iikw!$''r   )
r?   r@   rA   rB   rI   r   r   r0   r4   rC   rD   s   @r   rF   rF   F   s%    DFL:( (r   rF   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.r6   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_validr4   r9   )r   r&   r^   r*   r3   s        r   postzProcessFormView.post   s8    
 }}==???4(($$T**r   c                 &     | j                   |i |S r>   )rb   )r   r^   r*   s      r   putzProcessFormView.put   s    tyy$)&))r   N)r?   r@   rA   rB   r_   rb   rd   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?   r@   rA   rB   r   r   r   rf   rf      s    ,r   rf   c                       e Zd ZdZy)FormViewz?A view for displaying a form and rendering a template response.Nrg   r   r   r   ri   ri      s    Ir   ri   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>   )rH   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>   )rH   r;   rb   rm   s       r   rb   zBaseCreateView.post   s#    w|G5d5f55r   r?   r@   rA   rB   r_   rb   rC   rD   s   @r   rk   rk          
56 6r   rk   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?   r@   rA   rB   template_name_suffixr   r   r   rr   rr      s     #r   rr   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_objectrH   r;   r_   rm   s       r   r_   zBaseUpdateView.get   s*    oo'w{74T4V44r   c                 T    | j                         | _        t        |   |g|i |S r>   )ry   rH   r;   rb   rm   s       r   rb   zBaseUpdateView.post   s*    oo'w|G5d5f55r   ro   rD   s   @r   rw   rw      rp   r   rw   c                       e Zd ZdZdZy)
UpdateViewzDView for updating an object, with a response rendered by a template.rs   Nrt   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.
        )ry   rH   r0   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   rb   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.   rS   rH   rT   r   r   s    r   r0   zDeletionMixin.get_success_url   sC    *4##**BT[[-A-ABB&?A Ar   )r?   r@   rA   rB   r.   r   rb   r0   r   r   r   r~   r~      s    0K15Ar   r~   c                       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.
    Nrg   r   r   r   r   r      s    r   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_deleteNrt   r   r   r   r   r      s     -r   r   N)django.core.exceptionsr   django.formsr   rM   django.httpr   django.views.generic.baser   r   r   django.views.generic.detailr	   r
   r   r   rF   r[   rf   ri   rk   rr   rw   r|   r~   r   r   r   r   r   <module>r      s    7 . , O O 
92 92x8(Y 1 8(v*d *.-9o -J$l J6^_ 6#2N #6^_ 6#2N #
A A4]N -2N -r   