Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Django 42 upgrade changes * Added changelog * Updated test.yml to exclude django 3.1 and below * Added readthedocs and pillow pinned=9.5.0 * removed python 3.7 and added 3.10 * fix: workflow and django 4.2 compatibility issues * fix: remove useless * fix: fix PR errors * fix: fix typo * Removed LanguagesessionKEY * fix: restore 'default_app_config' * fix: failing tests * fix: update pip requirement * fix: failing tests * updated path from re_path in settingsadmin * removed unused import * updated regular expression * Update settingsadmin.py --------- Co-authored-by: Josh Peng Yu <joshyu@users.noreply.github.com>
- Loading branch information
1 parent
0059b95
commit 16e260b
Showing
73 changed files
with
279 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Read the Docs configuration file | ||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details | ||
version: 2 | ||
|
||
build: | ||
os: ubuntu-22.04 | ||
tools: | ||
python: "3.9" | ||
|
||
sphinx: | ||
configuration: docs/conf.py | ||
fail_on_warning: false | ||
|
||
formats: | ||
- epub | ||
|
||
python: | ||
install: | ||
- requirements: docs/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,63 @@ | ||
import datetime | ||
|
||
from django.utils.translation import LANGUAGE_SESSION_KEY, get_language | ||
from django.conf import settings | ||
from django.utils.deprecation import MiddlewareMixin | ||
from django.utils.translation import get_language | ||
|
||
from cms.utils.compat import DJANGO_2_2 | ||
|
||
if DJANGO_2_2: | ||
from django.utils.translation import LANGUAGE_SESSION_KEY | ||
|
||
|
||
class LanguageCookieMiddleware(MiddlewareMixin): | ||
def process_response(self, request, response): | ||
language = get_language() | ||
if hasattr(request, 'session'): | ||
session_language = request.session.get(LANGUAGE_SESSION_KEY, None) | ||
if session_language and not session_language == language: | ||
request.session[LANGUAGE_SESSION_KEY] = language | ||
request.session.save() | ||
if settings.LANGUAGE_COOKIE_NAME in request.COOKIES and \ | ||
request.COOKIES[settings.LANGUAGE_COOKIE_NAME] == language: | ||
def __init__(self, get_response): | ||
super().__init__(get_response) | ||
|
||
if DJANGO_2_2: | ||
|
||
def __call__(self, request): | ||
response = self.get_response(request) | ||
language = get_language() | ||
if hasattr(request, 'session'): | ||
session_language = request.session.get(LANGUAGE_SESSION_KEY, None) | ||
if session_language and not session_language == language: | ||
request.session[LANGUAGE_SESSION_KEY] = language | ||
request.session.save() | ||
if ( | ||
settings.LANGUAGE_COOKIE_NAME in request.COOKIES | ||
and request.COOKIES[settings.LANGUAGE_COOKIE_NAME] == language # noqa: W503 | ||
): | ||
return response | ||
response.set_cookie( | ||
settings.LANGUAGE_COOKIE_NAME, | ||
value=language, | ||
domain=settings.LANGUAGE_COOKIE_DOMAIN, | ||
max_age=settings.LANGUAGE_COOKIE_AGE or 365 * 24 * 60 * 60, # 1 year | ||
path=settings.LANGUAGE_COOKIE_PATH, | ||
) | ||
return response | ||
else: | ||
|
||
def __call__(self, request): | ||
response = self.get_response(request) | ||
language = get_language() | ||
if ( | ||
settings.LANGUAGE_COOKIE_NAME in request.COOKIES # noqa: W503 | ||
and request.COOKIES[settings.LANGUAGE_COOKIE_NAME] == language | ||
): | ||
return response | ||
|
||
# To ensure support of very old browsers, Django processed automatically "expires" according | ||
# to max_age value. | ||
# https://docs.djangoproject.com/en/3.2/ref/request-response/#django.http.HttpResponse.set_cookie | ||
|
||
response.set_cookie( | ||
settings.LANGUAGE_COOKIE_NAME, | ||
value=language, | ||
domain=settings.LANGUAGE_COOKIE_DOMAIN, | ||
max_age=settings.LANGUAGE_COOKIE_AGE or 365 * 24 * 60 * 60, # 1 year | ||
httponly=settings.LANGUAGE_COOKIE_HTTPONLY, | ||
path=settings.LANGUAGE_COOKIE_PATH, | ||
samesite=settings.LANGUAGE_COOKIE_SAMESITE, | ||
secure=settings.LANGUAGE_COOKIE_SECURE, | ||
) | ||
return response | ||
max_age = 365 * 24 * 60 * 60 # 10 years | ||
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=max_age) | ||
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, language, expires=expires) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.