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

Fix: skip objects using placeholders without source #253

Merged
merged 2 commits into from
Nov 14, 2024
Merged
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
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)
Loading