Ticket #5394: configurable-redirect-field-name-2.diff
File configurable-redirect-field-name-2.diff, 3.5 KB (added by , 17 years ago) |
---|
-
django/contrib/auth/views.py
9 9 from django.contrib.auth import REDIRECT_FIELD_NAME 10 10 from django.utils.translation import ugettext as _ 11 11 12 def login(request, template_name='registration/login.html' ):12 def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME): 13 13 "Displays the login form and handles the login action." 14 14 manipulator = AuthenticationForm(request) 15 redirect_to = request.REQUEST.get( REDIRECT_FIELD_NAME, '')15 redirect_to = request.REQUEST.get(redirect_field_name, '') 16 16 if request.POST: 17 17 errors = manipulator.get_validation_errors(request.POST) 18 18 if not errors: … … 35 35 36 36 return render_to_response(template_name, { 37 37 'form': oldforms.FormWrapper(manipulator, request.POST, errors), 38 REDIRECT_FIELD_NAME: redirect_to,38 redirect_field_name: redirect_to, 39 39 'site_name': current_site.name, 40 40 }, context_instance=RequestContext(request)) 41 41 … … 56 56 login_url = settings.LOGIN_URL 57 57 return logout(request, login_url) 58 58 59 def redirect_to_login(next, login_url=None ):59 def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): 60 60 "Redirects the user to the login page, passing the given 'next' page" 61 61 if not login_url: 62 62 from django.conf import settings 63 63 login_url = settings.LOGIN_URL 64 return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next))64 return HttpResponseRedirect('%s?%s=%s' % (login_url, redirect_field_name, next)) 65 65 66 66 def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html', 67 67 email_template_name='registration/password_reset_email.html'): -
django/contrib/auth/decorators.py
2 2 from django.http import HttpResponseRedirect 3 3 from urllib import quote 4 4 5 def user_passes_test(test_func, login_url=None ):5 def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): 6 6 """ 7 7 Decorator for views that checks that the user passes the given test, 8 8 redirecting to the log-in page if necessary. The test should be a callable … … 15 15 def _checklogin(request, *args, **kwargs): 16 16 if test_func(request.user): 17 17 return view_func(request, *args, **kwargs) 18 return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, quote(request.get_full_path())))18 return HttpResponseRedirect('%s?%s=%s' % (login_url, redirect_field_name, quote(request.get_full_path()))) 19 19 _checklogin.__doc__ = view_func.__doc__ 20 20 _checklogin.__dict__ = view_func.__dict__ 21 21 22 22 return _checklogin 23 23 return _dec 24 24 25 login_required = user_passes_test(lambda u: u.is_authenticated()) 26 login_required.__doc__ = ( 25 def login_required(redirect_field_name=REDIRECT_FIELD_NAME): 27 26 """ 28 27 Decorator for views that checks that the user is logged in, redirecting 29 28 to the log-in page if necessary. 30 29 """ 31 ) 30 return user_passes_test(lambda u: u.is_authenticated(), redirect_field_name=REDIRECT_FIELD_NAME) 31 32 32 33 33 def permission_required(perm, login_url=None): 34 34 """