o
    Mf                      @   s   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ZG dd deeZdS )    )ImproperlyConfigured)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   [/var/www/html/analyze/labelStudio/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_url1   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_valid7   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_invalid;   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   superr0   r$   	__class__r   r   r0   ?   s   zFormMixin.get_context_dataN)__name__
__module____qualname____doc__r   r   r(   r   r   r   r   r   r   r*   r-   r1   r0   __classcell__r   r   r3   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<   r4   get_querysetr6   model_formsmodelform_factory)r   r>   r   r   r   r   J   s$   



zModelFormMixin.get_form_classc                    s(   t   }t| dr|d| ji |S )r   r<   instance)r2   r   hasattrr"   r<   r$   r3   r   r   r   g   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*   n   s   zModelFormMixin.get_success_urlc                    s   |  | _t |S )z0If the form is valid, save the associated model.)saver<   r2   r-   r+   r3   r   r   r-   {   s   
zModelFormMixin.form_valid)
r6   r7   r8   r9   r=   r   r   r*   r-   r:   r   r   r3   r   r;   F   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-   r1   )r   r    rM   r%   r,   r   r   r   post   s   

zProcessFormView.postc                 O   s   | j |i |S r5   )rP   )r   rM   r%   r   r   r   put   s   zProcessFormView.putN)r6   r7   r8   r9   rN   rP   rQ   r   r   r   r   rK      s
    rK   c                   @      e Zd ZdZdS )BaseFormViewz"A base view for displaying a form.Nr6   r7   r8   r9   r   r   r   r   rS          rS   c                   @   rR   )FormViewz?A view for displaying a form and rendering a template response.NrT   r   r   r   r   rV      rU   rV   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 r5   )r<   r2   rN   rL   r3   r   r   rN         zBaseCreateView.getc                    rY   r5   )r<   r2   rP   rL   r3   r   r   rP      rZ   zBaseCreateView.postr6   r7   r8   r9   rN   rP   r:   r   r   r3   r   rX          rX   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r6   r7   r8   r9   template_name_suffixr   r   r   r   r^      s    r^   c                       rW   )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 r5   )
get_objectr<   r2   rN   rL   r3   r   r   rN         
zBaseUpdateView.getc                    rc   r5   )rd   r<   r2   rP   rL   r3   r   r   rP      re   zBaseUpdateView.postr[   r   r   r3   r   rb      r\   rb   c                   @   r]   )
UpdateViewzDView for updating an object, with a response rendered by a template.r_   Nr`   r   r   r   r   rf      s    rf   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.
        )rd   r<   r*   deleter   )r   r    rM   r%   r(   r   r   r   rh      s   

zDeletionMixin.deletec                 O   s   | j |g|R i |S r5   )rh   rL   r   r   r   rP      s   zDeletionMixin.postc                 C   s$   | j r| j jdi | jjS td)Nr'   r   )r(   rE   r<   rF   r   r   r   r   r   r*      s
   zDeletionMixin.get_success_url)r6   r7   r8   r9   r(   rh   rP   r*   r   r   r   r   rg      s    rg   c                   @   rR   )BaseDeleteViewzx
    Base view for deleting an object.

    Using this base class requires subclassing to provide a response mixin.
    NrT   r   r   r   r   ri      rU   ri   c                   @   r]   )
DeleteViewzs
    View for deleting an object retrieved with self.get_object(), with a
    response rendered by a template.
    _confirm_deleteNr`   r   r   r   r   rj      s    rj   N)django.core.exceptionsr   django.formsr   rA   django.httpr   django.views.generic.baser   r   r   django.views.generic.detailr   r	   r
   r   r;   rK   rS   rV   rX   r^   rb   rf   rg   ri   rj   r   r   r   r   <module>   s"    <;