o
    uvXj}  ã                   @   s¼   d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ e  d¡ZG d	d
„ d
ƒZG dd„ dƒZG dd„ dƒZG dd„ deeeƒZG dd„ deƒZdS )é    N)Úupdate_wrapper)ÚImproperlyConfigured)ÚHttpResponseÚHttpResponseGoneÚHttpResponseNotAllowedÚHttpResponsePermanentRedirectÚHttpResponseRedirect)ÚTemplateResponse)Úreverse)Úclassonlymethodzdjango.requestc                   @   s   e Zd ZdZdZdd„ ZdS )ÚContextMixinz
    A default context mixin that passes the keyword arguments received by
    get_context_data() as the template context.
    Nc                 K   s&   |  d| ¡ | jd ur| | j¡ |S )NÚview)Ú
setdefaultÚextra_contextÚupdate)ÚselfÚkwargs© r   úV/var/www/html/myproject/venv/lib/python3.10/site-packages/django/views/generic/base.pyÚget_context_data   s   
zContextMixin.get_context_data)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    r   c                   @   sT   e Zd ZdZg d¢Zdd„ Zedd„ ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚViewz}
    Intentionally simple parent class for all views. Only implements
    dispatch-by-method and simple sanity checking.
    )ÚgetÚpostÚputÚpatchÚdeleteÚheadÚoptionsÚtracec                 K   s"   |  ¡ D ]
\}}t| ||ƒ qdS )z|
        Constructor. Called in the URLconf; can contain helpful extra
        keyword arguments, and other things.
        N)ÚitemsÚsetattr)r   r   ÚkeyÚvaluer   r   r   Ú__init__&   s   ÿzView.__init__c                    s~   ˆD ]}|ˆ j v rtd|ˆ jf ƒ‚tˆ |ƒs tdˆ j|f ƒ‚q‡ ‡fdd„}ˆ |_ˆ|_t|ˆ dd� t|ˆ jdd� |S )z0Main entry point for a request-response process.zUYou tried to pass in the %s method name as a keyword argument to %s(). Don't do that.zm%s() received an invalid keyword %r. as_view only accepts arguments that are already attributes of the class.c                    sr   ˆ di ˆ¤Ž}t |dƒrt |dƒs|j|_|j| g|¢R i |¤Ž t |dƒs-tdˆ j ƒ‚|j| g|¢R i |¤ŽS )Nr   r    Úrequestz\%s instance has no 'request' attribute. Did you override setup() and forget to call super()?r   )Úhasattrr   r    ÚsetupÚAttributeErrorr   Údispatch)r(   Úargsr   r   ©ÚclsÚ
initkwargsr   r   r   =   s   
ÿÿzView.as_view.<locals>.viewr   )Úupdated)Úassigned)Úhttp_method_namesÚ	TypeErrorr   r)   Ú
view_classÚview_initkwargsr   r,   )r/   r0   r%   r   r   r.   r   Úas_view0   s    
þ
þÿzView.as_viewc                 O   s   || _ || _|| _dS )z1Initialize attributes shared by all view methods.N)r(   r-   r   ©r   r(   r-   r   r   r   r   r*   S   s   
z
View.setupc                 O   sB   |j  ¡ | jv rt| |j  ¡ | jƒ}n| j}||g|¢R i |¤ŽS ©N)ÚmethodÚlowerr3   ÚgetattrÚhttp_method_not_allowed)r   r(   r-   r   Úhandlerr   r   r   r,   Y   s   zView.dispatchc                 O   s(   t jd|j|jd|dœd� t|  ¡ ƒS )NzMethod Not Allowed (%s): %si•  ©Ústatus_coder(   ©Úextra)ÚloggerÚwarningr:   Úpathr   Ú_allowed_methodsr8   r   r   r   r=   c   s
   
þzView.http_method_not_allowedc                 O   s$   t ƒ }d |  ¡ ¡|d< d|d< |S )z8Handle responding to requests for the OPTIONS HTTP verb.z, ÚAllowÚ0zContent-Length)r   ÚjoinrF   )r   r(   r-   r   Úresponser   r   r   r!   j   s   zView.optionsc                    s   ‡ fdd„ˆ j D ƒS )Nc                    s   g | ]}t ˆ |ƒr| ¡ ‘qS r   )r)   Úupper)Ú.0Úm©r   r   r   Ú
<listcomp>r   s    z)View._allowed_methods.<locals>.<listcomp>)r3   rN   r   rN   r   rF   q   s   zView._allowed_methodsN)r   r   r   r   r3   r'   r   r7   r*   r,   r=   r!   rF   r   r   r   r   r      s    

