
    Dvg,                         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        }|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   s     W/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/contrib/auth/mixins.pyget_login_urlzAccessMixin.get_login_url   sv     N8h&8	 	&>* > >>*> >>*> > >  
 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   r6   zLoginRequiredMixin.dispatchF   sI    |, 	/,,...uww9$999&999r   )r   r-   r.   r/   r6   __classcell__r   s   @r   r2   r2   C   s>        88: : : : : : : : :r   r2   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         6t          | j        j         d| j        j         d| j        j         d          t	          | j         t
                    r	| 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   permss     r   get_permission_requiredz/PermissionRequiredMixin.get_permission_requiredQ   s    
 #+&>* H H>*H H >*H H H   d.44 	--/EE,Er   c                 h    |                                  }| j        j                            |          S )zT
        Override this method to customize the way permissions are checked.
        )rC   r!   r"   	has_permsrA   s     r   has_permissionz&PermissionRequiredMixin.has_permissionc   s.     ,,..| **5111r   c                     |                                  s|                                 S  t                      j        |g|R i |S r4   )rF   r,   r5   r6   r7   s       r   r6   z PermissionRequiredMixin.dispatchj   sP    ""$$ 	/,,...uww9$999&999r   )	r   r-   r.   r/   r?   rC   rF   r6   r:   r;   s   @r   r=   r=   L   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.)NotImplementedErrorformatr   r   r   s    r   	test_funczUserPassesTestMixin.test_funcv   s/    !IPP' 
 
 	
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_func}   s     ~r   c                      |                                              }|s|                                 S  t                      j        |g|R i |S r4   )rO   r,   r5   r6   )r   r!   r8   r9   user_test_resultr   s        r   r6   zUserPassesTestMixin.dispatch   s^    /4--//11 	/,,...uww9$999&999r   )r   r-   r.   r/   rM   rO   r6   r:   r;   s   @r   rI   rI   p   s`         

 
 
  : : : : : : : : :r   rI   N)urllib.parser   django.confr   django.contrib.authr   django.contrib.auth.viewsr   django.core.exceptionsr   r   django.shortcutsr	   r   r2   r=   rI   r0   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 ( ( ( ( ( (6
 6
 6
 6
 6
 6
 6
 6
r: : : : : : : :!: !: !: !: !:k !: !: !:H: : : : :+ : : : : :r   