Skip to content

Commit aab0417

Browse files
authored
Merge branch 'master' into feat/improve_default_copy
2 parents db7666a + bf89036 commit aab0417

File tree

13 files changed

+95
-36
lines changed

13 files changed

+95
-36
lines changed

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
python-version: '3.11'
2020
cache: 'pip'
2121
- name: Cache dependencies
22-
uses: actions/cache@v4.2.0
22+
uses: actions/cache@v4.2.2
2323
with:
2424
path: ~/.cache/pip
2525
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
@@ -44,7 +44,7 @@ jobs:
4444
python-version: '3.11'
4545
cache: 'pip'
4646
- name: Cache dependencies
47-
uses: actions/cache@v4.2.0
47+
uses: actions/cache@v4.2.2
4848
with:
4949
path: ~/.cache/pip
5050
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
strategy:
150150
fail-fast: false
151151
matrix:
152-
python-version: ['3.11']
152+
python-version: ['3.12']
153153
requirements-file: ['dj51_cms41.txt']
154154
cms-version: [
155155
'https://github.com/django-cms/django-cms/archive/develop-4.tar.gz'
@@ -183,7 +183,7 @@ jobs:
183183
strategy:
184184
fail-fast: false
185185
matrix:
186-
python-version: [ "3.11" ]
186+
python-version: [ "3.12" ]
187187
cms-version: [
188188
'https://github.com/django-cms/django-cms/archive/develop-4.tar.gz'
189189
]

CHANGELOG.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22
Changelog
33
=========
44

5+
2.2.0 (2025-01-17)
6+
==================
7+
8+
* feat: Added bulk delete to version change view by @polyccon in https://github.com/django-cms/djangocms-versioning/pull/338
9+
* feat: Re-introduce deleting languages of a page by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/443
10+
* feat: Autocomplete fields for grouper selection and option for less verbose UI by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/433
11+
* fix: Unpublished or archived versions not shown in language menu by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/440
12+
* fix: add resolvability check before redirecting to prevent insecure redirects after publishing by @theShinigami in https://github.com/django-cms/djangocms-versioning/pull/436
13+
* fix: test.pypi.org workflow environment name by @marksweb in https://github.com/django-cms/djangocms-versioning/pull/434
14+
* fix: attempt to remove missing item from list by @jrief in https://github.com/django-cms/djangocms-versioning/pull/439
15+
* fix: Take csrf token from CMS config if possible by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/444
16+
* build(deps): bump codecov/codecov-action from 4 to 5 by @dependabot in https://github.com/django-cms/djangocms-versioning/pull/435
17+
* build(deps): bump actions/cache from 4.0.2 to 4.1.2 by @dependabot in https://github.com/django-cms/djangocms-versioning/pull/431
18+
* build(deps): bump actions/cache from 4.1.2 to 4.2.0 by @dependabot in https://github.com/django-cms/djangocms-versioning/pull/438
19+
20+
**New Contributors**
21+
22+
* @polyccon made their first contribution in https://github.com/django-cms/djangocms-versioning/pull/338
23+
* @theShinigami made their first contribution in https://github.com/django-cms/djangocms-versioning/pull/436
24+
525
2.1.0 (2024-07-12)
626
==================
727

djangocms_versioning/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.1.0"
1+
__version__ = "2.2.0"

djangocms_versioning/cms_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import collections
22

3+
from cms import __version__ as cms_version
34
from cms.app_base import CMSAppConfig, CMSAppExtension
45
from cms.extensions.models import BaseExtension
56
from cms.models import PageContent, Placeholder
@@ -22,6 +23,7 @@
2223
from django.utils.encoding import force_str
2324
from django.utils.functional import cached_property
2425
from django.utils.translation import gettext_lazy as _
26+
from packaging.version import Version as PackageVersion
2527

2628
from . import indicators
2729
from .admin import VersioningAdminMixin
@@ -393,6 +395,7 @@ class VersioningCMSConfig(CMSAppConfig):
393395
content_admin_mixin=VersioningCMSPageAdminMixin,
394396
)
395397
]
396-
cms_toolbar_mixin = CMSToolbarVersioningMixin
398+
if PackageVersion(cms_version) < PackageVersion("4.2"):
399+
cms_toolbar_mixin = CMSToolbarVersioningMixin
397400
PageContent.add_to_class("is_editable", is_editable)
398401
PageContent.add_to_class("content_indicator", indicators.content_indicator)