"
r   c                   @   s0   e Zd ZdZdZdZeZdZdd„ Z	dd„ Z
dS )ÚTemplateResponseMixinz.A mixin that can be used to render a template.Nc                 K   s0   |  d| j¡ | jd| j|  ¡ || jdœ|¤ŽS )zÏ
        Return a response, using the `response_class` for this view, with a
        template rendered with the given context.

        Pass response_kwargs to the constructor of the response class.
        Úcontent_type)r(   ÚtemplateÚcontextÚusingNr   )r   rQ   Úresponse_classr(   Úget_template_namesÚtemplate_engine)r   rS   Úresponse_kwargsr   r   r   Úrender_to_response|   s   üûz(TemplateResponseMixin.render_to_responsec                 C   s   | j du r	tdƒ‚| j gS )z¢
        Return a list of template names to be used for the request. Must return
        a list. May not be called if render_to_response() is overridden.
        NztTemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()')Útemplate_namer   rN   r   r   r   rV   Œ   s
   
ÿz(TemplateResponseMixin.get_template_names)r   r   r   r   rZ   rW   r	   rU   rQ   rY   rV   r   r   r   r   rP   u   s    rP   c                   @   s   e Zd ZdZdd„ ZdS )ÚTemplateViewzT
    Render a template. Pass keyword arguments from the URLconf to the context.
    c                 O   s   | j di |¤Ž}|  |¡S )Nr   )r   rY   )r   r(   r-   r   rS   r   r   r   r   �   s   
zTemplateView.getN)r   r   r   r   r   r   r   r   r   r[   ™   s    r[   c                   @   s`   e Zd ZdZdZdZdZdZdd„ Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚRedirectViewz&Provide a redirect on any GET request.FNc                 O   sX   | j r	| j | }n| jrt| j||d�}ndS | jj dd¡}|r*| jr*d||f }|S )z±
        Return the URL redirect to. Keyword arguments from the URL pattern
        match generating the redirect request are provided as kwargs to this
        method.
        )r-   r   NÚQUERY_STRINGÚ z%s?%s)ÚurlÚpattern_namer
   r(   ÚMETAr   Úquery_string)r   r-   r   r_   r   r   r   Úget_redirect_url©   s   
zRedirectView.get_redirect_urlc                 O   sH   | j |i |¤Ž}|r| jrt|ƒS t|ƒS tjd|jd|dœd� tƒ S )NzGone: %siš  r?   rA   )rc   Ú	permanentr   r   rC   rD   rE   r   )r   r(   r-   r   r_   r   r   r   r   »   s   þzRedirectView.getc                 O   ó   | j |g|¢R i |¤ŽS r9   ©r   r8   r   r   r   r    É   ó   zRedirectView.headc                 O   re   r9   rf   r8   r   r   r   r   Ì   rg   zRedirectView.postc                 O   re   r9   rf   r8   r   r   r   r!   Ï   rg   zRedirectView.optionsc                 O   re   r9   rf   r8   r   r   r   r   Ò   rg   zRedirectView.deletec                 O   re   r9   rf   r8   r   r   r   r   Õ   rg   zRedirectView.putc                 O   re   r9   rf   r8   r   r   r   r   Ø   rg   zRedirectView.patch)r   r   r   r   rd   r_   r`   rb   rc   r   r    r   r!   r   r   r   r   r   r   r   r\   ¢   s    r\   )ÚloggingÚ	functoolsr   Údjango.core.exceptionsr   Údjango.httpr   r   r   r   r   Údjango.template.responser	   Údjango.urlsr
   Údjango.utils.decoratorsr   Ú	getLoggerrC   r   r   rP   r[   r\   r   r   r   r   Ú<module>   s    
W$	