Skip to content

Commit

Permalink
feat: Remove Add cta and hide delete dropdown actions from AliasCont…
Browse files Browse the repository at this point in the history
…ent admin ChangeList (#98)
  • Loading branch information
NarenderRajuB authored Apr 6, 2022
1 parent 9b30313 commit 4929b90
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 8 deletions.
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: Remove Add cta and hide delete dropdown actions from AliasContent admin ChangeList
* feat: Site field added to plugin

1.0.2 (2022-04-01)
Expand Down
9 changes: 8 additions & 1 deletion djangocms_alias/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ def delete_model(self, request, obj):
@admin.register(AliasContent)
class AliasContentAdmin(*alias_content_admin_classes):
form = AliasContentForm
list_filter = (LanguageFilter, )
list_filter = (LanguageFilter,)
list_display = alias_content_admin_list_display
# Disable dropdown actions
actions = None
change_form_template = "admin/djangocms_alias/aliascontent/change_form.html"

# Add Alias category in the admin manager list and order field
Expand All @@ -112,6 +114,11 @@ def get_category(self, obj):
get_category.short_description = _('category')
get_category.admin_order_field = "alias__category"

def has_add_permission(self, request, obj=None):
# FIXME: It is not currently possible to add an alias from the django admin changelist issue #97
# https://github.com/django-cms/djangocms-alias/issues/97
return False

def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)

Expand Down
78 changes: 73 additions & 5 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def setUp(self):
self.superuser = self.get_superuser()

def test_language_filter(self):
"""
When rendering aliascontent manager language filter
"""
category = Category.objects.create(name='Language Filter Category')
alias = AliasModel.objects.create(
category=category,
Expand Down Expand Up @@ -66,6 +69,9 @@ def setUp(self):

@skipUnless(not is_versioning_enabled(), 'Test only relevant when no versioning')
def test_alias_content_manager_rendering_without_versioning_actions(self):
"""
When rendering aliascontent manager without versioning
"""
category = Category.objects.create(name='Language Filter Category')
alias = AliasModel.objects.create(
category=category,
Expand All @@ -76,7 +82,6 @@ def test_alias_content_manager_rendering_without_versioning_actions(self):
name="EN Alias Content",
language="en",
)

base_url = self.get_admin_url(AliasContent, "changelist")

with self.login_user_context(self.superuser):
Expand Down Expand Up @@ -121,9 +126,29 @@ def test_alias_content_manager_rendering_without_versioning_actions(self):
change_category_and_site_url,
response_content_decoded,
)
# check for add content admin link
add_alias_link = admin_reverse(
'{}_{}_add'.format(
expected_en_content._meta.app_label,
expected_en_content._meta.model_name
)
)
self.assertNotIn(
# It is not currently possible to add an alias from the django admin changelist issue #97
# https://github.com/django-cms/djangocms-alias/issues/97
add_alias_link,
response_content_decoded,
)
self.assertNotIn(
'<option value="delete_selected">Delete selected alias contents</option>', # noqa: E501
response_content_decoded
)

@skipUnless(is_versioning_enabled(), 'Test only relevant for versioning')
def test_alias_content_manager_rendering_with_versioning_actions(self):
"""
When rendering aliascontent manager with versioning actions
"""
category = Category.objects.create(name='Language Filter Category')
alias = AliasModel.objects.create(
category=category,
Expand Down Expand Up @@ -194,10 +219,6 @@ 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,
)

usage_url = admin_reverse(USAGE_ALIAS_URL_NAME, args=[expected_en_content.alias.pk])
change_category_and_site_url = admin_reverse(
Expand Down Expand Up @@ -225,3 +246,50 @@ def test_alias_content_manager_rendering_with_versioning_actions(self):
change_category_and_site_url,
response_content_decoded,
)

@skipUnless(is_versioning_enabled(), 'Test only relevant for versioning')
def test_alias_content_manager_rendering_preview_add_url(self):
"""
When rendering aliascontent manager with versioning actions and preview
"""
category = Category.objects.create(name='Language Filter Category')
alias = AliasModel.objects.create(
category=category,
position=0,
)
expected_en_content = AliasContent.objects.create(
alias=alias,
name="EN Alias Content",
language="en",
)

from djangocms_versioning.models import Version

Version.objects.create(content=expected_en_content, created_by=self.superuser)

with self.login_user_context(self.superuser):
base_url = self.get_admin_url(AliasContent, "changelist")
# en is the default language configured for the site
response = self.client.get(base_url)

response_content_decoded = response.content.decode()

self.assertIn(
expected_en_content.get_absolute_url(),
response_content_decoded,
)
self.assertNotIn(
'<option value="delete_selected">Delete selected alias contents</option>', # noqa: E501
response_content_decoded
)
# check for add content admin link
add_aliascontent_url = admin_reverse(
'{}_{}_add'.format(
expected_en_content._meta.app_label,
expected_en_content._meta.model_name
)
)
self.assertNotIn(
add_aliascontent_url,
response_content_decoded,
)
20 changes: 18 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from unittest import skipIf, skipUnless
from unittest import skip, skipIf, skipUnless

from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
Expand Down Expand Up @@ -1055,7 +1055,7 @@ def test_select2_view_category(self):
category2 = Category.objects.create(name='test 2')
alias1 = self._create_alias(name='test 2', category=category2)
alias2 = self._create_alias(name='foo', category=category2, position=1)
# This shouldnt show becuase it's in different Category
# This shouldnt show because it's in different Category
self._create_alias(name='three')
with self.login_user_context(self.superuser):
response = self.client.get(
Expand Down Expand Up @@ -1108,6 +1108,10 @@ def test_select2_view_pk(self):
[alias1.pk],
)

@skip(
"It is not currently possible to add an alias from the django admin changelist issue "
"#https://github.com/django-cms/djangocms-alias/issues/97#97"
)
def test_aliascontent_add_view(self):
alias = Alias.objects.create(category=self.category)
with self.login_user_context(self.superuser):
Expand All @@ -1128,6 +1132,10 @@ def test_aliascontent_add_view(self):
self.assertEqual(alias_content.language, 'de')
self.assertEqual(alias_content.name, 'alias test de 1')

@skip(
"It is not currently possible to add an alias from the django admin changelist issue "
"#https://github.com/django-cms/djangocms-alias/issues/97#97"
)
def test_aliascontent_add_view_get(self):
alias = Alias.objects.create(category=self.category)
with self.login_user_context(self.superuser):
Expand All @@ -1144,6 +1152,10 @@ def test_aliascontent_add_view_get(self):
self.assertContains(response, 'type="hidden" name="language" value="fr"')
self.assertContains(response, 'type="hidden" name="alias" value="{}"'.format(alias.pk))

@skip(
"It is not currently possible to add an alias from the django admin changelist issue "
"#https://github.com/django-cms/djangocms-alias/issues/97#97"
)
def test_aliascontent_add_view_invalid_data(self):
alias = Alias.objects.create(category=self.category)
self._create_alias(
Expand All @@ -1168,6 +1180,10 @@ def test_aliascontent_add_view_invalid_data(self):
'Alias with this Name and Category already exists',
)

@skip(
"It is not currently possible to add an alias from the django admin changelist issue "
"#https://github.com/django-cms/djangocms-alias/issues/97#97"
)
def test_aliascontent_add_view_valid_data(self):
alias = Alias.objects.create(category=self.category)
if is_versioning_enabled():
Expand Down

0 comments on commit 4929b90

Please sign in to comment.