Code

Ticket #5394: configurable-redirect-field-name.diff

File configurable-redirect-field-name.diff, 3.8 KB (added by Petr Marhoun <petr.marhoun@…>, 7 years ago)
Line 
1=== modified file 'django/conf/global_settings.py'
2--- django/conf/global_settings.py      2007-08-19 10:24:35 +0000
3+++ django/conf/global_settings.py      2007-09-10 17:55:53 +0000
4@@ -328,6 +328,8 @@
5 
6 LOGIN_REDIRECT_URL = '/accounts/profile/'
7 
8+REDIRECT_FIELD_NAME = 'next'
9+
10 ###########
11 # TESTING #
12 ###########
13
14=== modified file 'django/contrib/auth/__init__.py'
15--- django/contrib/auth/__init__.py     2007-07-13 05:03:33 +0000
16+++ django/contrib/auth/__init__.py     2007-09-10 17:55:53 +0000
17@@ -3,7 +3,6 @@
18 
19 SESSION_KEY = '_auth_user_id'
20 BACKEND_SESSION_KEY = '_auth_user_backend'
21-REDIRECT_FIELD_NAME = 'next'
22 
23 def load_backend(path):
24     i = path.rfind('.')
25
26=== modified file 'django/contrib/auth/decorators.py'
27--- django/contrib/auth/decorators.py   2007-04-25 08:49:57 +0000
28+++ django/contrib/auth/decorators.py   2007-09-10 17:55:53 +0000
29@@ -1,4 +1,3 @@
30-from django.contrib.auth import REDIRECT_FIELD_NAME
31 from django.http import HttpResponseRedirect
32 from urllib import quote
33 
34@@ -8,14 +7,14 @@
35     redirecting to the log-in page if necessary. The test should be a callable
36     that takes the user object and returns True if the user passes.
37     """
38+    from django.conf import settings
39     if not login_url:
40-        from django.conf import settings
41         login_url = settings.LOGIN_URL
42     def _dec(view_func):
43         def _checklogin(request, *args, **kwargs):
44             if test_func(request.user):
45                 return view_func(request, *args, **kwargs)
46-            return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, quote(request.get_full_path())))
47+            return HttpResponseRedirect('%s?%s=%s' % (login_url, settings.REDIRECT_FIELD_NAME, quote(request.get_full_path())))
48         _checklogin.__doc__ = view_func.__doc__
49         _checklogin.__dict__ = view_func.__dict__
50 
51
52=== modified file 'django/contrib/auth/views.py'
53--- django/contrib/auth/views.py        2007-08-25 18:34:28 +0000
54+++ django/contrib/auth/views.py        2007-09-10 17:55:53 +0000
55@@ -6,19 +6,18 @@
56 from django.contrib.sites.models import Site, RequestSite
57 from django.http import HttpResponseRedirect
58 from django.contrib.auth.decorators import login_required
59-from django.contrib.auth import REDIRECT_FIELD_NAME
60 from django.utils.translation import ugettext as _
61 
62 def login(request, template_name='registration/login.html'):
63     "Displays the login form and handles the login action."
64     manipulator = AuthenticationForm(request)
65-    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
66+    from django.conf import settings
67+    redirect_to = request.REQUEST.get(settings.REDIRECT_FIELD_NAME, '')
68     if request.POST:
69         errors = manipulator.get_validation_errors(request.POST)
70         if not errors:
71             # Light security check -- make sure redirect_to isn't garbage.
72             if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
73-                from django.conf import settings
74                 redirect_to = settings.LOGIN_REDIRECT_URL
75             from django.contrib.auth import login
76             login(request, manipulator.get_user())
77@@ -35,7 +34,7 @@
78 
79     return render_to_response(template_name, {
80         'form': oldforms.FormWrapper(manipulator, request.POST, errors),
81-        REDIRECT_FIELD_NAME: redirect_to,
82+        settings.REDIRECT_FIELD_NAME: redirect_to,
83         'site_name': current_site.name,
84     }, context_instance=RequestContext(request))
85 
86@@ -61,7 +60,7 @@
87     if not login_url:
88         from django.conf import settings
89         login_url = settings.LOGIN_URL
90-    return HttpResponseRedirect('%s?%s=%s' % (login_url, REDIRECT_FIELD_NAME, next))
91+    return HttpResponseRedirect('%s?%s=%s' % (login_url, settings.REDIRECT_FIELD_NAME, next))
92 
93 def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html',
94         email_template_name='registration/password_reset_email.html'):
95