
    h                         d dl mZ d dlmZ d dlmZ d dlmZmZ  G d d      Z	 G d de	      Z
 G d	 d
e	      Z G d de	      Zy)    )settings)REDIRECT_FIELD_NAME)redirect_to_login)ImproperlyConfiguredPermissionDeniedc                   8    e Zd ZdZdZdZdZeZd Z	d Z
d Zd Zy)	AccessMixinz^
    Abstract CBV mixin that gives access mixins the same customizable
    functionality.
    N Fc                     | j                   xs t        j                  }|s.t        dj	                  | 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/ranktracker/api/venv/lib/python3.12/site-packages/django/contrib/auth/mixins.pyget_login_urlzAccessMixin.get_login_url   sM     NN8h&8&8	&''-vdnn.E.E'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        | j                  j                         | j                         | j                               S N)
raise_exceptionrequestuseris_authenticatedr   r   r   get_full_pathr   r   r   s    r   handle_no_permissionz AccessMixin.handle_no_permission)   s`    4<<#4#4#E#E"4#E#E#GHH !;!;!=t?Q?Q?SUYUqUqUsttr   )r   
__module____qualname____doc__r   r   r   r   r   r   r   r   r$    r   r   r	   r	      s4     I "O-
.(ur   r	   c                   "     e Zd ZdZ fdZ xZS )LoginRequiredMixinz.Verify that the current user is authenticated.c                 v    |j                   j                  s| j                         S t        |   |g|i |S r   )r!   r"   r$   superdispatchr   r    argskwargsr   s       r   r-   zLoginRequiredMixin.dispatch1   s9    ||,,,,..w9$9&99r   )r   r%   r&   r'   r-   __classcell__r   s   @r   r*   r*   /   s    8: :r   r*   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                  j                              t        | j                   t              r| j                   f}|S | j                   }|S )zv
        Override this method to override the permission_required attribute.
        Must return an iterable.
        z|{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_required;   so    
 ##+&1178O8O1P  d..4--/E  ,,Er   c                 l    | j                         }| j                  j                  j                  |      S )zT
        Override this method to customize the way permissions are checked.
        )r:   r    r!   	has_permsr8   s     r   has_permissionz&PermissionRequiredMixin.has_permissionK   s-     ,,.||  **511r   c                 j    | j                         s| j                         S t        |   |g|i |S r   )r=   r$   r,   r-   r.   s       r   r-   z PermissionRequiredMixin.dispatchR   s8    ""$,,..w9$9&99r   )	r   r%   r&   r'   r6   r:   r=   r-   r1   r2   s   @r   r4   r4   7   s     E 2: :r   r4   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                 ^    t        dj                  | j                  j                              )Nz;{} is missing the implementation of the test_func() method.)NotImplementedErrorr   r   r   r   s    r   	test_funczUserPassesTestMixin.test_func^   s*    !IPPQUQ_Q_QhQhi
 	
r   c                     | j                   S )zK
        Override this method to use a different test_func method.
        )rC   r   s    r   get_test_funcz!UserPassesTestMixin.get_test_funcc   s     ~~r   c                 x     | j                                }|s| j                         S t        |   |g|i |S r   )rE   r$   r,   r-   )r   r    r/   r0   user_test_resultr   s        r   r-   zUserPassesTestMixin.dispatchi   sC    /4--/1,,..w9$9&99r   )r   r%   r&   r'   rC   rE   r-   r1   r2   s   @r   r@   r@   X   s    


: :r   r@   N)django.confr   django.contrib.authr   django.contrib.auth.viewsr   django.core.exceptionsr   r   r	   r*   r4   r@   r(   r   r   <module>rL      sC      3 7 I%u %uP: ::k :B:+ :r   