Changeset 81

Show
Ignore:
Timestamp:
10/15/07 11:43:15 (15 months ago)
Author:
steadicat
Message:

Fixed an indentation error and added a check for backends which set an empty path (e.g. runfcgi).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • django/trunk/middleware/urlmiddleware.py

    r69 r81  
    2323Changelog 
    2424 
     251.3.2 
     26Fixed an indentation issue. Added a check for those backends 
     27which set an empty path (e.g. runfcgi). 
     28 
    25291.3.1 
    26 Added support for running in a test suite (doesn't assume that 
    27 HTTP_HOST is set) 
     30Added support for running in a test 
     31suite (doesn't assume that HTTP_HOST is set) 
    2832 
    29331.3 
     
    4448First release. 
    4549""" 
    46 __version__ = "1.3.1" 
     50__version__ = "1.3.2" 
    4751__license__ = "Python" 
    4852__copyright__ = "Copyright (C) 2006-2007, Stefano J. Attardi" 
     
    6266        # Change the language setting for the current page 
    6367        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"] 
    6670            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 = "/" 
    6875 
    6976        # 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] 
    7178        new_url = old_url[:] 
    7279 
    7380        # 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."): 
    7582            new_url[0] = old_url[0][4:] 
    7683 
    7784        if hasattr(settings, "APPEND_SLASH") and not settings.APPEND_SLASH: 
    7885            # 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]): 
    8087 
    8188                if old_url[1][-1] == "/": 
     
    8794                    new_url[1] = other 
    8895 
    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) 
    95103 
    96104        return None 
     
    100108        # Change the language setting for future pages 
    101109        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"] 
    104112            else: 
    105                 response.set_cookie('django_language', request.GET["lang"]) 
     113                response.set_cookie("django_language", request.GET["lang"]) 
    106114 
    107115        return response