o
    ea                     @   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mZmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZ G dd	 d	eZd
S )    )render_to_response)RequestContext)
simplejson)logout)debuginfosuccesswarningerroradd_message)reverse)HttpResponseHttpResponseForbiddenHttp404HttpResponseNotAllowedHttpResponseRedirectHttpResponsePermanentRedirectHttpResponseNotModifiedHttpResponseBadRequestHttpResponseNotFoundHttpResponseGoneHttpResponseServerErrorc                   @   s,  e Zd ZdZg ZdZdZg ZdZdZ	dZ
dZ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>ddZd>ddZdd Z		d?ddZdd Z		d?dd Zd>d!d"Zd>d#d$Zd>d%d&Zd>d'd(Zd>d)d*Zd+d, Zd-d. Z d@d0d1Z!d2d3 Z"d4d5 Z#d6d7 Z$d8d9 Z%d:d; Z&d<d= Z'dS )ABaseViewa  
    A base class to create class based views.
    
    It will automatically check allowed methods if a list of allowed methods are
    given. It also automatically tries to route to 'handle_`method`' methods if
    they're available. So if for example you define a 'handle_post' method and
    the request method is 'POST', this one will be called instead of 'handle'.
    
    For each request a new instance of this class will be created and it will get
    three attributes set: request, args and kwargs.
    z	base.htmlF	not_foundNc                 O   s   || _ || _d S N)_initial_args_initial_kwargs)selfargskwargs r    >/var/www/html/venv/lib/python3.10/site-packages/utils/views.py__init__2   s   
zBaseView.__init__c                 C   s   |   S )z.
        INTERNAL: required by django
        )get_view_namer   r    r    r!   __name__7   s   zBaseView.__name__c                 O   s   | j r|j| j vrt| | j S | jr|j st| | j S | jr-|jjs-t| | j S | j	r>|j
| j	s>t| | j S d|j  }t| |sLd}| j| ji | j}||_t|||i |S )z
        INTERNAL: Called by django when a request should be handled by this view.
        Creates a new instance of this class to sandbox 
        z	handle_%shandle)allowed_methodsmethodgetattrauto_decline_responselogin_requireduseris_authenticatedsuperuser_requiredis_superuserrequired_permissions	has_permslowerhasattr	__class__r   r   request)r   r5   r   r   handle_func_namesandboxr    r    r!   __call__>   s   
zBaseView.__call__c                 C   s   | j jS )z/
        Returns the name of this view
        )r4   r%   r$   r    r    r!   r#   Z   s   zBaseView.get_view_namec                 C   s   | j S r   )templater$   r    r    r!   get_template`   s   zBaseView.get_templatec                 C   s   t | j d S r   )r   r5   r$   r    r    r!   r   c   s   zBaseView.logoutc                 C   s   dS )z,
        Write your view logic here
        Nr    r$   r    r    r!   r&   j   s   zBaseView.handle c                 C      t |S r   )r   r   datar    r    r!   not_allowedt      zBaseView.not_allowedc                 C   r<   r   )r   r=   r    r    r!   	forbiddenw   r@   zBaseView.forbiddenc                 C   r<   r   )r   r   urlr    r    r!   redirectz   r@   zBaseView.redirectc              	   C      |  tt|||||S r   )rD   r   viewr   viewnameurlconfr   r   prefixcurrent_appr    r    r!   named_redirect}      zBaseView.named_redirectc                 C   r<   r   )r   rB   r    r    r!   permanent_redirect   r@   zBaseView.permanent_redirectc              	   C   rE   r   )rN   r   rF   rG   r    r    r!   named_permanent_redirect   rM   z!BaseView.named_permanent_redirectc                 C   r<   r   )r   r=   r    r    r!   not_modified   r@   zBaseView.not_modifiedc                 C   r<   r   )r   r=   r    r    r!   bad_request   r@   zBaseView.bad_requestc                 C   r<   r   )r   r=   r    r    r!   r      r@   zBaseView.not_foundc                 C   r<   r   )r   r=   r    r    r!   gone   r@   zBaseView.gonec                 C   r<   r   )r   r=   r    r    r!   server_error   r@   zBaseView.server_errorc                 C   s   t t|ddS )Nzapplication/json)mimtype)r   r   dumpsr=   r    r    r!   r         zBaseView.simplejsonc                 C   r<   r   )r   r=   r    r    r!   response   r@   zBaseView.responseTc                 C   s(   |rt |  |t| jS t |  |S r   )r   r:   r   r5   )r   r>   request_contextr    r    r!   r      s   zBaseView.render_to_responsec                 C      t | j| d S r   )r   r5   r   messager    r    r!   message_debug      zBaseView.message_debugc                 C   rY   r   )r   r5   rZ   r    r    r!   message_info   r]   zBaseView.message_infoc                 C   rY   r   )r   r5   rZ   r    r    r!   message_success   r]   zBaseView.message_successc                 C   rY   r   )r	   r5   rZ   r    r    r!   message_warning   r]   zBaseView.message_warningc                 C   rY   r   )r
   r5   rZ   r    r    r!   message_error   r]   zBaseView.message_errorc                 C   s   t | j|| d S r   )r   r5   )r   msgtyper[   r    r    r!   r      rV   zBaseView.add_message)r;   )NNNNN)T)(r%   
__module____qualname____doc__r'   r9   r+   r0   r.   r*   r5   r   r   r"   propertyr8   r#   r:   r   r&   r?   rA   rD   rL   rN   rO   rP   rQ   r   rR   rS   r   rW   r   r\   r^   r_   r`   ra   r   r    r    r    r!   r      sV    











	r   N)django.shortcutsr   django.templater   django.utilsr   django.contrib.authr   django.contrib.messagesr   r   r   r	   r
   r   django.core.urlresolversr   django.httpr   r   r   r   r   r   r   r   r   r   r   objectr   r    r    r    r!   <module>   s     4