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: Snippet plugin showing ID instead of name #100

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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
Unreleased
==========

* fix: Snippet plugin added to a page now displays name instead of ID
* fix: Slug field on list display for admin should only be displayed when versioning is not available

4.0.0.dev2 (2021-12-22)
Expand Down
4 changes: 4 additions & 0 deletions djangocms_snippet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class SnippetPtr(CMSPlugin):

search_fields = ['snippet__html'] if SEARCH_ENABLED else []

def get_short_description(self):
snippet_label = SnippetGrouper.objects.filter(pk=self.snippet_grouper.pk).first()
return snippet_label

class Meta:
verbose_name = _('Snippet Ptr')
verbose_name_plural = _('Snippet Ptrs')
20 changes: 19 additions & 1 deletion tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from cms.api import add_plugin, create_page
from cms.models import PageContent
from cms.test_utils.testcases import CMSTestCase
from cms.toolbar.utils import get_object_edit_url
from cms.toolbar.utils import get_object_edit_url, get_object_structure_url

from djangocms_snippet.models import Snippet, SnippetGrouper
from djangocms_versioning.models import Version
Expand Down Expand Up @@ -290,3 +290,21 @@ def test_published_snippet_and_page_live_url_rendering(self):

self.assertContains(response, "<p>Published snippet</p>")
self.assertNotIn("Draft snippet", str(response.content))

def test_correct_name_is_displayed_for_snippet_component_on_page(self):
"""
If a component is added to the page, it should show the snippet name and not ID
"""
add_plugin(
self.draft_pagecontent.placeholders.get(slot="content"),
"SnippetPlugin",
self.language,
snippet_grouper=self.draft_snippet.snippet_grouper,
)

# Request structure endpoint on page
request_url = get_object_structure_url(self.draft_pagecontent, "en")
with self.login_user_context(self.superuser):
response = self.client.get(request_url)

self.assertContains(response, "<strong>Snippet</strong> plugin_snippet</span>")