Skip to content

Commit

Permalink
Merge branch 'develop' into fix/django-cmsgh-7654-sideframe-hsitory-n…
Browse files Browse the repository at this point in the history
…av-button-wrap
  • Loading branch information
wesleyboar committed Dec 7, 2023
2 parents 3ab5304 + 63b614d commit 621c76e
Show file tree
Hide file tree
Showing 39 changed files with 286 additions and 340 deletions.
3 changes: 0 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ contact_links:
- name: Question
url: https://www.django-cms.org/en/support/
about: Please use our community channels to ask for questions.
- name: Feature Request
url: https://discourse.django-cms.org/c/feature-requests
about: Please submit and discuss feature requests via discourse forum.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: "3.12"
cache: 'pip'
- name: Cache dependencies
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: "3.12"
cache: 'pip'
- run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-live-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.10'
python-version: '3.12'

- name: Install pypa/build
run: >-
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.10'
python-version: '3.12'

- name: Install pypa/build
run: >-
Expand Down
15 changes: 3 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11']
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 @@ -67,10 +64,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11']
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 @@ -122,10 +116,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '3.8', '3.9', '3.10', '3.11']
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
1 change: 0 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Community & Association
You can join us online:

* in our `django CMS Slack channel <https://www.django-cms.org/slack>`_
* on our `Discourse forum <https://discourse.django-cms.org>`_

You can join a work group and work collaboratively on django CMS

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The demo platform is kindly provided by Divio, platinum member of the django CMS
Getting Help
************

Please head over to our `Slack channel <https://www.django-cms.org/slack>`_ or our `discourse forum <https://discourse.django-cms.org/>`_ for support.
Please head over to our `Slack channel <https://www.django-cms.org/slack>`_ for support.

********************
Professional support
Expand Down
6 changes: 4 additions & 2 deletions cms/admin/pageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,10 @@ def unpublish(self, request, page_id, language):
return HttpResponseRedirect(path)

def delete_translation(self, request, object_id, extra_context=None):
if 'language' in request.GET:
language = request.GET['language']
if 'delete_language' in request.GET:
language = request.GET['delete_language']
elif 'delete_language' in request.POST:
language = request.POST['delete_language']
else:
language = get_language_from_request(request)

Expand Down
8 changes: 7 additions & 1 deletion cms/cache/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ def _get_placeholder_cache_version_key(placeholder, lang, site_id):
lang=str(lang),
site=site_id,
)
if len(key) > 250:
# django itself adds "version" add the end of cache-keys, e.g. "<key>:1".
# -> If `cache.set()` is for example called with `version=""`, it still adds
# `:` at the end. So if we check the length for `> 250`, a length of 249
# or even 250 ends up in an InvalidCacheKey-exception.
# In order to avoid these errors, we hash the keys at a lower length to also
# have a little buffer.
if len(key) > 200:
key = '{prefix}|{hash}'.format(
prefix=prefix,
hash=hashlib.sha1(key.encode('utf-8')).hexdigest(),
Expand Down
3 changes: 1 addition & 2 deletions cms/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
(_("Getting started developer guide"), 'https://docs.django-cms.org/en/latest/introduction/index.html'),
(_("Documentation"), 'https://docs.django-cms.org/en/latest/'),
(_("User guide"), 'https://docs.google.com/document/d/1f5eWyD_sxUSok436fSqDI0NHcpQ88CXQoDoQm9ZXb0s/'),
(_("Support Forum"), 'https://discourse.django-cms.org/'),
(_("Support Slack"), 'https://www.django-cms.org/slack'),
(_("What's new"), 'https://www.django-cms.org/en/blog/'),
)
Expand Down Expand Up @@ -551,7 +550,7 @@ def change_language_menu(self):
)
disabled = len(remove) == 1
for code, name in remove:
url = add_url_parameters(translation_delete_url, language=code)
url = add_url_parameters(translation_delete_url, delete_language=code)
remove_plugins_menu.add_modal_item(name, url=url, disabled=disabled)

if copy:
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
21 changes: 17 additions & 4 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 @@ -196,13 +197,23 @@ def test_delete_translation(self):
create_title("de", "delete-page-translation-2", page, slug="delete-page-translation-2")
create_title("es-mx", "delete-page-translation-es", page, slug="delete-page-translation-es")
with self.login_user_context(admin_user):
response = self.client.get(URL_CMS_TRANSLATION_DELETE % page.pk, {'language': 'de'})
response = self.client.get(URL_CMS_TRANSLATION_DELETE % page.pk, {'delete_language': 'de'})
self.assertEqual(response.status_code, 200)
response = self.client.post(URL_CMS_TRANSLATION_DELETE % page.pk, {'language': 'de'})
self.assertContains(
response,
'Are you sure you want to delete the title "delete-page-translation-2 (delete-page-translation-2, de)"?'
)
response = self.client.get(URL_CMS_TRANSLATION_DELETE % page.pk + "?delete_language=de&cms_path=/en/?edit&language=en")
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
'Are you sure you want to delete the title "delete-page-translation-2 (delete-page-translation-2, de)"?'
)
response = self.client.post(URL_CMS_TRANSLATION_DELETE % page.pk, {'delete_language': 'de'})
self.assertRedirects(response, URL_CMS_PAGE)
response = self.client.get(URL_CMS_TRANSLATION_DELETE % page.pk, {'language': 'es-mx'})
response = self.client.get(URL_CMS_TRANSLATION_DELETE % page.pk, {'delete_language': 'es-mx'})
self.assertEqual(response.status_code, 200)
response = self.client.post(URL_CMS_TRANSLATION_DELETE % page.pk, {'language': 'es-mx'})
response = self.client.post(URL_CMS_TRANSLATION_DELETE % page.pk, {'delete_language': 'es-mx'})
self.assertRedirects(response, URL_CMS_PAGE)

def test_change_dates(self):
Expand Down Expand Up @@ -887,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
4 changes: 2 additions & 2 deletions cms/tests/test_apphooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from cms.test_utils.testcases import CMSTestCase
from cms.tests.test_menu_utils import DumbPageLanguageUrl
from cms.toolbar.toolbar import CMSToolbar
from cms.utils.compat import DJANGO_2_2, DJANGO_3
from cms.utils.compat import DJANGO_2_2, DJANGO_3, DJANGO_4_1
from cms.utils.conf import get_cms_setting
from cms.utils.urlutils import admin_reverse
from menus.menu_pool import menu_pool
Expand Down 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', 'view' if not (DJANGO_3 or DJANGO_2_2) else 'ClassBasedView' ),
('sample-class-based-view', 'view' if not DJANGO_3 else 'ClassBasedView' ),
)

with force_language("en"):
Expand Down
Loading

0 comments on commit 621c76e

Please sign in to comment.