diff options
| author | Claude Paroz <claude@2xlibre.net> | 2017-12-02 13:00:30 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-01-03 11:25:40 -0500 |
| commit | b3cd9fb18ba127c067a4f3c79a32e51c8d8cc6ae (patch) | |
| tree | 9895f2f119b7636d0a8ab1c945745bf97c994bba /django | |
| parent | ccc25bfe4f0964a00df3af6f91c2d9e20159a0c2 (diff) | |
Refs #15902 -- Made set_language() view always set the current language in a cookie.
The plan is to later deprecate/remove storing the language in the session.
Diffstat (limited to 'django')
| -rw-r--r-- | django/views/i18n.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/django/views/i18n.py b/django/views/i18n.py index e121d3038a..1f3170f71f 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -22,9 +22,9 @@ LANGUAGE_QUERY_PARAMETER = 'language' def set_language(request): """ - Redirect to a given URL while setting the chosen language in the session or - cookie. The URL and the language code need to be specified in the request - parameters. + Redirect to a given URL while setting the chosen language in the session + (if enabled) and in a cookie. The URL and the language code need to be + specified in the request parameters. Since this view changes how the user will see the rest of the site, it must only be accessed as a POST request. If called as a GET request, it will @@ -49,13 +49,12 @@ def set_language(request): response = HttpResponseRedirect(next_trans) if hasattr(request, 'session'): request.session[LANGUAGE_SESSION_KEY] = lang_code - else: - response.set_cookie( - settings.LANGUAGE_COOKIE_NAME, lang_code, - max_age=settings.LANGUAGE_COOKIE_AGE, - path=settings.LANGUAGE_COOKIE_PATH, - domain=settings.LANGUAGE_COOKIE_DOMAIN, - ) + response.set_cookie( + settings.LANGUAGE_COOKIE_NAME, lang_code, + max_age=settings.LANGUAGE_COOKIE_AGE, + path=settings.LANGUAGE_COOKIE_PATH, + domain=settings.LANGUAGE_COOKIE_DOMAIN, + ) return response |
