o
    ;Wf#                     @   s.  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 de	ZG d	d
 d
eeZG dd deZG dd deeZG dd de
eZG dd deeZG dd deeZG dd deeZG dd deeZG dd dZG dd deeeZG dd deeZdS )     )ImproperlyConfigured)Form)models)HttpResponseRedirect)ContextMixinTemplateResponseMixinView)BaseDetailViewSingleObjectMixin!SingleObjectTemplateResponseMixinc                       sr   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  ZS )	FormMixinz5Provide a way to show and handle a form in a request.Nc                 C   s
   | j  S )z6Return the initial data to use for forms on this view.)initialcopyself r   /media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_CUSTOMER_APIS/venv/lib/python3.10/site-packages/django/views/generic/edit.pyget_initial   s   
zFormMixin.get_initialc                 C      | j S )z#Return the prefix to use for forms.)prefixr   r   r   r   
get_prefix      zFormMixin.get_prefixc                 C   r   )zReturn the form class to use.)
form_classr   r   r   r   get_form_class   r   zFormMixin.get_form_classc                 C   s"   |du r|   }|di |  S )z7Return an instance of the form to be used in this view.Nr   )r   get_form_kwargs)r   r   r   r   r   get_form!   s   zFormMixin.get_formc                 C   s:   |   |  d}| jjdv r|| 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   kwargsr   r   r   r   '   s   zFormMixin.get_form_kwargsc                 C   s   | 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   r   r   r   get_success_url7   s   
zFormMixin.get_success_urlc                 C   s   t |  S )z3If the form is valid, redirect to the supplied URL.)r   r+   r   formr   r   r   
form_valid=   s   zFormMixin.form_validc                 C   s   |  | j|dS )z0If the form is invalid, render the invalid form.)r-   render_to_responseget_context_datar,   r   r   r   form_invalidA   s   zFormMixin.form_invalidc                    s&   d|vr
|   |d< t jdi |S )z&Insert the form into the context dict.r-   Nr   )r   superr1   r%   	__class__r   r   r1   E   s   zFormMixin.get_context_dataN)__name__
__module____qualname____doc__r   r   r)   r   r   r   r   r   r   r+   r.   r2   r1   __classcell__r   r   r4   r   r      s    
r   c                       s@   e Zd ZdZdZdd Z fddZdd Z fd	d
Z  Z	S )ModelFormMixinz:Provide a way to show and handle a ModelForm in a request.Nc                 C   s   | j dur| jrtd| jr| jS | jdur| j}nt| dddur(| jj}n|  j}| j du r:td| jj t	j
|| j d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)r>   r   r   modelgetattrr=   r5   get_querysetr7   model_formsmodelform_factory)r   r?   r   r   r   r   Q   s$   



zModelFormMixin.get_form_classc                    s(   t   }t| dr|d| ji |S )r   r=   instance)r3   r   hasattrr#   r=   r%   r4   r   r   r   n   s   

zModelFormMixin.get_form_kwargsc                 C   sH   | j r| j jdi | jj}|S z| j }W |S  ty#   tdw )r'   z^No URL to redirect to.  Either provide a url or define a get_absolute_url method on the Model.Nr   )r)   formatr=   __dict__get_absolute_urlAttributeErrorr   )r   urlr   r   r   r+   u   s   	zModelFormMixin.get_success_urlc                    s   |  | _t |S )z0If the form is valid, save the associated model.)saver=   r3   r.   r,   r4   r   r   r.      s   
zModelFormMixin.form_valid)
r7   r8   r9   r:   r>   r   r   r+   r.   r;   r   r   r4   r   r<   L   s    r<   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ProcessFormViewz.Render a form on GET and processes it on POST.c                 O   s   |  |  S )z=Handle GET requests: instantiate a blank version of the form.r/   r   r!   argsr&   r   r   r   get   s   zProcessFormView.getc                 O   s$   |   }| r| |S | |S )z
        Handle POST requests: instantiate a form instance with the passed
        POST variables and then check if it's valid.
        )r   is_validr.   r2   r   r!   rN   r&   r-   r   r   r   post   s   

