Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Use auth.redirect_to_login instead of custom redirect code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmispelon committed Dec 1, 2012
1 parent dac8f1f commit e5e24bf
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions braces/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import login_required
from django.contrib.auth.views import redirect_to_login
from django.core import serializers
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.utils import simplejson as json
from django.http import (HttpResponseForbidden, HttpResponseRedirect,
HttpResponse)
from django.http import HttpResponseForbidden, HttpResponse
from django.utils.decorators import method_decorator
from django.utils.http import urlquote
from django.views.generic import CreateView
Expand Down Expand Up @@ -92,12 +92,9 @@ def dispatch(self, request, *args, **kwargs):
if self.raise_exception: # *and* if an exception was desired
return HttpResponseForbidden() # return a forbidden response.
else:
# otherwise, redirect the user to the login page.
# Also, handily, sets the `next` GET argument
# for future redirects.
path = urlquote(request.get_full_path())
tup = self.login_url, self.redirect_field_name, path
return HttpResponseRedirect("%s?%s=%s" % tup)
return redirect_to_login(request.get_full_path(),
self.login_url,
self.redirect_field_name)

return super(PermissionRequiredMixin, self).dispatch(request,
*args, **kwargs)
Expand Down Expand Up @@ -160,9 +157,9 @@ def dispatch(self, request, *args, **kwargs):
if not request.user.has_perms(perms_all):
if self.raise_exception:
return HttpResponseForbidden()
path = urlquote(request.get_full_path())
tup = self.login_url, self.redirect_field_name, path
return HttpResponseRedirect("%s?%s=%s" % tup)
return redirect_to_login(request.get_full_path(),
self.login_url,
self.redirect_field_name)

# If perms_any, check that user has at least one in the list/tuple
if perms_any:
Expand All @@ -175,9 +172,9 @@ def dispatch(self, request, *args, **kwargs):
if not has_one_perm:
if self.raise_exception:
return HttpResponseForbidden()
path = urlquote(request.get_full_path())
tup = self.login_url, self.redirect_field_name, path
return HttpResponseRedirect("%s?%s=%s" % tup)
return redirect_to_login(request.get_full_path(),
self.login_url,
self.redirect_field_name)

return super(MultiplePermissionsRequiredMixin, self).dispatch(request,
*args, **kwargs)
Expand Down Expand Up @@ -254,12 +251,9 @@ def dispatch(self, request, *args, **kwargs):
if self.raise_exception: # *and* if an exception was desired
return HttpResponseForbidden() # return a forbidden response.
else:
# otherwise, redirect the user to the login page.
# Also, handily, sets the `next` GET argument for
# future redirects.
path = urlquote(request.get_full_path())
tup = self.login_url, self.redirect_field_name, path
return HttpResponseRedirect("%s?%s=%s" % tup)
return redirect_to_login(request.get_full_path(),
self.login_url,
self.redirect_field_name)

return super(SuperuserRequiredMixin, self).dispatch(request,
*args, **kwargs)
Expand Down Expand Up @@ -331,12 +325,9 @@ def dispatch(self, request, *args, **kwargs):
if self.raise_exception: # *and* if an exception was desired
return HttpResponseForbidden() # return a forbidden response
else:
# otherwise, redirect the user to the login page.
# Also, handily, sets the GET `next` argument for
# future redirects.
path = urlquote(request.get_full_path())
tup = self.login_url, self.redirect_field_name, path
return HttpResponseRedirect("%s?%s=%s" % tup)
return redirect_to_login(request.get_full_path(),
self.login_url,
self.redirect_field_name)

return super(StaffuserRequiredMixin, self).dispatch(request,
*args, **kwargs)
Expand Down

0 comments on commit e5e24bf

Please sign in to comment.