Changeset 81
- Timestamp:
- 10/15/07 11:43:15 (15 months ago)
- Files:
-
- 1 modified
-
django/trunk/middleware/urlmiddleware.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
django/trunk/middleware/urlmiddleware.py
r69 r81 23 23 Changelog 24 24 25 1.3.2 26 Fixed an indentation issue. Added a check for those backends 27 which set an empty path (e.g. runfcgi). 28 25 29 1.3.1 26 Added support for running in a test suite (doesn't assume that27 HTTP_HOST is set)30 Added support for running in a test 31 suite (doesn't assume that HTTP_HOST is set) 28 32 29 33 1.3 … … 44 48 First release. 45 49 """ 46 __version__ = "1.3. 1"50 __version__ = "1.3.2" 47 51 __license__ = "Python" 48 52 __copyright__ = "Copyright (C) 2006-2007, Stefano J. Attardi" … … 62 66 # Change the language setting for the current page 63 67 if "lang" in request.GET and check_for_language(request.GET["lang"]): 64 if hasattr(request, 'session'):65 request.session[ 'django_language'] = request.GET["lang"]68 if hasattr(request, "session"): 69 request.session["django_language"] = request.GET["lang"] 66 70 else: 67 request.COOKIES['django_language'] = request.GET["lang"] 71 request.COOKIES["django_language"] = request.GET["lang"] 72 73 # work-around for runfcgi 74 if request.path == "": request.path = "/" 68 75 69 76 # Check for a redirect based on settings.APPEND_SLASH and settings.PREPEND_WWW 70 old_url = [request.META.get( 'HTTP_HOST', 'localhost'), request.path]77 old_url = [request.META.get("HTTP_HOST", "localhost"), request.path] 71 78 new_url = old_url[:] 72 79 73 80 # if REMOVE_WWW is True, remove the www. from the urls if necessary 74 if hasattr(settings, "REMOVE_WWW") and settings.REMOVE_WWW and old_url[0].startswith( 'www.'):81 if hasattr(settings, "REMOVE_WWW") and settings.REMOVE_WWW and old_url[0].startswith("www."): 75 82 new_url[0] = old_url[0][4:] 76 83 77 84 if hasattr(settings, "APPEND_SLASH") and not settings.APPEND_SLASH: 78 85 # if the url is not found, try with(out) the trailing slash 79 if not self._urlExists(old_url[1]):86 if old_url[1] != "/" and not self._urlExists(old_url[1]): 80 87 81 88 if old_url[1][-1] == "/": … … 87 94 new_url[1] = other 88 95 89 if new_url != old_url: 90 # Redirect 91 newurl = "%s://%s%s" % (os.environ.get('HTTPS') == 'on' and 'https' or 'http', new_url[0], new_url[1]) 92 if request.GET: 93 newurl += '?' + request.GET.urlencode() 94 return HttpResponseRedirect(newurl) 96 if new_url != old_url: 97 # Redirect 98 newurl = "%s://%s%s" % (os.environ.get("HTTPS") == "on" and "https" or "http", new_url[0], new_url[1]) 99 if request.GET: 100 newurl += "?" + request.GET.urlencode() 101 102 return HttpResponseRedirect(newurl) 95 103 96 104 return None … … 100 108 # Change the language setting for future pages 101 109 if "lang" in request.GET and check_for_language(request.GET["lang"]): 102 if 'sessionid'in request.COOKIES:103 request.session[ 'django_language'] = request.GET["lang"]110 if "sessionid" in request.COOKIES: 111 request.session["django_language"] = request.GET["lang"] 104 112 else: 105 response.set_cookie( 'django_language', request.GET["lang"])113 response.set_cookie("django_language", request.GET["lang"]) 106 114 107 115 return response