Skip to content

Commit

Permalink
fix: Unify edit icons
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed May 19, 2024
1 parent 9dbdb48 commit b898442
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,26 @@ def _get_edit_link(self, obj, request, disabled=False):
f"admin:{version._meta.app_label}_{version._meta.model_name}_edit_redirect",
args=(version.pk,),
)
# Only show if no draft exists
if version.state == PUBLISHED:
pks_for_grouper = version.versionable.for_content_grouping_values(
obj
).values_list("pk", flat=True)
drafts = Version.objects.filter(
object_id__in=pks_for_grouper,
content_type=version.content_type,
state=DRAFT,
)
if drafts.exists():
return ""
icon = "edit-new"
else:
icon = "edit"

return self.admin_action_button(
url,
icon="pencil",
title=_("Edit"),
icon=icon,
title=_("Edit") if icon == "edit" else _("New Draft"),
name="edit",
disabled=disabled,
action="post",
Expand Down Expand Up @@ -748,7 +764,7 @@ def _get_edit_link(self, obj, request, disabled=False):
return ""
icon = "edit-new"
else:
icon = "pencil"
icon = "edit"

# Don't open in the sideframe if the item is not sideframe compatible
keepsideframe = obj.versionable.content_model_is_sideframe_editable
Expand All @@ -760,7 +776,7 @@ def _get_edit_link(self, obj, request, disabled=False):
return self.admin_action_button(
edit_url,
icon=icon,
title=_("Edit") if icon == "pencil" else _("New Draft"),
title=_("Edit") if icon == "edit" else _("New Draft"),
name="edit",
action="post",
disabled=disabled,
Expand Down

0 comments on commit b898442

Please sign in to comment.