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 draft deletion bug on Django CMS 4.0.x #233

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion djangocms_alias/admin.py
Original file line number Diff line number Diff line change
@@ -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 _
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions djangocms_alias/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/django_42.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
https://github.com/django-cms/djangocms-versioning/tarball/support/django-cms-4.0.x#egg=djangocms-versioning
Loading