From 09e62ade4d5ca854349da75b69126133d5f8191f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=82=85=E7=9D=BF=E6=9B=BC?= Date: Mon, 4 Nov 2024 15:18:57 +0800 Subject: [PATCH] fix empty date issue if the alias has legacy empty date. --- djangocms_version_locking/cms_config.py | 10 ++++++---- .../monkeypatch/djangocms_alias/admin.py | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/djangocms_version_locking/cms_config.py b/djangocms_version_locking/cms_config.py index 2f4d1bc..5e95235 100644 --- a/djangocms_version_locking/cms_config.py +++ b/djangocms_version_locking/cms_config.py @@ -9,14 +9,16 @@ def add_alias_version_lock(obj, field): - version = obj.versions.all()[0] + # add None obj check, if the legacy data has empty value. lock_icon = "" - if version.state == DRAFT and version_is_locked(version): - lock_icon = mark_safe('') + if obj: + version = obj.versions.all()[0] + if version.state == DRAFT and version_is_locked(version): + lock_icon = mark_safe('') return format_html( "{is_locked}{field_value}", is_locked=lock_icon, - field_value=getattr(obj, field), + field_value=getattr(obj, field, '-'), ) diff --git a/djangocms_version_locking/monkeypatch/djangocms_alias/admin.py b/djangocms_version_locking/monkeypatch/djangocms_alias/admin.py index a0d81a0..0c99a7e 100644 --- a/djangocms_version_locking/monkeypatch/djangocms_alias/admin.py +++ b/djangocms_version_locking/monkeypatch/djangocms_alias/admin.py @@ -36,6 +36,9 @@ def _get_content_obj(self, obj: Alias): return content_obj def _get_edit_link(self, obj: Alias, request: HttpRequest, disabled: bool = False): + if self._get_content_obj(obj): + # Don't display the link if it can't be edited, as the content is empty. + return "" version = proxy_model(self._get_content_obj(obj).versions.all()[0], self._get_content_obj(obj)) if version.state not in (DRAFT, PUBLISHED): @@ -70,6 +73,9 @@ def _get_edit_link(self, obj: Alias, request: HttpRequest, disabled: bool = Fals ) def _get_manage_versions_link(self, obj: Alias, request: HttpRequest, disabled: bool = False): + if self._get_content_obj(obj): + # Don't display the link if it can't find version list urls, as the content is empty. + return "" url = version_list_url(self._get_content_obj(obj)) return self.admin_action_button( url,