zProcessFormView.postc                 O   s   | j |i |S r6   )rR   )r   rN   r&   r   r   r   put   s   zProcessFormView.putN)r7   r8   r9   r:   rO   rR   rS   r   r   r   r   rL      s
    rL   c                   @      e Zd ZdZdS )BaseFormViewz"A base view for displaying a form.Nr7   r8   r9   r:   r   r   r   r   rU          rU   c                   @   rT   )FormViewz?A view for displaying a form and rendering a template response.NrV   r   r   r   r   rX      rW   rX   c                       ,   e Zd ZdZ fddZ fddZ  ZS )BaseCreateViewz
    Base view for creating a new object instance.

    Using this base class requires subclassing to provide a response mixin.
    c                        d | _ t j|g|R i |S r6   )r=   r3   rO   rM   r4   r   r   rO         zBaseCreateView.getc                    r[   r6   )r=   r3   rR   rM   r4   r   r   rR      r\   zBaseCreateView.postr7   r8   r9   r:   rO   rR   r;   r   r   r4   r   rZ          rZ   c                   @      e Zd ZdZdZdS )
CreateViewzQ
    View for creating a new object, with a response rendered by a template.
    _formNr7   r8   r9   r:   template_name_suffixr   r   r   r   r`      s    r`   c                       rY   )BaseUpdateViewz
    Base view for updating an existing object.

    Using this base class requires subclassing to provide a response mixin.
    c                    $   |   | _t j|g|R i |S r6   )
get_objectr=   r3   rO   rM   r4   r   r   rO         
zBaseUpdateView.getc                    re   r6   )rf   r=   r3   rR   rM   r4   r   r   rR      rg   zBaseUpdateView.postr]   r   r   r4   r   rd      r^   rd   c                   @   r_   )
UpdateViewzDView for updating an object, with a response rendered by a template.ra   Nrb   r   r   r   r   rh      s    rh   c                   @   s,   e Zd ZdZdZdd Zdd Zdd ZdS )	DeletionMixinz&Provide the ability to delete objects.Nc                 O   s$   |   | _|  }| j  t|S )zn
        Call the delete() method on the fetched object and then redirect to the
        success URL.
        )rf   r=   r+   deleter   )r   r!   rN   r&   r)   r   r   r   rj      s   

zDeletionMixin.deletec                 O   s   | j |g|R i |S r6   )rj   rM   r   r   r   rR      s   zDeletionMixin.postc                 C   s$   | j r| j jdi | jjS td)Nr(   r   )r)   rF   r=   rG   r   r   r   r   r   r+      s   zDeletionMixin.get_success_url)r7   r8   r9   r:   r)   rj   rR   r+   r   r   r   r   ri      s    ri   c                   @   s$   e Zd ZdZeZdd Zdd ZdS )BaseDeleteViewzx
    Base view for deleting an object.

    Using this base class requires subclassing to provide a response mixin.
    c                 O   s.   |   | _|  }| r| |S | |S r6   )rf   r=   r   rP   r.   r2   rQ   r   r   r   rR      s
   


zBaseDeleteView.postc                 C   s   |   }| j  t|S r6   )r+   r=   rj   r   )r   r-   r)   r   r   r   r.     s   
zBaseDeleteView.form_validN)r7   r8   r9   r:   r   r   rR   r.   r   r   r   r   rk      s
    rk   c                   @   r_   )
DeleteViewzs
    View for deleting an object retrieved with self.get_object(), with a
    response rendered by a template.
    _confirm_deleteNrb   r   r   r   r   rl     s    rl   N)django.core.exceptionsr   django.formsr   r   rB   django.httpr   django.views.generic.baser   r   r   django.views.generic.detailr	   r
   r   r   r<   rL   rU   rX   rZ   r`   rd   rh   ri   rk   rl   r   r   r   r   <module>   s$    ?=