7 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
5d0a7c6d16
translation: Don't use session for storing lang pref in Django 4.0
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>
2022-06-20 08:15:58 -04:00
Sunil Mohan Adapa
379e0af9c9
translation: Always set language cookie when switching language
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>
2021-10-09 21:03:29 -04:00
Sunil Mohan Adapa
57931353d3
sso, translation: Help set language cookie when user logins in
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>
2021-10-09 21:03:26 -04:00
Sunil Mohan Adapa
9368504da5
*.py: Use SPDX license identifier
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-02-19 14:38:55 +02:00
Sunil Mohan Adapa
54cf2566d8
searx, app, translation, language-selection: Fix license header
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-10-20 11:54:10 -04:00
Sunil Mohan Adapa
1cb7b3210a
locale: Decouple language setting from login views
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>
2018-02-21 21:08:05 +01:00
Sunil Mohan Adapa
90932e78af
locale: Implement utilities for setting/getting language
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>
2018-02-21 21:07:47 +01:00