o Úøa•ã@sŽddlmZddlmZddlmZddlmZddlm Z m Z ddl m Z Gdd„dƒZ Gd d „d e ƒZGd d „d e ƒZGd d„de ƒZdS)é)Úurlparse)Úsettings)ÚREDIRECT_FIELD_NAME)Úredirect_to_login)ÚImproperlyConfiguredÚPermissionDenied)Ú resolve_urlc@s@eZdZdZdZdZdZeZdd„Z dd„Z d d „Z d d „Z dS) Ú AccessMixinz^ Abstract CBV mixin that gives access mixins the same customizable functionality. NÚFcCs*|jptj}|std |jj¡ƒ‚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 ©rú|r9||kr>|j  ¡}t |||  ¡ƒS)Né) Úraise_exceptionÚrequestÚuserÚis_authenticatedrrÚbuild_absolute_urirrrÚ get_full_pathrr)rÚpathÚresolved_login_urlÚ login_schemeÚ login_netlocÚcurrent_schemeÚcurrent_netlocrrrÚhandle_no_permission,s$   ÿÿ ýz AccessMixin.handle_no_permission) rÚ __module__Ú __qualname__Ú__doc__r rrrrrrrr)rrrrr s  r cs eZdZdZ‡fdd„Z‡ZS)ÚLoginRequiredMixinz.Verify that the current user is authenticated.cs*|jjs| ¡Stƒj|g|¢Ri|¤ŽS©N)rr r)ÚsuperÚdispatch©rrÚargsÚkwargs©rrrr0DózLoginRequiredMixin.dispatch)rr*r+r,r0Ú __classcell__rrr4rr-Bsr-cs4eZdZdZdZdd„Zdd„Z‡fdd„Z‡ZS) ÚPermissionRequiredMixinz;Verify that the current user has all specified permissions.NcCs>|jdurtd |jj¡ƒ‚t|jtƒr|jf}|S|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_requiredrr rrÚ isinstancer©rÚpermsrrrÚget_permission_requiredNs  þ ÿz/PermissionRequiredMixin.get_permission_requiredcCs| ¡}|jj |¡S)zT Override this method to customize the way permissions are checked. )r<rrÚ has_permsr:rrrÚhas_permission^sz&PermissionRequiredMixin.has_permissioncs*| ¡s| ¡Stƒj|g|¢Ri|¤ŽSr.)r>r)r/r0r1r4rrr0er5z PermissionRequiredMixin.dispatch) rr*r+r,r8r<r>r0r6rrr4rr7Js r7cs0eZdZdZdd„Zdd„Z‡fdd„Z‡ZS)ÚUserPassesTestMixinz] Deny a request with a permission error if the test_func() method returns False. cCstd |jj¡ƒ‚)Nz;{} is missing the implementation of the test_func() method.)ÚNotImplementedErrorr rrrrrrÚ test_funcqs ÿzUserPassesTestMixin.test_funccCr)zK Override this method to use a different test_func method. )rArrrrÚ get_test_funcvrz!UserPassesTestMixin.get_test_funccs0| ¡ƒ}|s | ¡Stƒj|g|¢Ri|¤ŽSr.)rBr)r/r0)rrr2r3Úuser_test_resultr4rrr0|s zUserPassesTestMixin.dispatch)rr*r+r,rArBr0r6rrr4rr?ks r?N)Ú urllib.parserÚ django.confrÚdjango.contrib.authrÚdjango.contrib.auth.viewsrÚdjango.core.exceptionsrrÚdjango.shortcutsrr r-r7r?rrrrÚs    8!