Ticket #6310: contrib_auth_decorators.patch
File contrib_auth_decorators.patch, 1.7 KB (added by , 17 years ago) |
---|
-
usr/local/src/django/django/contrib/auth/decorators.py
1 1 from django.contrib.auth import REDIRECT_FIELD_NAME 2 from django.http import HttpResponseRedirect 2 from django.http import HttpResponseRedirect, HttpResponseForbidden 3 3 from django.utils.http import urlquote 4 4 5 5 def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): … … 30 30 Decorator for views that checks whether a user has a particular permission 31 31 enabled, redirecting to the log-in page if necessary. 32 32 """ 33 # import pdb; pdb.set_trace() 33 34 return user_passes_test(lambda u: u.has_perm(perm), login_url=login_url) 34 35 35 36 class _CheckLogin(object): … … 58 59 return _CheckLogin(view_func, self.test_func, self.login_url, self.redirect_field_name) 59 60 60 61 def __call__(self, request, *args, **kwargs): 62 """ Execute the test_function for the end user, 63 otherwise, redirect them to an appropriate page """ 64 61 65 if self.test_func(request.user): 62 66 return self.view_func(request, *args, **kwargs) 67 63 68 path = urlquote(request.get_full_path()) 69 70 if request.user.is_authenticated(): 71 # pushing the user back through the login_url only makes 72 # sense if they haven't already done that. 73 return HttpResponseForbidden("<h1>Access Forbidden: You do not have rights to %s</h1>" % path) 74 64 75 tup = self.login_url, self.redirect_field_name, path 76 65 77 return HttpResponseRedirect('%s?%s=%s' % tup)