From db0b6c4d78fa469f56c55a9f139d3a66980f8c45 Mon Sep 17 00:00:00 2001 From: Florian Scherf Date: Thu, 11 Apr 2024 16:01:58 +0200 Subject: [PATCH] fix draft deletion bug on Django CMS 4.0.x (#233) * fix djangocms-versioning draft deletion bug (#214) (#215) * fix djangocms-versioning draft deletion bug (#214) Previously, `djangocms_alias.models.AliasContent.delete` deleted all plugins related to `AliasContent.alias`, with the same language. Drafts and previously published versions included. This meant that the deletion of a draft resulted in plugins disappearing from published pages. This patch removes the mechanism entirely and instead adds a warning, notifying the user that the last version or translation of a language got deleted. Signed-off-by: Florian Scherf * ci: auto fixes from pre-commit hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Florian Scherf Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * tests: requirements: django42: fix broken djangocms-versioning URL Signed-off-by: Florian Scherf --------- Signed-off-by: Florian Scherf Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- djangocms_alias/admin.py | 13 ++++++++++++- djangocms_alias/models.py | 5 ----- tests/requirements/django_42.txt | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/djangocms_alias/admin.py b/djangocms_alias/admin.py index d28e4159..daac1022 100644 --- a/djangocms_alias/admin.py +++ b/djangocms_alias/admin.py @@ -1,6 +1,6 @@ from cms.utils.permissions import get_model_permission_codename from cms.utils.urlutils import admin_reverse -from django.contrib import admin +from django.contrib import admin, messages from django.db.models.functions import Lower from django.template.loader import render_to_string from django.utils.translation import gettext_lazy as _ @@ -168,6 +168,17 @@ def delete_model(self, request, obj): if not is_versioning_enabled(): emit_content_delete([obj], sender=self.model) + if obj.alias._default_manager.filter(language=obj.language).count() == 1: + message = _( + "Alias content for language {} deleted. A new empty alias content will be created if needed." + ).format(obj.language) + self.message_user(request, message, level=messages.WARNING) + + return super().delete_model( + request=request, + obj=obj, + ) + def get_list_actions(self): """ Collect rendered actions from implemented methods and return as list diff --git a/djangocms_alias/models.py b/djangocms_alias/models.py index d63099e6..f027b704 100644 --- a/djangocms_alias/models.py +++ b/djangocms_alias/models.py @@ -305,11 +305,6 @@ def get_absolute_url(self): def get_template(self): return "djangocms_alias/alias_content.html" - @transaction.atomic - def delete(self, *args, **kwargs): - super().delete(*args, **kwargs) - self.alias.cms_plugins.filter(language=self.language).delete() - @transaction.atomic def populate(self, replaced_placeholder=None, replaced_plugin=None, plugins=None): if not replaced_placeholder and not replaced_plugin: diff --git a/tests/requirements/django_42.txt b/tests/requirements/django_42.txt index e268f69e..778ac268 100644 --- a/tests/requirements/django_42.txt +++ b/tests/requirements/django_42.txt @@ -7,4 +7,4 @@ django-sekizai django-parler https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms -https://github.com/joshyu/djangocms-versioning/tarball/feat/django-42-compatible#egg=djangocms-versioning \ No newline at end of file +https://github.com/django-cms/djangocms-versioning/tarball/support/django-cms-4.0.x#egg=djangocms-versioning