a
    Qh,                     @   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
 d dlmZ G dd dZG d	d
 d
eZG dd deZG dd deZdS )    )urlparse)settings)REDIRECT_FIELD_NAME)redirect_to_login)ImproperlyConfiguredPermissionDenied)resolve_urlc                   @   s@   e Zd ZdZdZdZdZeZdd Z	dd Z
d	d
 Zdd ZdS )AccessMixinz^
    Abstract CBV mixin that gives access mixins the same customizable
    functionality.
    N Fc                 C   s>   | j p
tj}|s6t| jj d| jj d| jj dt|S )zK
        Override this method to override the login_url attribute.
        z, is missing the login_url attribute. Define z,.login_url, settings.LOGIN_URL, or override z.get_login_url().)	login_urlr   	LOGIN_URLr   	__class____name__str)selfr    r   S/var/www/sistema_ama/venv/lib/python3.9/site-packages/django/contrib/auth/mixins.pyget_login_url   s    
zAccessMixin.get_login_urlc                 C   s   | j S )z[
        Override this method to override the permission_denied_message attribute.
        )permission_denied_messager   r   r   r   get_permission_denied_message"   s    z)AccessMixin.get_permission_denied_messagec                 C   s   | j S )zU
        Override this method to override the redirect_field_name attribute.
        )redirect_field_namer   r   r   r   get_redirect_field_name(   s    z#AccessMixin.get_redirect_field_namec                 C   s   | j s| jjjrt|  | j }t|  }t	|d d \}}t	|d d \}}|rf||kr||rr||kr|| j
 }t|||  S )N   )raise_exceptionrequestuseris_authenticatedr   r   build_absolute_urir   r   r   get_full_pathr   r   )r   pathresolved_login_urllogin_schemelogin_netloccurrent_schemecurrent_netlocr   r   r   handle_no_permission.   s"    

z AccessMixin.handle_no_permission)r   
__module____qualname____doc__r   r   r   r   r   r   r   r   r&   r   r   r   r   r	   
   s   r	   c                       s    e Zd ZdZ fddZ  ZS )LoginRequiredMixinz.Verify that the current user is authenticated.c                    s*   |j js|  S t j|g|R i |S N)r   r   r&   superdispatchr   r   argskwargsr   r   r   r-   F   s    zLoginRequiredMixin.dispatch)r   r'   r(   r)   r-   __classcell__r   r   r1   r   r*   C   s   r*   c                       s4   e Zd ZdZdZdd Zdd Z fddZ  ZS )	PermissionRequiredMixinz;Verify that the current user has all specified permissions.Nc                 C   sP   | j du r0t| jj d| jj d| jj dt| j trF| j f}n| j }|S )zv
        Override this method to override the permission_required attribute.
        Must return an iterable.
        Nz6 is missing the permission_required attribute. Define z".permission_required, or override z.get_permission_required().)permission_requiredr   r   r   
isinstancer   r   permsr   r   r   get_permission_requiredQ   s    


z/PermissionRequiredMixin.get_permission_requiredc                 C   s   |   }| jj|S )zT
        Override this method to customize the way permissions are checked.
        )r8   r   r   	has_permsr6   r   r   r   has_permissionc   s    z&PermissionRequiredMixin.has_permissionc                    s*   |   s|  S t j|g|R i |S r+   )r:   r&   r,   r-   r.   r1   r   r   r-   j   s    z PermissionRequiredMixin.dispatch)	r   r'   r(   r)   r4   r8   r:   r-   r2   r   r   r1   r   r3   L   s
   r3   c                       s0   e Zd ZdZdd Zdd Z fddZ  ZS )UserPassesTestMixinz]
    Deny a request with a permission error if the test_func() method returns
    False.
    c                 C   s   t d| jjd S )Nz;{} is missing the implementation of the test_func() method.)NotImplementedErrorformatr   r   r   r   r   r   	test_funcv   s
    zUserPassesTestMixin.test_funcc                 C   s   | j S )zK
        Override this method to use a different test_func method.
        )r>   r   r   r   r   get_test_func}   s    z!UserPassesTestMixin.get_test_funcc                    s0   |    }|s|  S t j|g|R i |S r+   )r?   r&   r,   r-   )r   r   r/   r0   Zuser_test_resultr1   r   r   r-      s    
zUserPassesTestMixin.dispatch)r   r'   r(   r)   r>   r?   r-   r2   r   r   r1   r   r;   p   s   r;   N)urllib.parser   django.confr   django.contrib.authr   django.contrib.auth.viewsr   django.core.exceptionsr   r   django.shortcutsr   r	   r*   r3   r;   r   r   r   r   <module>   s   9	$