Code

Ticket #285: script_name_path_info2.diff

File script_name_path_info2.diff, 15.4 KB (added by jmelesky, 7 years ago)

corrected and far more comprehensive patch, against [6292]

Line 
1Index: django/http/__init__.py
2===================================================================
3--- django/http/__init__.py     (revision 6292)
4+++ django/http/__init__.py     (working copy)
5@@ -26,6 +26,7 @@
6     def __init__(self):
7         self.GET, self.POST, self.COOKIES, self.META, self.FILES = {}, {}, {}, {}, {}
8         self.path = ''
9+        self.full_path = ''
10         self.method = None
11 
12     def __repr__(self):
13@@ -57,7 +58,7 @@
14             location = self.get_full_path()
15         if not ':' in location:
16             current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http',
17-                                         get_host(self), self.path)
18+                                         get_host(self), self.full_path)
19             location = urljoin(current_uri, location)
20         return location
21 
22Index: django/core/handlers/wsgi.py
23===================================================================
24--- django/core/handlers/wsgi.py        (revision 6292)
25+++ django/core/handlers/wsgi.py        (working copy)
26@@ -75,7 +75,9 @@
27 class WSGIRequest(http.HttpRequest):
28     def __init__(self, environ):
29         self.environ = environ
30-        self.path = force_unicode(environ['PATH_INFO'])
31+        self.path = force_unicode(environ.get('PATH_INFO', '/'))
32+        self.full_path = (force_unicode(environ.get('SCRIPT_NAME', ''))
33+                          + force_unicode(environ.get('PATH_INFO', '/')))
34         self.META = environ
35         self.method = environ['REQUEST_METHOD'].upper()
36 
37@@ -102,7 +104,7 @@
38             (get, post, cookies, meta)
39 
40     def get_full_path(self):
41-        return '%s%s' % (self.path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '')
42+        return '%s%s' % (self.full_path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '')
43 
44     def is_secure(self):
45         return 'HTTPS' in self.environ and self.environ['HTTPS'] == 'on'
46Index: django/core/handlers/modpython.py
47===================================================================
48--- django/core/handlers/modpython.py   (revision 6292)
49+++ django/core/handlers/modpython.py   (working copy)
50@@ -14,7 +14,12 @@
51 class ModPythonRequest(http.HttpRequest):
52     def __init__(self, req):
53         self._req = req
54-        self.path = force_unicode(req.uri)
55+        self.full_path = force_unicode(req.uri)
56+        root = req.get_options().get('django.root', '')
57+        if root and req.uri.startswith(root):
58+            self.path = force_unicode(req.uri[len(root):])
59+        else:
60+            self.path = self.full_path
61 
62     def __repr__(self):
63         # Since this is called as part of error handling, we need to be very
64@@ -39,7 +44,7 @@
65             (self.path, get, post, cookies, meta)
66 
67     def get_full_path(self):
68-        return '%s%s' % (self.path, self._req.args and ('?' + self._req.args) or '')
69+        return '%s%s' % (self.full_path, self._req.args and ('?' + self._req.args) or '')
70 
71     def is_secure(self):
72         # Note: modpython 3.2.10+ has req.is_https(), but we need to support previous versions
73Index: django/views/generic/create_update.py
74===================================================================
75--- django/views/generic/create_update.py       (revision 6292)
76+++ django/views/generic/create_update.py       (working copy)
77@@ -21,7 +21,7 @@
78     """
79     if extra_context is None: extra_context = {}
80     if login_required and not request.user.is_authenticated():
81-        return redirect_to_login(request.path)
82+        return redirect_to_login(request.full_path)
83 
84     manipulator = model.AddManipulator(follow=follow)
85     if request.POST:
86@@ -87,7 +87,7 @@
87     """
88     if extra_context is None: extra_context = {}
89     if login_required and not request.user.is_authenticated():
90-        return redirect_to_login(request.path)
91+        return redirect_to_login(request.full_path)
92 
93     # Look up the object to be edited
94     lookup_kwargs = {}
95@@ -163,7 +163,7 @@
96     """
97     if extra_context is None: extra_context = {}
98     if login_required and not request.user.is_authenticated():
99-        return redirect_to_login(request.path)
100+        return redirect_to_login(request.full_path)
101 
102     # Look up the object to be edited
103     lookup_kwargs = {}
104Index: django/views/debug.py
105===================================================================
106--- django/views/debug.py       (revision 6292)
107+++ django/views/debug.py       (working copy)
108@@ -345,7 +345,7 @@
109     </tr>
110     <tr>
111       <th>Request URL:</th>
112-      <td>{{ request_protocol }}://{{ request.META.HTTP_HOST }}{{ request.path|escape }}</td>
113+      <td>{{ request_protocol }}://{{ request.META.HTTP_HOST }}{{ request.full_path|escape }}</td>
114     </tr>
115     <tr>
116       <th>Exception Type:</th>
117@@ -634,7 +634,7 @@
118       </tr>
119       <tr>
120         <th>Request URL:</th>
121-      <td>{{ request_protocol }}://{{ request.META.HTTP_HOST }}{{ request.path|escape }}</td>
122+      <td>{{ request_protocol }}://{{ request.META.HTTP_HOST }}{{ request.full_path|escape }}</td>
123       </tr>
124     </table>
125   </div>
126Index: django/contrib/syndication/feeds.py
127===================================================================
128--- django/contrib/syndication/feeds.py (revision 6292)
129+++ django/contrib/syndication/feeds.py (working copy)
130@@ -25,7 +25,7 @@
131     def __init__(self, slug, request):
132         self.slug = slug
133         self.request = request
134-        self.feed_url = request.path
135+        self.feed_url = request.full_path
136         self.title_template_name = self.title_template or ('feeds/%s_title.html' % slug)
137         self.description_template_name = self.description_template or ('feeds/%s_description.html' % slug)
138 
139Index: django/contrib/comments/views/userflags.py
140===================================================================
141--- django/contrib/comments/views/userflags.py  (revision 6292)
142+++ django/contrib/comments/views/userflags.py  (working copy)
143@@ -19,7 +19,7 @@
144     comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID)
145     if request.POST:
146         UserFlag.objects.flag(comment, request.user)
147-        return HttpResponseRedirect('%sdone/' % request.path)
148+        return HttpResponseRedirect('%sdone/' % request.full_path)
149     return render_to_response('comments/flag_verify.html', {'comment': comment},
150         context_instance=RequestContext(request, extra_context, context_processors))
151 flag = login_required(flag)
152@@ -50,7 +50,7 @@
153             comment.save()
154             m = ModeratorDeletion(None, request.user.id, comment.id, None)
155             m.save()
156-        return HttpResponseRedirect('%sdone/' % request.path)
157+        return HttpResponseRedirect('%sdone/' % request.full_path)
158     return render_to_response('comments/delete_verify.html', {'comment': comment},
159         context_instance=RequestContext(request, extra_context, context_processors))
160 delete = login_required(delete)
161Index: django/contrib/admin/views/auth.py
162===================================================================
163--- django/contrib/admin/views/auth.py  (revision 6292)
164+++ django/contrib/admin/views/auth.py  (working copy)
165@@ -20,7 +20,7 @@
166             msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user}
167             if "_addanother" in request.POST:
168                 request.user.message_set.create(message=msg)
169-                return HttpResponseRedirect(request.path)
170+                return HttpResponseRedirect(request.full_path)
171             else:
172                 request.user.message_set.create(message=msg + ' ' + _("You may edit it again below."))
173                 return HttpResponseRedirect('../%s/' % new_user.id)
174Index: django/contrib/admin/views/main.py
175===================================================================
176--- django/contrib/admin/views/main.py  (revision 6292)
177+++ django/contrib/admin/views/main.py  (working copy)
178@@ -276,7 +276,7 @@
179                     (pk_value, force_unicode(new_object).replace('"', '\\"')))
180             elif "_addanother" in request.POST:
181                 request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)))
182-                return HttpResponseRedirect(request.path)
183+                return HttpResponseRedirect(request.full_path)
184             else:
185                 request.user.message_set.create(message=msg)
186                 return HttpResponseRedirect(post_url)
187@@ -353,9 +353,9 @@
188             if "_continue" in request.POST:
189                 request.user.message_set.create(message=msg + ' ' + _("You may edit it again below."))
190                 if '_popup' in request.REQUEST:
191-                    return HttpResponseRedirect(request.path + "?_popup=1")
192+                    return HttpResponseRedirect(request.full_path + "?_popup=1")
193                 else:
194-                    return HttpResponseRedirect(request.path)
195+                    return HttpResponseRedirect(request.full_path)
196             elif "_saveasnew" in request.POST:
197                 request.user.message_set.create(message=_('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(new_object)})
198                 return HttpResponseRedirect("../%s/" % pk_value)
199@@ -778,7 +778,7 @@
200         # is screwed up with the database, so display an error page.
201         if ERROR_FLAG in request.GET.keys():
202             return render_to_response('admin/invalid_setup.html', {'title': _('Database error')})
203-        return HttpResponseRedirect(request.path + '?' + ERROR_FLAG + '=1')
204+        return HttpResponseRedirect(request.full_path + '?' + ERROR_FLAG + '=1')
205     c = template.RequestContext(request, {
206         'title': cl.title,
207         'is_popup': cl.is_popup,
208Index: django/contrib/admin/views/decorators.py
209===================================================================
210--- django/contrib/admin/views/decorators.py    (revision 6292)
211+++ django/contrib/admin/views/decorators.py    (working copy)
212@@ -22,7 +22,7 @@
213         post_data = _encode_post_data({})
214     return render_to_response('admin/login.html', {
215         'title': _('Log in'),
216-        'app_path': request.path,
217+        'app_path': request.full_path,
218         'post_data': post_data,
219         'error_message': error_message
220     }, context_instance=template.RequestContext(request))
221@@ -99,7 +99,7 @@
222                         return view_func(request, *args, **kwargs)
223                     else:
224                         request.session.delete_test_cookie()
225-                        return http.HttpResponseRedirect(request.path)
226+                        return http.HttpResponseRedirect(request.full_path)
227             else:
228                 return _display_login_form(request, ERROR_MESSAGE)
229 
230Index: django/contrib/admin/views/doc.py
231===================================================================
232--- django/contrib/admin/views/doc.py   (revision 6292)
233+++ django/contrib/admin/views/doc.py   (working copy)
234@@ -27,7 +27,7 @@
235 
236 def bookmarklets(request):
237     # Hack! This couples this view to the URL it lives at.
238-    admin_root = request.path[:-len('doc/bookmarklets/')]
239+    admin_root = request.full_path[:-len('doc/bookmarklets/')]
240     return render_to_response('admin_doc/bookmarklets.html', {
241         'admin_url': "%s://%s%s" % (request.is_secure() and 'https' or 'http', get_host(request), admin_root),
242     }, context_instance=RequestContext(request))
243Index: django/contrib/databrowse/plugins/objects.py
244===================================================================
245--- django/contrib/databrowse/plugins/objects.py        (revision 6292)
246+++ django/contrib/databrowse/plugins/objects.py        (working copy)
247@@ -8,7 +8,7 @@
248     def model_view(self, request, model_databrowse, url):
249         # If the object ID wasn't provided, redirect to the model page, which is one level up.
250         if url is None:
251-            return http.HttpResponseRedirect(urlparse.urljoin(request.path, '../'))
252+            return http.HttpResponseRedirect(urlparse.urljoin(request.full_path, '../'))
253         easy_model = EasyModel(model_databrowse.site, model_databrowse.model)
254         obj = easy_model.object_by_pk(url)
255         return render_to_response('databrowse/object_detail.html', {'object': obj, 'root_url': model_databrowse.site.root_url})
256Index: django/contrib/databrowse/sites.py
257===================================================================
258--- django/contrib/databrowse/sites.py  (revision 6292)
259+++ django/contrib/databrowse/sites.py  (working copy)
260@@ -110,7 +110,7 @@
261 
262         `url` is the remainder of the URL -- e.g. 'comments/comment/'.
263         """
264-        self.root_url = request.path[:len(request.path) - len(url)]
265+        self.root_url = request.full_path[:len(request.full_path) - len(url)]
266         url = url.rstrip('/') # Trim trailing slash, if it exists.
267 
268         if url == '':
269Index: django/contrib/auth/views.py
270===================================================================
271--- django/contrib/auth/views.py        (revision 6292)
272+++ django/contrib/auth/views.py        (working copy)
273@@ -47,7 +47,7 @@
274         return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request))
275     else:
276         # Redirect to this page until the session has been cleared.
277-        return HttpResponseRedirect(next_page or request.path)
278+        return HttpResponseRedirect(next_page or request.full_path)
279 
280 def logout_then_login(request, login_url=None):
281     "Logs out the user if he is logged in. Then redirects to the log-in page."
282@@ -75,7 +75,7 @@
283                 form.save(domain_override=request.META['HTTP_HOST'])
284             else:
285                 form.save(email_template_name=email_template_name)
286-            return HttpResponseRedirect('%sdone/' % request.path)
287+            return HttpResponseRedirect('%sdone/' % request.full_path)
288     return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)},
289         context_instance=RequestContext(request))
290 
291@@ -90,7 +90,7 @@
292         errors = form.get_validation_errors(new_data)
293         if not errors:
294             form.save(new_data)
295-            return HttpResponseRedirect('%sdone/' % request.path)
296+            return HttpResponseRedirect('%sdone/' % request.full_path)
297     return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)},
298         context_instance=RequestContext(request))
299 password_change = login_required(password_change)
300Index: django/contrib/flatpages/views.py
301===================================================================
302--- django/contrib/flatpages/views.py   (revision 6292)
303+++ django/contrib/flatpages/views.py   (working copy)
304@@ -25,7 +25,7 @@
305     # logged in, redirect to the login page.
306     if f.registration_required and not request.user.is_authenticated():
307         from django.contrib.auth.views import redirect_to_login
308-        return redirect_to_login(request.path)
309+        return redirect_to_login(request.full_path)
310     if f.template_name:
311         t = loader.select_template((f.template_name, DEFAULT_TEMPLATE))
312     else:
313Index: django/middleware/common.py
314===================================================================
315--- django/middleware/common.py (revision 6292)
316+++ django/middleware/common.py (working copy)
317@@ -33,7 +33,7 @@
318 
319         # Check for a redirect based on settings.APPEND_SLASH and settings.PREPEND_WWW
320         host = http.get_host(request)
321-        old_url = [host, request.path]
322+        old_url = [host, request.full_path]
323         new_url = old_url[:]
324         if settings.PREPEND_WWW and old_url[0] and not old_url[0].startswith('www.'):
325             new_url[0] = 'www.' + old_url[0]