diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 072d236b..6bf6352d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,7 @@ Changelog Unreleased ========== +* feat: Added action button on published versions to view the content. * ci: Updated isort params in lint workflow to meet current requirements. * ci: Update actions to v3 where possible, and coverage to v2 due to v1 sunset in Feb * ci: Remove ``os`` from test workflow matrix because it's unused diff --git a/djangocms_versioning/admin.py b/djangocms_versioning/admin.py index 133c3a5d..2e0fc708 100644 --- a/djangocms_versioning/admin.py +++ b/djangocms_versioning/admin.py @@ -210,7 +210,7 @@ def list_actions(obj): def _get_preview_link(self, obj, request, disabled=False): """ - Return a user friendly button for previewing the content model + Return a user-friendly button for previewing the content model :param obj: Instance of versioned content model :param request: The request to admin menu :param disabled: Should the link be marked disabled? @@ -537,6 +537,19 @@ def _get_unpublish_link(self, obj, request, disabled=False): {"unpublish_url": unpublish_url, "disabled": disabled}, ) + def _get_published_link(self, obj, request): + """Helper function to get the link to the published page""" + if not obj.state == PUBLISHED: + # Don't display the link if it isn't published + return "" + + published_url = getattr(obj.content, "get_absolute_url", None) + + return render_to_string( + "djangocms_versioning/admin/icons/published_icon.html", + {"url": published_url, "disabled": False}, + ) if published_url else "" + def _get_edit_link(self, obj, request, disabled=False): """Helper function to get the html link to the edit action """ @@ -629,6 +642,7 @@ def get_state_actions(self): self._get_archive_link, self._get_publish_link, self._get_unpublish_link, + self._get_published_link, self._get_revert_link, self._get_discard_link, ] diff --git a/djangocms_versioning/templates/djangocms_versioning/admin/icons/published_icon.html b/djangocms_versioning/templates/djangocms_versioning/admin/icons/published_icon.html new file mode 100644 index 00000000..6ae2cd3d --- /dev/null +++ b/djangocms_versioning/templates/djangocms_versioning/admin/icons/published_icon.html @@ -0,0 +1,5 @@ +{% extends "./base.html" %} +{% load static i18n %} +{% block title %}{% trans 'View published' %}{% endblock %} +{% block name %}view published{% endblock %} +{% block icon %}{% static 'djangocms_versioning/svg/preview.svg' %}{% endblock %} diff --git a/setup.cfg b/setup.cfg index 274739e5..cc43d147 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,9 @@ exclude = **/migrations/, build/, .tox/, + .venv, venv, + node_modules [isort] line_length = 88 @@ -15,7 +17,7 @@ lines_after_imports = 2 combine_as_imports = true include_trailing_comma = true balanced_wrapping = true -skip = manage.py, migrations, .tox +skip = manage.py, migrations, .tox, .venv, node_modules extra_standard_library = mock known_django = django known_cms = cms, menus diff --git a/tests/test_admin.py b/tests/test_admin.py index debe2d0d..4cb7bc25 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -617,6 +617,45 @@ def test_revert_action_link_for_archive_state(self): expected_disabled_control, actual_disabled_control.replace("\n", "") ) + def test_action_published_link_visible_state(self): + """The published content link action is available""" + version = factories.PollVersionFactory(state=constants.PUBLISHED) + user = factories.UserFactory() + request = RequestFactory().get("/admin/polls/pollcontent/") + request.user = user + published_url = version.content.get_absolute_url() + + expected_action_state = ( + '