Helps: #2228.
- In Django 3.0, storing language preference in session key is deprecated and
only the language cookie is used. In Django 4.0, this functionality is
completely removed along with the constant LANGUAGE_SESSION_KEY.
- Debian stable (Bullseye) uses Django 2.2 and this depends on code to store
language preference in session key. To work on Django 2.2 through 4.0, check if
the constant is available and then set the session key of the constant is found.
Tests:
- Change language in user edit page and see that it is persisted.
- After logout, the new language is still set.
- Changing language as anonymous user works.
- Run tests in stable, testing and unstable containers.
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
Django 3.0 will now always set the language cookie. It will stop setting the
session language in Django 4.0. To avoid breaking current behavior, always set
the language cookie when switching language.
"To limit creation of sessions and hence favor some caching strategies,
django.views.i18n.set_language() will stop setting the user’s language in the
session in Django 4.0. Since Django 2.1, the language is always stored in the
LANGUAGE_COOKIE_NAME cookie."
Tests:
- All relevant functional tests run.
- Repeat login and user page editing tests.
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This patch only ensures that response object is send along with set_language()
call. In later changes, response object can be used by set_language() to set the
language cookie.
Tests:
- Relevant functional tests pass.
- Login, user's language is set when the language is set to non-browser sent
language.
- Logout, user's language is retained when set to non-browser sent language.
- Login, user's language is set when the language is set to browser sent
language.
- Logout, user's language is retained when set to browser sent language.
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
Use the user_logged_in signal provided by Django to log the user in. This keeps
the login code simple and uncluttered.
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
Separate language cookie are only used if sessions (session middleware) are not
available. Otherwise, even anonymous users have their language preference in
sessions instead of cookies. This is default Django behavior, conform to it.
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>