Ticket #285: script_name_path_info4.diff
File script_name_path_info4.diff, 20.1 KB (added by , 17 years ago) |
---|
-
django/http/__init__.py
26 26 def __init__(self): 27 27 self.GET, self.POST, self.COOKIES, self.META, self.FILES = {}, {}, {}, {}, {} 28 28 self.path = '' 29 self.full_path = '' 29 30 self.method = None 30 31 31 32 def __repr__(self): … … 71 72 location = self.get_full_path() 72 73 if not ':' in location: 73 74 current_uri = '%s://%s%s' % (self.is_secure() and 'https' or 'http', 74 self.get_host(), self. path)75 self.get_host(), self.full_path) 75 76 location = urljoin(current_uri, location) 76 77 return location 77 78 -
django/test/client.py
151 151 'PATH_INFO': '/', 152 152 'QUERY_STRING': '', 153 153 'REQUEST_METHOD': 'GET', 154 'SCRIPT_NAME': None,154 'SCRIPT_NAME': '', 155 155 'SERVER_NAME': 'testserver', 156 156 'SERVER_PORT': 80, 157 157 'SERVER_PROTOCOL': 'HTTP/1.1', -
django/core/handlers/wsgi.py
75 75 class WSGIRequest(http.HttpRequest): 76 76 def __init__(self, environ): 77 77 self.environ = environ 78 self.path = force_unicode(environ['PATH_INFO']) 78 self.path = force_unicode(environ.get('PATH_INFO', '/')) 79 self.full_path = (force_unicode(environ.get('SCRIPT_NAME', '')) 80 + force_unicode(environ.get('PATH_INFO', '/'))) 79 81 self.META = environ 82 self.META['PATH_INFO'] = self.path 83 self.META['SCRIPT_NAME'] = force_unicode(environ.get('SCRIPT_NAME', '')) 80 84 self.method = environ['REQUEST_METHOD'].upper() 81 85 82 86 def __repr__(self): … … 102 106 (get, post, cookies, meta) 103 107 104 108 def get_full_path(self): 105 return '%s%s' % (self. path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '')109 return '%s%s' % (self.full_path, self.environ.get('QUERY_STRING', '') and ('?' + self.environ.get('QUERY_STRING', '')) or '') 106 110 107 111 def is_secure(self): 108 112 return 'HTTPS' in self.environ and self.environ['HTTPS'] == 'on' -
django/core/handlers/modpython.py
14 14 class ModPythonRequest(http.HttpRequest): 15 15 def __init__(self, req): 16 16 self._req = req 17 self.path = force_unicode(req.uri) 17 self.full_path = force_unicode(req.uri) 18 root = req.get_options().get('django.root', '') 19 self._django_root = force_unicode(root) 20 if root and req.uri.startswith(root): 21 self.path = force_unicode(req.uri[len(root):]) 22 else: 23 self.path = self.full_path 18 24 19 25 def __repr__(self): 20 26 # Since this is called as part of error handling, we need to be very … … 39 45 (self.path, get, post, cookies, meta) 40 46 41 47 def get_full_path(self): 42 return '%s%s' % (self. path, self._req.args and ('?' + self._req.args) or '')48 return '%s%s' % (self.full_path, self._req.args and ('?' + self._req.args) or '') 43 49 44 50 def is_secure(self): 45 51 # Note: modpython 3.2.10+ has req.is_https(), but we need to support previous versions … … 94 100 'CONTENT_LENGTH': self._req.clength, # This may be wrong 95 101 'CONTENT_TYPE': self._req.content_type, # This may be wrong 96 102 'GATEWAY_INTERFACE': 'CGI/1.1', 97 'PATH_INFO': self. _req.path_info,103 'PATH_INFO': self.path, 98 104 'PATH_TRANSLATED': None, # Not supported 99 105 'QUERY_STRING': self._req.args, 100 106 'REMOTE_ADDR': self._req.connection.remote_ip, … … 102 108 'REMOTE_IDENT': self._req.connection.remote_logname, 103 109 'REMOTE_USER': self._req.user, 104 110 'REQUEST_METHOD': self._req.method, 105 'SCRIPT_NAME': None, # Not supported111 'SCRIPT_NAME': self._django_root, 106 112 'SERVER_NAME': self._req.server.server_hostname, 107 113 'SERVER_PORT': self._req.server.port, 108 114 'SERVER_PROTOCOL': self._req.protocol, -
django/views/generic/create_update.py
21 21 """ 22 22 if extra_context is None: extra_context = {} 23 23 if login_required and not request.user.is_authenticated(): 24 return redirect_to_login(request. path)24 return redirect_to_login(request.full_path) 25 25 26 26 manipulator = model.AddManipulator(follow=follow) 27 27 if request.POST: … … 87 87 """ 88 88 if extra_context is None: extra_context = {} 89 89 if login_required and not request.user.is_authenticated(): 90 return redirect_to_login(request. path)90 return redirect_to_login(request.full_path) 91 91 92 92 # Look up the object to be edited 93 93 lookup_kwargs = {} … … 163 163 """ 164 164 if extra_context is None: extra_context = {} 165 165 if login_required and not request.user.is_authenticated(): 166 return redirect_to_login(request. path)166 return redirect_to_login(request.full_path) 167 167 168 168 # Look up the object to be edited 169 169 lookup_kwargs = {} -
django/views/debug.py
345 345 </tr> 346 346 <tr> 347 347 <th>Request URL:</th> 348 <td>{{ request_protocol }}://{{ request. META.HTTP_HOST }}{{ request.path|escape }}</td>348 <td>{{ request_protocol }}://{{ request.get_host }}{{ request.full_path|escape }}</td> 349 349 </tr> 350 350 <tr> 351 351 <th>Exception Type:</th> … … 634 634 </tr> 635 635 <tr> 636 636 <th>Request URL:</th> 637 <td>{{ request_protocol }}://{{ request. META.HTTP_HOST }}{{ request.path|escape }}</td>637 <td>{{ request_protocol }}://{{ request.get_host }}{{ request.full_path|escape }}</td> 638 638 </tr> 639 639 </table> 640 640 </div> -
django/contrib/syndication/feeds.py
25 25 def __init__(self, slug, request): 26 26 self.slug = slug 27 27 self.request = request 28 self.feed_url = request. path28 self.feed_url = request.full_path 29 29 self.title_template_name = self.title_template or ('feeds/%s_title.html' % slug) 30 30 self.description_template_name = self.description_template or ('feeds/%s_description.html' % slug) 31 31 -
django/contrib/comments/views/userflags.py
19 19 comment = get_object_or_404(Comment,pk=comment_id, site__id__exact=settings.SITE_ID) 20 20 if request.POST: 21 21 UserFlag.objects.flag(comment, request.user) 22 return HttpResponseRedirect('%sdone/' % request. path)22 return HttpResponseRedirect('%sdone/' % request.full_path) 23 23 return render_to_response('comments/flag_verify.html', {'comment': comment}, 24 24 context_instance=RequestContext(request, extra_context, context_processors)) 25 25 flag = login_required(flag) … … 50 50 comment.save() 51 51 m = ModeratorDeletion(None, request.user.id, comment.id, None) 52 52 m.save() 53 return HttpResponseRedirect('%sdone/' % request. path)53 return HttpResponseRedirect('%sdone/' % request.full_path) 54 54 return render_to_response('comments/delete_verify.html', {'comment': comment}, 55 55 context_instance=RequestContext(request, extra_context, context_processors)) 56 56 delete = login_required(delete) -
django/contrib/admin/views/auth.py
20 20 msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': 'user', 'obj': new_user} 21 21 if "_addanother" in request.POST: 22 22 request.user.message_set.create(message=msg) 23 return HttpResponseRedirect(request. path)23 return HttpResponseRedirect(request.full_path) 24 24 else: 25 25 request.user.message_set.create(message=msg + ' ' + _("You may edit it again below.")) 26 26 return HttpResponseRedirect('../%s/' % new_user.id) -
django/contrib/admin/views/main.py
276 276 (pk_value, force_unicode(new_object).replace('"', '\\"'))) 277 277 elif "_addanother" in request.POST: 278 278 request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name))) 279 return HttpResponseRedirect(request. path)279 return HttpResponseRedirect(request.full_path) 280 280 else: 281 281 request.user.message_set.create(message=msg) 282 282 return HttpResponseRedirect(post_url) … … 353 353 if "_continue" in request.POST: 354 354 request.user.message_set.create(message=msg + ' ' + _("You may edit it again below.")) 355 355 if '_popup' in request.REQUEST: 356 return HttpResponseRedirect(request. path + "?_popup=1")356 return HttpResponseRedirect(request.full_path + "?_popup=1") 357 357 else: 358 return HttpResponseRedirect(request. path)358 return HttpResponseRedirect(request.full_path) 359 359 elif "_saveasnew" in request.POST: 360 360 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)}) 361 361 return HttpResponseRedirect("../%s/" % pk_value) … … 778 778 # is screwed up with the database, so display an error page. 779 779 if ERROR_FLAG in request.GET.keys(): 780 780 return render_to_response('admin/invalid_setup.html', {'title': _('Database error')}) 781 return HttpResponseRedirect(request. path + '?' + ERROR_FLAG + '=1')781 return HttpResponseRedirect(request.full_path + '?' + ERROR_FLAG + '=1') 782 782 c = template.RequestContext(request, { 783 783 'title': cl.title, 784 784 'is_popup': cl.is_popup, -
django/contrib/admin/views/decorators.py
22 22 post_data = _encode_post_data({}) 23 23 return render_to_response('admin/login.html', { 24 24 'title': _('Log in'), 25 'app_path': request. path,25 'app_path': request.full_path, 26 26 'post_data': post_data, 27 27 'error_message': error_message 28 28 }, context_instance=template.RequestContext(request)) … … 99 99 return view_func(request, *args, **kwargs) 100 100 else: 101 101 request.session.delete_test_cookie() 102 return http.HttpResponseRedirect(request. path)102 return http.HttpResponseRedirect(request.full_path) 103 103 else: 104 104 return _display_login_form(request, ERROR_MESSAGE) 105 105 -
django/contrib/admin/views/doc.py
27 27 28 28 def bookmarklets(request): 29 29 # Hack! This couples this view to the URL it lives at. 30 admin_root = request. path[:-len('doc/bookmarklets/')]30 admin_root = request.full_path[:-len('doc/bookmarklets/')] 31 31 return render_to_response('admin_doc/bookmarklets.html', { 32 32 'admin_url': "%s://%s%s" % (request.is_secure() and 'https' or 'http', request.get_host(), admin_root), 33 33 }, context_instance=RequestContext(request)) -
django/contrib/databrowse/plugins/objects.py
8 8 def model_view(self, request, model_databrowse, url): 9 9 # If the object ID wasn't provided, redirect to the model page, which is one level up. 10 10 if url is None: 11 return http.HttpResponseRedirect(urlparse.urljoin(request. path, '../'))11 return http.HttpResponseRedirect(urlparse.urljoin(request.full_path, '../')) 12 12 easy_model = EasyModel(model_databrowse.site, model_databrowse.model) 13 13 obj = easy_model.object_by_pk(url) 14 14 return render_to_response('databrowse/object_detail.html', {'object': obj, 'root_url': model_databrowse.site.root_url}) -
django/contrib/databrowse/sites.py
110 110 111 111 `url` is the remainder of the URL -- e.g. 'comments/comment/'. 112 112 """ 113 self.root_url = request. path[:len(request.path) - len(url)]113 self.root_url = request.full_path[:len(request.full_path) - len(url)] 114 114 url = url.rstrip('/') # Trim trailing slash, if it exists. 115 115 116 116 if url == '': -
django/contrib/auth/views.py
47 47 return render_to_response(template_name, {'title': _('Logged out')}, context_instance=RequestContext(request)) 48 48 else: 49 49 # Redirect to this page until the session has been cleared. 50 return HttpResponseRedirect(next_page or request. path)50 return HttpResponseRedirect(next_page or request.full_path) 51 51 52 52 def logout_then_login(request, login_url=None): 53 53 "Logs out the user if he is logged in. Then redirects to the log-in page." … … 75 75 form.save(domain_override=request.META['HTTP_HOST']) 76 76 else: 77 77 form.save(email_template_name=email_template_name) 78 return HttpResponseRedirect('%sdone/' % request. path)78 return HttpResponseRedirect('%sdone/' % request.full_path) 79 79 return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)}, 80 80 context_instance=RequestContext(request)) 81 81 … … 90 90 errors = form.get_validation_errors(new_data) 91 91 if not errors: 92 92 form.save(new_data) 93 return HttpResponseRedirect('%sdone/' % request. path)93 return HttpResponseRedirect('%sdone/' % request.full_path) 94 94 return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)}, 95 95 context_instance=RequestContext(request)) 96 96 password_change = login_required(password_change) -
django/contrib/flatpages/views.py
25 25 # logged in, redirect to the login page. 26 26 if f.registration_required and not request.user.is_authenticated(): 27 27 from django.contrib.auth.views import redirect_to_login 28 return redirect_to_login(request. path)28 return redirect_to_login(request.full_path) 29 29 if f.template_name: 30 30 t = loader.select_template((f.template_name, DEFAULT_TEMPLATE)) 31 31 else: -
django/middleware/common.py
33 33 34 34 # Check for a redirect based on settings.APPEND_SLASH and settings.PREPEND_WWW 35 35 host = request.get_host() 36 old_url = [host, request. path]36 old_url = [host, request.full_path] 37 37 new_url = old_url[:] 38 38 if settings.PREPEND_WWW and old_url[0] and not old_url[0].startswith('www.'): 39 39 new_url[0] = 'www.' + old_url[0] -
AUTHORS
319 319 ymasuda@ethercube.com 320 320 Jarek Zgoda <jarek.zgoda@gmail.com> 321 321 Cheng Zhang 322 John Melesky 322 323 323 324 A big THANK YOU goes to: 324 325 -
docs/request_response.txt
24 24 All attributes except ``session`` should be considered read-only. 25 25 26 26 ``path`` 27 A string representing the path to the requested page relative to 28 the Django root, not including the domain. For WSGI servers, this 29 means it does not include SCRIPT_NAME. For mod_python servers, 30 this does not include the user-configurable django.root 31 PythonOption. 32 33 Example: ``"/bands/the_beatles/"`` 34 35 ``full_path`` 27 36 A string representing the full path to the requested page, not including 28 37 the domain. 29 38 … … 112 121 * ``REQUEST_METHOD`` -- A string such as ``"GET"`` or ``"POST"``. 113 122 * ``SERVER_NAME`` -- The hostname of the server. 114 123 * ``SERVER_PORT`` -- The port of the server. 124 * ``SCRIPT_NAME`` -- The location of the Django app (e.g. "/mysite") 115 125 116 126 ``user`` 117 127 A ``django.contrib.auth.models.User`` object representing the currently … … 157 167 ``request.POST`` has the given key. 158 168 159 169 ``get_full_path()`` 160 Returns the `` path``, plus an appended query string, if applicable.170 Returns the ``full_path``, plus an appended query string, if applicable. 161 171 162 172 Example: ``"/music/bands/the_beatles/?print=true"`` 163 173 -
docs/modpython.txt
36 36 PythonHandler django.core.handlers.modpython 37 37 SetEnv DJANGO_SETTINGS_MODULE mysite.settings 38 38 PythonDebug On 39 PythonOption django.root /mysite 39 40 </Location> 40 41 41 42 ...and replace ``mysite.settings`` with the Python import path to your Django … … 45 46 Django mod_python handler." It passes the value of ``DJANGO_SETTINGS_MODULE`` 46 47 so mod_python knows which settings to use. 47 48 49 The PythonOption tells Django: "Pass all requests through to the application as 50 if they were rooted at '/', but generate absolute URLs under '/mysite'." This 51 way, Django applications can be installed in any subdirectory URL without 52 having the full path hardwired in. 53 48 54 Note that we're using the ``<Location>`` directive, not the ``<Directory>`` 49 55 directive. The latter is used for pointing at places on your filesystem, 50 56 whereas ``<Location>`` points at places in the URL structure of a Web site. … … 60 66 PythonHandler django.core.handlers.modpython 61 67 SetEnv DJANGO_SETTINGS_MODULE mysite.settings 62 68 PythonDebug On 69 PythonOption django.root /mysite 63 70 **PythonPath "['/path/to/project'] + sys.path"** 64 71 </Location> 65 72