
    +h                         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          Z G d	 d
e          Z G d de          Z G d de          ZdS )    )urlparse)settings)REDIRECT_FIELD_NAME)redirect_to_login)ImproperlyConfiguredPermissionDenied)resolve_urlc                   :    e Zd ZdZdZdZdZeZd Z	d Z
d Zd ZdS )	AccessMixinz^
    Abstract CBV mixin that gives access mixins the same customizable
    functionality.
    N Fc                     | j         pt          j        }|s,t          d                    | j        j                            t          |          S )zK
        Override this method to override the login_url attribute.
        zr{0} is missing the login_url attribute. Define {0}.login_url, settings.LOGIN_URL, or override {0}.get_login_url().)	login_urlr   	LOGIN_URLr   format	__class____name__str)selfr   s     ^/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/django/contrib/auth/mixins.pyget_login_urlzAccessMixin.get_login_url   sR     N8h&8	 	&''-vdn.E'F'F   9~~    c                     | j         S )z[
        Override this method to override the permission_denied_message attribute.
        )permission_denied_messager   s    r   get_permission_denied_messagez)AccessMixin.get_permission_denied_message    s     --r   c                     | j         S )zU
        Override this method to override the redirect_field_name attribute.
        )redirect_field_namer   s    r   get_redirect_field_namez#AccessMixin.get_redirect_field_name&   s     ''r   c                    | j         s| j        j        j        r!t	          |                                           | j                                        }t          |                                           }t          |          d d         \  }}t          |          d d         \  }}|r||k    r!|r||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_netlocs          r   handle_no_permissionz AccessMixin.handle_no_permission,   s     	I4<#4#E 	I"4#E#E#G#GHHH|..00(););)=)=>> &..@%A%A"1"%E"l)1$);&	0!-!?!? "@!-!?!?<--//D ((**
 
 	
r   )r   
__module____qualname____doc__r   r   r!   r   r   r   r   r   r-    r   r   r   r   
   sr          I "O-
 
 
. . .( ( (
 
 
 
 
r   r   c                   "     e Zd ZdZ fdZ xZS )LoginRequiredMixinz.Verify that the current user is authenticated.c                 ~    |j         j        s|                                 S  t                      j        |g|R i |S N)r#   r$   r-   superdispatchr   r"   argskwargsr   s       r   r7   zLoginRequiredMixin.dispatchD   sI    |, 	/,,...uww9$999&999r   )r   r.   r/   r0   r7   __classcell__r   s   @r   r3   r3   B   s>        88: : : : : : : : :r   r3   c                   2     e Zd ZdZdZd Zd Z fdZ xZS )PermissionRequiredMixinz;Verify that the current user has all specified permissions.Nc                     | j         ,t          d                    | j        j                            t          | j         t                    r	| j         f}n| j         }|S )zv
        Override this method to override the permission_required attribute.
        Must return an iterable.
        Nz|{0} is missing the permission_required attribute. Define {0}.permission_required, or override {0}.get_permission_required().)permission_requiredr   r   r   r   
isinstancer   r   permss     r   get_permission_requiredz/PermissionRequiredMixin.get_permission_requiredN   sg    
 #+&1178O1P1P   d.44 	--/EE,Er   c                 h    |                                  }| j        j                            |          S )zT
        Override this method to customize the way permissions are checked.
        )rD   r"   r#   	has_permsrB   s     r   has_permissionz&PermissionRequiredMixin.has_permission^   s.     ,,..| **5111r   c                     |                                  s|                                 S  t                      j        |g|R i |S r5   )rG   r-   r6   r7   r8   s       r   r7   z PermissionRequiredMixin.dispatche   sP    ""$$ 	/,,...uww9$999&999r   )	r   r.   r/   r0   r@   rD   rG   r7   r;   r<   s   @r   r>   r>   J   sb        EE   2 2 2: : : : : : : : :r   r>   c                   .     e Zd ZdZd Zd Z fdZ xZS )UserPassesTestMixinz]
    Deny a request with a permission error if the test_func() method returns
    False.
    c                 Z    t          d                    | j        j                            )Nz;{} is missing the implementation of the test_func() method.)NotImplementedErrorr   r   r   r   s    r   	test_funczUserPassesTestMixin.test_funcq   s,    !IPPQUQ_Qhii
 
 	
r   c                     | j         S )zK
        Override this method to use a different test_func method.
        )rM   r   s    r   get_test_funcz!UserPassesTestMixin.get_test_funcv   s     ~r   c                      |                                              }|s|                                 S  t                      j        |g|R i |S r5   )rO   r-   r6   r7   )r   r"   r9   r:   user_test_resultr   s        r   r7   zUserPassesTestMixin.dispatch|   s^    /4--//11 	/,,...uww9$999&999r   )r   r.   r/   r0   rM   rO   r7   r;   r<   s   @r   rJ   rJ   k   s`         

 
 

  : : : : : : : : :r   rJ   N)urllib.parser   django.confr   django.contrib.authr   django.contrib.auth.viewsr   django.core.exceptionsr   r   django.shortcutsr	   r   r3   r>   rJ   r1   r   r   <module>rX      s)   ! ! ! ! ! !             3 3 3 3 3 3 7 7 7 7 7 7 I I I I I I I I ( ( ( ( ( (5
 5
 5
 5
 5
 5
 5
 5
p: : : : : : : :: : : : :k : : :B: : : : :+ : : : : :r   