djangocms_versioning/cms_toolbars.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from cms.cms_toolbars import (
77
ADD_PAGE_LANGUAGE_BREAK,
88
LANGUAGE_MENU_IDENTIFIER,
9+
BasicToolbar,
910
PageToolbar,
1011
PlaceholderToolbar,
1112
)
@@ -242,7 +243,7 @@ def _get_published_page_version(self):
242243

243244
return PageContent._original_manager.filter(
244245
page=self.page, language=language, versions__state=PUBLISHED
245-
).first()
246+
).select_related("page").first()
246247

247248
def _add_view_published_button(self):
248249
"""Helper method to add a publish button to the toolbar
@@ -320,7 +321,6 @@ def populate(self):
320321
self.page_content = self.get_page_content() if self.page else None
321322
self.permissions_activated = get_cms_setting("PERMISSION")
322323

323-
self.override_language_menu()
324324
self.change_admin_menu()
325325
self.add_page_menu()
326326
self.change_language_menu()
@@ -401,8 +401,9 @@ def change_language_menu(self):
401401
url = add_url_parameters(translation_delete_url, language=code)
402402
on_close = REFRESH_PAGE
403403
if self.toolbar.get_object() == pagecontent and not disabled:
404-
other_content = next((self.page.get_admin_content(lang)for lang in self.page.get_languages()
405-
if lang != pagecontent.language and lang in languages), None)
404+
other_content = next(
405+
(self.page.get_admin_content(lang) for lang in self.page.get_languages()
406+
if lang != pagecontent.language and lang in languages), None)
406407
on_close = get_object_preview_url(other_content)
407408
remove_plugins_menu.add_modal_item(name, url=url, disabled=disabled, on_close=on_close)
408409

@@ -432,10 +433,31 @@ def change_language_menu(self):
432433
)
433434

434435

436+
class VersioningBasicToolbar(BasicToolbar):
437+
def add_language_menu(self):
438+
"""
439+
Originally did override the default language menu for pages that are versioned.
440+
Now creates the menu from scratch, since VersiongBasicToolbar prevents the
441+
core from creating the too generic default language menu.
442+
"""
443+
if not settings.USE_I18N or not self.request.current_page:
444+
# Only add if no page is shown
445+
super().add_language_menu()
446+
return
447+
448+
language_menu = self.toolbar.get_or_create_menu(
449+
LANGUAGE_MENU_IDENTIFIER, _("Language"), position=-1
450+
)
451+
for code, name in get_language_tuple(self.current_site.pk):
452+
# Get the page content, it could be draft too!
453+
page_content = self.page.get_admin_content(language=code)
454+
if page_content:
455+
url = get_object_preview_url(page_content, code)
456+
language_menu.add_link_item(name, url=url, active=self.current_lang == code)
457+
458+
435459
def replace_toolbar(old, new):
436-
"""Replace `old` toolbar class with `new` class,
437-
while keeping its position in toolbar_pool.
438-
"""
460+
"""Replace `old` toolbar class with `new` class, while keeping its position in toolbar_pool."""
439461
new_name = ".".join((new.__module__, new.__name__))
440462
old_name = ".".join((old.__module__, old.__name__))
441463
toolbar_pool.toolbars = OrderedDict(
@@ -446,3 +468,4 @@ def replace_toolbar(old, new):
446468

447469
replace_toolbar(PageToolbar, VersioningPageToolbar)
448470
replace_toolbar(PlaceholderToolbar, VersioningToolbar)
471+
replace_toolbar(BasicToolbar, VersioningBasicToolbar)

djangocms_versioning/datastructures.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ def content_types(self):
177177

178178

179179
class PolymorphicVersionableItem(VersionableItem):
180-
"""VersionableItem for use by base polymorphic class
181-
(for example filer.File).
180+
"""VersionableItem for use by base polymorphic class (for example filer.File).
182181
"""
183182

