Django

Code

Changeset 6177

Show
Ignore:
Timestamp:
09/14/07 02:33:45 (8 months ago)
Author:
mtredinnick
Message:

Fixed #3651 -- Changed set_language_view() to require POST request is used, in accordance with the HTTP spec (it changes the user's state). Thanks, Fraser Nevett.

This is a backwards incompatible change for anybody previously using this view.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/views/i18n.py

    r5849 r6177  
    1010    Redirect to a given url while setting the chosen language in the 
    1111    session or cookie. The url and the language code need to be 
    12     specified in the GET parameters. 
     12    specified in the request parameters. 
     13 
     14    Since this view changes how the user will see the rest of the site, it must 
     15    only be accessed as a POST request. If called as a GET request, it will 
     16    redirect to the page in the request (the 'next' parameter) without changing 
     17    any state. 
    1318    """ 
    14     lang_code = request.GET.get('language', None) 
    1519    next = request.GET.get('next', None) 
    1620    if not next: 
     
    1923        next = '/' 
    2024    response = http.HttpResponseRedirect(next) 
    21     if lang_code and check_for_language(lang_code): 
    22         if hasattr(request, 'session'): 
    23             request.session['django_language'] = lang_code 
    24         else: 
    25             response.set_cookie('django_language', lang_code) 
     25    if request.method == 'POST': 
     26        lang_code = request.POST.get('language', None) 
     27        if lang_code and check_for_language(lang_code): 
     28            if hasattr(request, 'session'): 
     29                request.session['django_language'] = lang_code 
     30            else: 
     31                response.set_cookie('django_language', lang_code) 
    2632    return response 
    2733