Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog

Unreleased
==========
* feat: Added action button on published versions to view the content.
* ci: Remove ``os`` from test workflow matrix because it's unused
* ci: Added concurrency option to cancel in progress runs when new changes occur

Expand Down
19 changes: 18 additions & 1 deletion djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -537,6 +537,22 @@ 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"""
try:
if not obj.state == PUBLISHED:
# Don't display the link if it isn't published
return ""

published_url = obj.content.get_absolute_url()
except AttributeError:
return ""

return render_to_string(
"djangocms_versioning/admin/published_icon.html",
{"published_url": published_url},
)

def _get_edit_link(self, obj, request, disabled=False):
"""Helper function to get the html link to the edit action
"""
Expand Down Expand Up @@ -629,6 +645,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,
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load static i18n %}
{% spaceless %}
<a class="btn cms-form-get-method cms-versioning-action-btn js-versioning-action js-versioning-keep-sideframe" href="{{ published_url }}" title="{% trans "View published" %}">
<img src="{% static 'djangocms_versioning/svg/preview.svg' %}"></a>
{% endspaceless %}
40 changes: 40 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,46 @@ 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 = (
'<a class="btn cms-form-get-method cms-versioning-action-btn js-versioning-action '
'js-versioning-keep-sideframe" href="%s" title="View published">'
) % published_url
actual_action_control = self.version_admin._get_published_link(version, request)

self.assertIn(expected_action_state, actual_action_control)

def test_action_published_link_not_visible_state(self):
"""The published content link action is not available"""
version = factories.PollVersionFactory(state=constants.DRAFT)
user = factories.UserFactory()
request = RequestFactory().get("/admin/polls/pollcontent/")
request.user = user

expected_action_state = ''
actual_action_control = self.version_admin._get_published_link(version, request)

self.assertIn(expected_action_state, actual_action_control)

def test_action_published_link_not_valid_obj(self):
"""The published content link is not applicable with this object"""
version = factories.AnswerFactory()
user = factories.UserFactory()
request = RequestFactory().get("/admin/polls/answer/")
request.user = user

expected_action_state = ''
actual_action_control = self.version_admin._get_published_link(version, request)

self.assertIn(expected_action_state, actual_action_control)

def test_edit_action_link_sideframe_editing_disabled_state(self):
"""
Sideframe editing is disabled for objects with placeholders i.e. PageContent
Expand Down
6 changes: 2 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ skip_missing_interpreters=True

[testenv]
deps =
-r{toxinidir}/tests/requirements/requirements_base.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because I thought that the isort and flake8 deps needed it, obviously not so no issues removing this.


dj22: -r{toxinidir}/tests/requirements/django_22.txt
dj32: -r{toxinidir}/tests/requirements/django_32.txt
dj22: -r{toxinidir}/tests/requirements/dj22_cms40.txt
dj32: -r{toxinidir}/tests/requirements/dj32_cms40.txt

basepython =
py37: python3.7
Expand Down