From ea8db295367223871dfb99a3754d713180173911 Mon Sep 17 00:00:00 2001 From: Florian Scherf Date: Mon, 29 Jan 2024 12:32:29 +0100 Subject: [PATCH] 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 --- djangocms_alias/admin.py | 12 +++++++++++- djangocms_alias/models.py | 5 ----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/djangocms_alias/admin.py b/djangocms_alias/admin.py index 0400bbbe..f245c949 100644 --- a/djangocms_alias/admin.py +++ b/djangocms_alias/admin.py @@ -1,5 +1,5 @@ from django import forms -from django.contrib import admin +from django.contrib import admin, messages from django.http import ( Http404, HttpRequest, @@ -173,3 +173,13 @@ def has_module_permission(self, request: HttpRequest) -> bool: """Hides admin class in admin site overview""" return False + + def delete_model(self, request: HttpRequest, obj: AliasContent): + 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, + ) diff --git a/djangocms_alias/models.py b/djangocms_alias/models.py index 1bd9793c..71f69733 100644 --- a/djangocms_alias/models.py +++ b/djangocms_alias/models.py @@ -302,11 +302,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: