Skip to content

Commit

Permalink
Fix: skip objects using placeholders without source (#253)
Browse files Browse the repository at this point in the history
* Skip objects using placeholders without source

* test: add usage view test for alias saved to clipboard
  • Loading branch information
albanbochsler authored Nov 14, 2024
1 parent aa559f6 commit 3ba3433
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions djangocms_alias/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def objects_using(self):
plugins = self.cms_plugins.select_related("placeholder").prefetch_related("placeholder__source")
for plugin in plugins:
obj = plugin.placeholder.source

# Skip plugins that have no placeholder source e.g clipboard
if obj is None:
continue

obj_class_name = obj.__class__.__name__
if obj_class_name.endswith("Content"):
attr_name = obj_class_name.replace("Content", "").lower()
Expand Down
21 changes: 21 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,3 +1580,24 @@ def test_view_multilanguage(self):
self.assertNotContains(list_response, alias_content_de.name)
self.assertNotContains(detail_response, en_plugin.body)
self.assertNotContains(list_response, alias.name)

def test_usage_view_if_alias_is_saved_to_clipboard(self):
"""
The usage view should ignore the clipboard entry
"""

alias = self._create_alias()
placeholder = Placeholder.objects.create(slot="clipboard")
add_plugin(placeholder, "Alias", language="en", alias=alias)

with self.login_user_context(self.superuser):
response = self.client.get(
admin_reverse(
USAGE_ALIAS_URL_NAME,
args=[alias.pk],
),
)

self.assertEqual(response.status_code, 200)
# Check that the alias is displayed in the response content
self.assertContains(response, alias.name)

0 comments on commit 3ba3433

Please sign in to comment.