-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: show_placeholder did not respect edit/preview mode and failed loudly #8272
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
Conversation
Reviewer's GuideThis PR updates the show_placeholder tag to fail silently for missing page content in production and to respect admin-only content visibility in edit and preview modes by introducing an admin_manager flag in get_placeholders, adds tests for these behaviors, and cleans up obsolete admin utility code. Sequence diagram for show_placeholder tag with admin/preview mode handlingsequenceDiagram
participant User as actor User
participant Template as Template Engine
participant CMS as CMS Tags
participant Page as Page Model
participant PC as PageContent
participant PH as Placeholder
participant Toolbar as Toolbar
User->>Template: Render template with {% show_placeholder %}
Template->>CMS: _show_placeholder_by_id(...)
CMS->>Toolbar: get_toolbar_from_request(request)
CMS->>Toolbar: Check edit_mode_active/preview_mode_active
CMS->>Page: get_placeholders(lang, admin_manager)
alt admin_manager is True
Page->>PC: PageContent.admin_manager.latest_content().get(...)
else admin_manager is False
Page->>PC: PageContent.objects.get(...)
end
Page->>PH: Placeholder.objects.get_for_obj(page_content)
CMS->>Template: Return placeholder content or "" if not found
Class diagram for updated get_placeholders method in Page modelclassDiagram
class Page {
+get_placeholders(language: str, admin_manager: bool = False) QuerySet
}
class PageContent {
+admin_manager
+objects
}
class Placeholder {
+get_for_obj(obj)
}
Page --> PageContent : uses
Page --> Placeholder : uses
PageContent <|-- admin_manager
PageContent <|-- objects
Class diagram for _show_placeholder_by_id logic updateclassDiagram
class CMS_Tags {
+_show_placeholder_by_id(context, placeholder_name, reverse_id, lang=None, site=None)
}
class Toolbar {
+edit_mode_active
+preview_mode_active
}
CMS_Tags --> Toolbar : checks mode
CMS_Tags --> Page : calls get_placeholders
CMS_Tags --> Placeholder : gets placeholder
CMS_Tags ..> settings : uses DEBUG
CMS_Tags ..> PageContent : handles DoesNotExist exception
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @fsbraun - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `cms/tests/test_templatetags.py:304` </location>
<code_context>
+ content = _show_placeholder_by_id(context, "does_not_exist", "myreverseid", lang="go-lang")
+ self.assertEqual(content, "")
+
+ def test_show_placeholder_for_page_content_does_not_exist(self):
+ """
+ Verify ``show_placeholder`` correctly handles being given an
+ invalid identifier.
+ """
</code_context>
<issue_to_address>
Potential duplicate or incomplete test for missing page content.
Please implement 'test_show_placeholder_for_page_content_does_not_exist' to cover missing page content in both DEBUG and non-DEBUG modes, ensuring the new error handling is tested.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…udly (#8272) * fix: show_placeholder tag * Add test * Use current_content * fix: test names switched * Better naming inside test * fix: docs * Update docs/requirements.txt * Fix django_settings for docs
…udly (#8272) * fix: show_placeholder tag * Add test * Use current_content * fix: test names switched * Better naming inside test * fix: docs * Update docs/requirements.txt * Fix django_settings for docs
…udly (#8273) * fix: show_placeholder did not respect edit/preview mode and failed loudly (#8272) * fix: show_placeholder tag * Add test * Use current_content * fix: test names switched * Better naming inside test * fix: docs * Update docs/requirements.txt * Fix django_settings for docs * Update package.json
Description
This PR fixes #8271, by
{% show_placeholder %}
tag fail silently if the targeted page does not have a content object in the required languageRelated resources
Checklist
main
Summary by Sourcery
Enable show_placeholder to respect edit/preview modes by including admin-only content and to handle missing content gracefully outside debug mode.
Bug Fixes:
Enhancements:
Tests: