Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use correct version of Django in GitHub CI actions #7696

Merged
merged 10 commits into from
Nov 20, 2023
9 changes: 0 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ jobs:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12']
requirements-file: [
django-2.2.txt,
django-3.1.txt,
django-3.2.txt,
django-4.0.txt,
django-4.1.txt,
Expand Down Expand Up @@ -52,7 +50,6 @@ jobs:
pip install pytest
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install -r test_requirements/databases.txt
pip install -r docs/requirements.txt
python setup.py install

- name: Test with django test runner
Expand All @@ -69,8 +66,6 @@ jobs:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12']
requirements-file: [
django-2.2.txt,
django-3.1.txt,
django-3.2.txt,
django-4.0.txt,
django-4.1.txt,
Expand Down Expand Up @@ -107,7 +102,6 @@ jobs:
pip install pytest
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install -r test_requirements/databases.txt
pip install -r docs/requirements.txt
python setup.py install


Expand All @@ -124,8 +118,6 @@ jobs:
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12']
requirements-file: [
django-2.2.txt,
django-3.1.txt,
django-3.2.txt,
django-4.0.txt,
django-4.1.txt,
Expand All @@ -149,7 +141,6 @@ jobs:
python -m pip install --upgrade pip
pip install pytest
pip install -r test_requirements/${{ matrix.requirements-file }}
pip install -r docs/requirements.txt
python setup.py install

- name: Test with django test runner
Expand Down
85 changes: 54 additions & 31 deletions cms/middleware/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,62 @@
from django.utils.deprecation import MiddlewareMixin
from django.utils.translation import get_language

from cms.utils.compat import DJANGO_3_0
from cms.utils.compat import DJANGO_2_2

if DJANGO_2_2:
from django.utils.translation import LANGUAGE_SESSION_KEY


class LanguageCookieMiddleware(MiddlewareMixin):
def __init__(self, get_response):
self.get_response = get_response


def __call__(self, request):
response = self.get_response(request)
language = get_language()
if settings.LANGUAGE_COOKIE_NAME in request.COOKIES and \
request.COOKIES[settings.LANGUAGE_COOKIE_NAME] == language:
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

# 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

cookie_kwargs = {
'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,
}
if DJANGO_3_0:
cookie_kwargs.update({
'httponly': settings.LANGUAGE_COOKIE_HTTPONLY,
'samesite': settings.LANGUAGE_COOKIE_SAMESITE,
'secure': settings.LANGUAGE_COOKIE_SECURE,
})

response.set_cookie(
settings.LANGUAGE_COOKIE_NAME,
**cookie_kwargs
)
return response
3 changes: 3 additions & 0 deletions cms/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
URL_CMS_TRANSLATION_DELETE,
CMSTestCase,
)
from cms.utils.compat import DJANGO_2_2
from cms.utils.conf import get_cms_setting
from cms.utils.urlutils import admin_reverse

Expand Down Expand Up @@ -897,6 +898,8 @@ def test_form_errors(self):
response = self.client.post(self.get_admin_url(Page, 'add'), new_page_data)
expected_error = '<ul class="errorlist"><li>Enter a valid “slug” consisting of letters, numbers, ' \
'underscores or hyphens.</li></ul>'
if DJANGO_2_2:
expected_error = expected_error.replace("“", "&#39").replace("”", "&#39")
self.assertEqual(response.status_code, 200)
self.assertContains(response, expected_error, html=True)

Expand Down
2 changes: 1 addition & 1 deletion cms/tests/test_apphooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_apphook_permissions_preserves_view_name(self):
view_names = (
('sample-settings', 'sample_view'),
('sample-class-view', 'ClassView'),
('sample-class-based-view', 'ClassBasedView' ),
('sample-class-based-view', 'view' if not DJANGO_3 else 'ClassBasedView' ),
)

with force_language("en"):
Expand Down
99 changes: 0 additions & 99 deletions cms/tests/test_docs.py

This file was deleted.

2 changes: 1 addition & 1 deletion cms/tests/test_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def test_hide_toolbar_login_nonstaff(self):
def test_admin_logout_staff(self):
with override_settings(CMS_PERMISSION=True):
with self.login_user_context(self.get_staff()):
response = self.client.get('/en/admin/logout/?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
response = self.client.get('/en/admin/logout/')
self.assertEqual(response.status_code, 200)

def test_show_toolbar_without_edit(self):
Expand Down
7 changes: 6 additions & 1 deletion cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse
from django.utils.cache import patch_cache_control
from django.utils.http import url_has_allowed_host_and_scheme

try:
from django.utils.http import url_has_allowed_host_and_scheme # Not available in Django 2.2
except ImportError:
# Django 2.2 only
from django.utils.http import is_safe_url as url_has_allowed_host_and_scheme
from django.utils.timezone import now
from django.utils.translation import get_language_from_request
from django.views.decorators.http import require_POST
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ django CMS Python Django
----------- ----------------------------- ----------------------------------------
\ 3.11 3.10 3.9 3.8 3.7 3.6 3.5 4.2 4.1 4.0 3.2 3.1 3.0 2.2 2.1 2.0 1.11
=========== ==== ==== === === === === === === === === === === === === === === ====
4.1.x ✓ ✓ ✓ × × ✓ ✓ ✓ ✓ ✓ ✓ × × ×
4.1.x ✓ ✓ ✓ × × × × LTS ✓ ✓ LTS × × × × × ×
3.11.3+ ✓ ✓ ✓ ✓ ✓ × × LTS ✓ ✓ LTS × × × × × ×
3.11.1 ✓ ✓ ✓ ✓ ✓ × × × ✓ ✓ ✓ × × × × × ×
3.11.0 ✓ ✓ ✓ ✓ ✓ × × × × ✓ ✓ × × × × × ×
Expand Down
4 changes: 0 additions & 4 deletions test_requirements/django-2.2.txt

This file was deleted.