From 80e68fe15f89aeaf0db4c8dea30d57fa407927de 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:43:10 +0800 Subject: [PATCH] fix empty date issue if the alias has legacy empty data, code refact. --- .../monkeypatch/djangocms_alias/admin.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/djangocms_version_locking/monkeypatch/djangocms_alias/admin.py b/djangocms_version_locking/monkeypatch/djangocms_alias/admin.py index 0c99a7e..a39367d 100644 --- a/djangocms_version_locking/monkeypatch/djangocms_alias/admin.py +++ b/djangocms_version_locking/monkeypatch/djangocms_alias/admin.py @@ -36,10 +36,11 @@ 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): + obj_content = self._get_content_obj(obj) + if not obj_content: # 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)) + version = proxy_model(obj_content.versions.all()[0], obj_content) if version.state not in (DRAFT, PUBLISHED): # Don't display the link if it can't be edited @@ -73,10 +74,11 @@ 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): + obj_content = self._get_content_obj(obj) + if not obj_content: # 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)) + url = version_list_url(obj_content) return self.admin_action_button( url, icon="list-ol",