Skip to content

fix: Correct ContentRenderer logic for toolbar and page content handling #8092

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

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Dec 9, 2024

Description

Fix the logic in ContentRenderer._get_content_object to correctly handle toolbar objects and page content associations, and add a corresponding test to verify the behavior.

Bug Fixes:

Tests:

  • Add a test for ContentRenderer._get_content_object to ensure it returns the correct placeholders for a page using the toolbar.

Related resources

Checklist

  • I have opened this pull request against develop-4
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined the channel #pr-reviews on our Discord Server to find a “pr review buddy” who is going to review my pull request.

Summary by Sourcery

Correct the logic in ContentRenderer to properly handle toolbar objects and page content associations, and add a test to verify the correct behavior.

Bug Fixes:

  • Fix the logic in ContentRenderer._get_content_object to correctly handle toolbar objects and page content associations.

Tests:

  • Add a test for ContentRenderer._get_content_object to ensure it returns the correct placeholders for a page using the toolbar.

Copy link
Contributor

sourcery-ai bot commented Dec 9, 2024

Reviewer's Guide by Sourcery

This PR fixes the ContentRenderer._get_content_object method to properly handle toolbar objects and page content associations. The implementation improves the logic by correctly checking the toolbar object type and its relationship with the page, and restructures the code to handle different cases more clearly. A new test has been added to verify the behavior.

Updated class diagram for ContentRenderer

classDiagram
    class ContentRenderer {
        - toolbar
        - request_language
        + _get_content_object(page, slots)
        + _preload_placeholders_for_page(page, slots, inherit)
    }
    class Toolbar {
        + get_object()
        + preview_mode_active
        + edit_mode_active
    }
    class Page {
        + pagecontent_set
        + get_content_obj(language, fallback)
    }
    class PageContent {
        + page
        + rescan_placeholders()
    }
    class Placeholder {
        + get_for_obj(obj)
        + none()
    }
    ContentRenderer --> Toolbar
    ContentRenderer --> Page
    ContentRenderer --> Placeholder
    PageContent --> Page
    Placeholder --> PageContent
Loading

File-Level Changes

Change Details Files
Refactor ContentRenderer._get_content_object method to improve toolbar object handling
  • Add explicit type checking for PageContent objects from toolbar
  • Verify page association when checking toolbar objects
  • Restructure conditional logic to use early returns
  • Replace nested assignments with walrus operator for cleaner code
  • Add proper fallback to Placeholder.objects.none() when no content is found
cms/plugin_rendering.py
Add test coverage for placeholder retrieval through toolbar
  • Create test case to verify placeholder retrieval when toolbar object is set
  • Test scenario where toolbar content object belongs to a different page
cms/tests/test_rendering.py

Assessment against linked issues

Issue Objective Addressed Explanation
#8087 Fix the 'EmptyPageContent' object has no attribute '_state' error when previewing pages from other sites in Django-Admin

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai bot changed the title fix: @sourcery-ai fix: Correct placeholder retrieval logic in ContentRenderer Dec 9, 2024
@fsbraun fsbraun changed the title fix: Correct placeholder retrieval logic in ContentRenderer fix: @sourcery-ai Dec 9, 2024
@sourcery-ai sourcery-ai bot changed the title fix: @sourcery-ai fix: Correct ContentRenderer logic for toolbar and page content handling Dec 9, 2024
@fsbraun fsbraun marked this pull request as ready for review December 9, 2024 12:39
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Member

@vinitkumar vinitkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Let's get this merged and released 🚢 🚀

@fsbraun fsbraun merged commit 3f8fcb5 into django-cms:develop-4 Dec 9, 2024
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Preview page from other site throws 'EmptyPageContent' object has no attribute '_state'
2 participants