Skip to content

Commit 3ba3433

Browse files
Fix: skip objects using placeholders without source (#253)
* Skip objects using placeholders without source * test: add usage view test for alias saved to clipboard
1 parent aa559f6 commit 3ba3433

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

djangocms_alias/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ def objects_using(self):
133133
plugins = self.cms_plugins.select_related("placeholder").prefetch_related("placeholder__source")
134134
for plugin in plugins:
135135
obj = plugin.placeholder.source
136+
137+
# Skip plugins that have no placeholder source e.g clipboard
138+
if obj is None:
139+
continue
140+
136141
obj_class_name = obj.__class__.__name__
137142
if obj_class_name.endswith("Content"):
138143
attr_name = obj_class_name.replace("Content", "").lower()

tests/test_views.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,3 +1580,24 @@ def test_view_multilanguage(self):
15801580
self.assertNotContains(list_response, alias_content_de.name)
15811581
self.assertNotContains(detail_response, en_plugin.body)
15821582
self.assertNotContains(list_response, alias.name)
1583+
1584+
def test_usage_view_if_alias_is_saved_to_clipboard(self):
1585+
"""
1586+
The usage view should ignore the clipboard entry
1587+
"""
1588+
1589+
alias = self._create_alias()
1590+
placeholder = Placeholder.objects.create(slot="clipboard")
1591+
add_plugin(placeholder, "Alias", language="en", alias=alias)
1592+
1593+
with self.login_user_context(self.superuser):
1594+
response = self.client.get(
1595+
admin_reverse(
1596+
USAGE_ALIAS_URL_NAME,
1597+
args=[alias.pk],
1598+
),
1599+
)
1600+
1601+
self.assertEqual(response.status_code, 200)
1602+
# Check that the alias is displayed in the response content
1603+
self.assertContains(response, alias.name)

0 commit comments

Comments
 (0)