Paginator der besser ins Design passt.
This commit is contained in:
@@ -20,13 +20,16 @@ class LoginRequiredMixin(object):
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if request.user.is_authenticated():
|
||||
return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
|
||||
return super(LoginRequiredMixin, self).dispatch(request, *args,
|
||||
**kwargs)
|
||||
elif self.raise_exception: # if an exception was desired
|
||||
return http.HttpResponseForbidden() # return a forbidden response.
|
||||
else:
|
||||
messages.error(request, _("You need to be logged in"))
|
||||
path = urlquote(request.get_full_path())
|
||||
return http.HttpResponseRedirect("%s?%s=%s" % (self.login_url, self.redirect_field_name, path))
|
||||
return http.HttpResponseRedirect(
|
||||
"%s?%s=%s" % (self.login_url, self.redirect_field_name, path))
|
||||
|
||||
|
||||
class PermissionRequiredMixin(object):
|
||||
"""
|
||||
@@ -60,18 +63,23 @@ class PermissionRequiredMixin(object):
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
# Verify class settings
|
||||
if self.permission_required is None or len(self.permission_required.split(".")) != 2:
|
||||
raise ImproperlyConfigured("'PermissionRequiredMixin' requires 'permission_required' attribute to be set.")
|
||||
if self.permission_required is None or len(
|
||||
self.permission_required.split(".")) != 2:
|
||||
raise ImproperlyConfigured(
|
||||
"'PermissionRequiredMixin' requires 'permission_required' attribute to be set.")
|
||||
has_permission = request.user.has_perm(self.permission_required)
|
||||
|
||||
if has_permission:
|
||||
return super(PermissionRequiredMixin, self).dispatch(request, *args, **kwargs)
|
||||
return super(PermissionRequiredMixin, self).dispatch(request, *args,
|
||||
**kwargs)
|
||||
elif self.raise_exception:
|
||||
return http.HttpResponseForbidden()
|
||||
else:
|
||||
messages.warning(request, self.permission_failed_message)
|
||||
path = urlquote(request.get_full_path())
|
||||
return http.HttpResponseRedirect("%s?%s=%s" % (self.login_url, self.redirect_field_name, path))
|
||||
return http.HttpResponseRedirect(
|
||||
"%s?%s=%s" % (self.login_url, self.redirect_field_name, path))
|
||||
|
||||
|
||||
class SuperuserRequiredMixin(object):
|
||||
"""
|
||||
@@ -83,10 +91,13 @@ class SuperuserRequiredMixin(object):
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if request.user.is_superuser: # If the user is a standard user,
|
||||
return super(SuperuserRequiredMixin, self).dispatch(request, *args, **kwargs)
|
||||
return super(SuperuserRequiredMixin, self).dispatch(request, *args,
|
||||
**kwargs)
|
||||
elif self.raise_exception: # *and* if an exception was desired
|
||||
return http.HttpResponseForbidden() # return a forbidden response.
|
||||
else:
|
||||
messages.error(request, _("You don't have the permissions for this"))
|
||||
messages.error(request,
|
||||
_("You don't have the permissions for this"))
|
||||
path = urlquote(request.get_full_path())
|
||||
return http.HttpResponseRedirect("%s?%s=%s" % (self.login_url, self.redirect_field_name, path))
|
||||
return http.HttpResponseRedirect(
|
||||
"%s?%s=%s" % (self.login_url, self.redirect_field_name, path))
|
||||
|
||||
Reference in New Issue
Block a user