MCPcopy
hub / github.com/django/django / handle_no_permission

Method handle_no_permission

django/contrib/auth/mixins.py:47–65  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

45 return self.redirect_field_name
46
47 def handle_no_permission(self):
48 if self.raise_exception or self.request.user.is_authenticated:
49 raise PermissionDenied(self.get_permission_denied_message())
50
51 path = self.request.build_absolute_uri()
52 resolved_login_url = resolve_url(self.get_login_url())
53 # If the login url is the same scheme and net location then use the
54 # path as the "next" url.
55 login_scheme, login_netloc = urlsplit(resolved_login_url)[:2]
56 current_scheme, current_netloc = urlsplit(path)[:2]
57 if (not login_scheme or login_scheme == current_scheme) and (
58 not login_netloc or login_netloc == current_netloc
59 ):
60 path = self.request.get_full_path()
61 return redirect_to_login(
62 path,
63 resolved_login_url,
64 self.get_redirect_field_name(),
65 )
66
67
68class LoginRequiredMixin(AccessMixin):

Callers 3

dispatchMethod · 0.45
dispatchMethod · 0.45
dispatchMethod · 0.45

Calls 8

get_login_urlMethod · 0.95
PermissionDeniedClass · 0.90
resolve_urlFunction · 0.90
redirect_to_loginFunction · 0.90
build_absolute_uriMethod · 0.80
get_full_pathMethod · 0.80

Tested by

no test coverage detected