
vÅÏ^  ã               @   sŸ   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z m Z Gd d „  d ƒ Z	 Gd d „  d e	 ƒ Z
 Gd	 d
 „  d
 e	 ƒ Z Gd d „  d e	 ƒ Z d S)é    )Úsettings)ÚREDIRECT_FIELD_NAME)Úredirect_to_login)ÚImproperlyConfiguredÚPermissionDeniedc               @   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 } | s3 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   Z	LOGIN_URLr   ÚformatÚ	__class__Ú__name__Ústr)Úselfr	   © r   ú</tmp/pip-build-8lau8j11/django/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_name)r   r   r   r   Úget_redirect_field_name#   s    z#AccessMixin.get_redirect_field_namec             C   sO   |  j  s |  j j j r* t |  j ƒ  ƒ ‚ t |  j j ƒ  |  j ƒ  |  j	 ƒ  ƒ S)N)
Úraise_exceptionÚrequestÚuserÚis_authenticatedr   r   r   Zget_full_pathr   r   )r   r   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 ‡  S)ÚLoginRequiredMixinz.Verify that the current user is authenticated.c                s,   | j  j s |  j ƒ  St ƒ  j | | | Ž S)N)r   r   r   ÚsuperÚdispatch)r   r   ÚargsÚkwargs)r   r   r   r    1   s    
zLoginRequiredMixin.dispatch)r   r   r   r   r    r   r   )r   r   r   /   s   r   c                   sF   e  Z d  Z d Z d Z d d „  Z d d „  Z ‡  f d d †  Z ‡  S)	ÚPermissionRequiredMixinz;Verify that the current user has all specified permissions.Nc             C   sX   |  j  d k r* t d j |  j j ƒ ƒ ‚ t |  j  t ƒ rK |  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   Úpermsr   r   r   Úget_permission_required;   s    	z/PermissionRequiredMixin.get_permission_requiredc             C   s   |  j  ƒ  } |  j j j | ƒ S)zT
        Override this method to customize the way permissions are checked.
        )r'   r   r   Z	has_perms)r   r&   r   r   r   Úhas_permissionK   s    z&PermissionRequiredMixin.has_permissionc                s,   |  j  ƒ  s |  j ƒ  St ƒ  j | | | Ž S)N)r(   r   r   r    )r   r   r!   r"   )r   r   r   r    R   s    
z PermissionRequiredMixin.dispatch)r   r   r   r   r$   r'   r(   r    r   r   )r   r   r#   7   s
   r#   c                   s@   e  Z d  Z d Z d d „  Z d d „  Z ‡  f d d †  Z ‡  S)ÚUserPassesTestMixinz]
    Deny a request with a permission error if the test_func() method returns
    False.
    c             C   s   t  d j |  j j ƒ ƒ ‚ d  S)Nz<{0} is missing the implementation of the test_func() method.)ÚNotImplementedErrorr
   r   r   )r   r   r   r   Ú	test_func^   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_funcc   s    z!UserPassesTestMixin.get_test_funcc                s5   |  j  ƒ  ƒ  } | s |  j ƒ  St ƒ  j | | | Ž S)N)r,   r   r   r    )r   r   r!   r"   Zuser_test_result)r   r   r   r    i   s    
zUserPassesTestMixin.dispatch)r   r   r   r   r+   r,   r    r   r   )r   r   r)   X   s   r)   N)Zdjango.confr   Zdjango.contrib.authr   Zdjango.contrib.auth.viewsr   Zdjango.core.exceptionsr   r   r   r   r#   r)   r   r   r   r   Ú<module>   s   (!