From 8d18942cc04bb0f12caed845722c33fa7a5a7c33 Mon Sep 17 00:00:00 2001 From: Josh Yu Date: Tue, 27 Aug 2024 09:53:32 +0800 Subject: [PATCH] fix: monkeypatch script & update filter label --- CHANGELOG.rst | 3 ++ djangocms_content_expiry/admin.py | 2 +- djangocms_content_expiry/monkeypatch/admin.py | 40 ++++++++++--------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3a8d594..e49b619 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,9 @@ Changelog unreleased ========== +* add support for Django CMS 4.1 +* fix `Expiry Date Range` filter label +* fix monkeypatch scripts 1.6.1 (2024-05-31) diff --git a/djangocms_content_expiry/admin.py b/djangocms_content_expiry/admin.py index 7f79f50..403232a 100644 --- a/djangocms_content_expiry/admin.py +++ b/djangocms_content_expiry/admin.py @@ -101,7 +101,7 @@ def get_rangefilter_expires_default(self, *args, **kwargs): return get_rangefilter_expires_default() def get_rangefilter_expires_title(self, *args, **kwargs): - return _("By Expiry Date Range") + return _("Expiry Date Range") @admin.display( description=_('Title') diff --git a/djangocms_content_expiry/monkeypatch/admin.py b/djangocms_content_expiry/monkeypatch/admin.py index a8fab3c..fa65e20 100644 --- a/djangocms_content_expiry/monkeypatch/admin.py +++ b/djangocms_content_expiry/monkeypatch/admin.py @@ -4,7 +4,8 @@ from djangocms_moderation import admin as moderation_admin from djangocms_moderation.models import ModerationCollection, ModerationRequest -from djangocms_versioning import admin +from djangocms_versioning import admin as versioning_admin +from djangocms_versioning.models import Version from djangocms_content_expiry.constants import CONTENT_EXPIRY_COMPLIANCE_FIELD_LABEL from djangocms_content_expiry.models import ContentExpiry @@ -14,22 +15,25 @@ def _get_expiry_link(self, obj, request): """ Generate a content expiry link for the Versioning Admin """ - expiry_url = reverse( - "admin:{app}_{model}_change".format( - app=ContentExpiry._meta.app_label, model=ContentExpiry._meta.model_name - ), - args=(obj.contentexpiry.pk,), - ) - return render_to_string( - 'djangocms_content_expiry/admin/icons/additional_content_settings_icon.html', - { - "url": f"{expiry_url}?_to_field=id&_popup=1", - "field_id": f"contentexpiry_{obj.pk}", - } - ) + try: + expiry_url = reverse( + "admin:{app}_{model}_change".format( + app=ContentExpiry._meta.app_label, model=ContentExpiry._meta.model_name + ), + args=(obj.contentexpiry.pk,), + ) + return render_to_string( + 'djangocms_content_expiry/admin/icons/additional_content_settings_icon.html', + { + "url": f"{expiry_url}?_to_field=id&_popup=1", + "field_id": f"contentexpiry_{obj.pk}", + } + ) + except Version.contentexpiry.RelatedObjectDoesNotExist: + return '' -admin.VersionAdmin._get_expiry_link = _get_expiry_link +versioning_admin.VersionAdmin._get_expiry_link = _get_expiry_link def get_state_actions(func): @@ -43,7 +47,7 @@ def inner(self, *args, **kwargs): return inner -admin.VersionAdmin.get_state_actions = get_state_actions(admin.VersionAdmin.get_state_actions) +versioning_admin.VersionAdmin.get_state_actions = get_state_actions(versioning_admin.VersionAdmin.get_state_actions) def compliance_number(self, obj): @@ -54,7 +58,7 @@ def compliance_number(self, obj): compliance_number.short_description = CONTENT_EXPIRY_COMPLIANCE_FIELD_LABEL -admin.VersionAdmin.compliance_number = compliance_number +versioning_admin.VersionAdmin.compliance_number = compliance_number def get_list_display(func): @@ -69,7 +73,7 @@ def inner(self, request): return inner -admin.VersionAdmin.get_list_display = get_list_display(admin.VersionAdmin.get_list_display) +versioning_admin.VersionAdmin.get_list_display = get_list_display(versioning_admin.VersionAdmin.get_list_display) def _get_urls(func):