Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds a link to published content #272

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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: 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
Expand Down
16 changes: 15 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,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
"""
Expand Down Expand Up @@ -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,
]
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ exclude =
**/migrations/,
build/,
.tox/,
.venv,
venv,
node_modules

[isort]
line_length = 88
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
'<a\n title="View published"\n class="btn\n\n cms-versioning-action-btn\n '
'cms-versioning-action-view published\n cms-form-get-method \n js-versioning-action\n '
'js-versioning-keep-sideframe "\n\n href="%s"'
) % 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

with self.assertRaises(AttributeError):
self.version_admin._get_published_link(version, request)

def test_edit_action_link_sideframe_editing_disabled_state(self):
"""
Sideframe editing is disabled for objects with placeholders i.e. PageContent
Expand Down
10 changes: 5 additions & 5 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 All @@ -25,9 +23,11 @@ commands =
{env:COMMAND:coverage} report

[testenv:flake8]
deps = flake8
commands = flake8
basepython = python3.8

[testenv:isort]
commands = isort --recursive --check-only --diff {toxinidir}
deps = isort
commands = isort --check --diff {toxinidir}
basepython = python3.8