184183
def _get_content_types(self):

djangocms_versioning/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def get_for_content(self, content_object):
5151
version = self.get(
5252
object_id=content_object.pk, content_type__in=versionable.content_types
5353
)
54+
version._state.fields_cache["content"] = content_object
5455
content_object._version_cache = version
5556
return version
5657

@@ -243,7 +244,11 @@ def convert_to_proxy(self):
243244
"""Returns a copy of current Version object, but as an instance
244245
of its correct proxy model"""
245246

247+
cache = self._state.fields_cache
248+
del self._state.fields_cache # Remove cache before creating deep copy
246249
new_obj = copy.deepcopy(self)
250+
new_obj._state.fields_cache = cache # Recover caches
251+
self._state.fields_cache = cache # Recover caches
247252
new_obj.__class__ = self.versionable.version_model_proxy
248253
return new_obj
249254

djangocms_versioning/plugin_rendering.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from functools import lru_cache
21

32
from cms import __version__ as cms_version
43
from cms.plugin_rendering import ContentRenderer, StructureRenderer
54
from cms.utils.placeholder import rescan_placeholders_for_obj
5+
from django.utils.functional import cached_property
66

77
from . import versionables
88
from .constants import DRAFT, PUBLISHED
@@ -77,12 +77,10 @@ def render_plugin(self, instance, page=None):
7777

7878

7979
class CMSToolbarVersioningMixin:
80-
@property
81-
@lru_cache(16)
80+
@cached_property
8281
def content_renderer(self):
8382
return VersionContentRenderer(request=self.request)
8483

85-
@property
86-
@lru_cache(16)
84+
@cached_property
8785
def structure_renderer(self):
8886
return VersionStructureRenderer(request=self.request)

pyproject.toml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.ruff]
2-
exclude = [
2+
extend-exclude = [
33
".eggs",
44
".git",
55
".mypy_cache",
@@ -13,25 +13,24 @@ exclude = [
1313
line-length = 120
1414

1515
[tool.ruff.lint]
16-
# https://beta.ruff.rs/docs/configuration/
1716
select = [
1817
"E", # pycodestyle errors
1918
"W", # pycodestyle warnings
2019
"F", # pyflakes
2120
"I", # isort
2221
"C", # flake8-comprehensions
2322
"B", # flake8-bugbear
24-
"Q", # flake8-quotes
23+
"Q", # flake8-quotes
2524
"PLE", # pylint error
2625
"PLR", # pylint refactor
2726
"PLW", # pylint warning
28-
"UP", # pyupgrade
27+
"UP", # pyupgrade
2928
]
3029

31-
ignore = [
30+
extend-ignore = [
3231
"B006", # Do not use mutable data structures for argument defaults
3332
"B011", # tests use assert False
34-
"B019", # Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks
33+
"B019", # Use of `functools.lru_cache` on methods can lead to memory leaks
3534
"B905", # `zip()` without an explicit `strict=` parameter
3635
"C901", # too complex functions
3736
"E402", # module level import not at top of file
@@ -44,6 +43,10 @@ ignore = [
4443
"UP007", # Use `X | Y` for type annotations
4544
]
4645

46+
# TODO: fix these checks separately
47+
# "E501" - Line too long
48+
# "F401" - Unused imports
49+
4750
[tool.ruff.lint.per-file-ignores]
4851
"__init__.py" = [
4952
"F401" # unused-import

0 commit comments

Comments
 (0)