Skip to content

Commit

Permalink
feat: Add preview link to Alias AliasContent Manager versioning actio…
Browse files Browse the repository at this point in the history
…ns (#89)
  • Loading branch information
NarenderRajuB authored Mar 30, 2022
1 parent b50e334 commit 42f2d2c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog

Unreleased
==========
* Add versioning actions to Alias AliasContent Manager
* feat: Add preview link to Alias AliasContent Manager versioning actions
* feat: Add versioning actions to Alias AliasContent Manager
* feat: Github Actions integration
* Python 3.8, 3.9 support added
* Django 3.0, 3.1 and 3.2 support added
Expand Down
35 changes: 35 additions & 0 deletions djangocms_alias/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _

from cms.utils.permissions import get_model_permission_codename
Expand Down Expand Up @@ -124,3 +125,37 @@ def delete_model(self, request, obj):
# Versioning emits it's own signals for changes
if not is_versioning_enabled():
emit_content_delete([obj], sender=self.model)

def get_list_actions(self):
"""
Collect rendered actions from implemented methods and return as list
"""
return [
self._get_preview_link,
self._get_manage_versions_link,
]

def _get_preview_link(self, obj, request, disabled=False):
"""
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?
:return: Preview icon template
"""
preview_url = obj.get_absolute_url()
if not preview_url:
disabled = True

return render_to_string(
"djangocms_versioning/admin/icons/preview.html",
{"url": preview_url, "disabled": disabled},
)

def change_view(self, request, object_id, form_url='', extra_context=None):
extra_context = extra_context or {}
# Provide additional context to the changeform
extra_context['is_versioning_enabled'] = is_versioning_enabled()
return super().change_view(
request, object_id, form_url, extra_context=extra_context,
)
8 changes: 8 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def test_alias_content_manager_rendering_without_versioning_actions(self):
expected_en_content.name,
response_content_decoded,
)
self.assertNotIn(
expected_en_content.get_absolute_url(),
response_content_decoded,
)

@skipUnless(is_versioning_enabled(), 'Test only relevant for versioning')
def test_alias_content_manager_rendering_with_versioning_actions(self):
Expand Down Expand Up @@ -171,3 +175,7 @@ def test_alias_content_manager_rendering_with_versioning_actions(self):
localize(localtime(latest_alias_content_version.modified)),
response_content_decoded,
)
self.assertIn(
expected_en_content.get_absolute_url(),
response_content_decoded,
)

0 comments on commit 42f2d2c

Please sign in to comment.