Skip to content

Conversation

@fsbraun
Copy link
Member

@fsbraun fsbraun commented Oct 31, 2025

Include page path in navigation node attributes to minimize API calls and update serializer to remove redundant path field.

Enhancements:

  • Add page.get_path result to navigation node attributes for direct path access
  • Remove redundant path field from NavigationNodeSerializer and its output

Fixes #77

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 31, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR streamlines endpoint resolution logic, enriches navigation nodes by embedding the page path to reduce downstream API calls, refactors minor formatting in menu patching, and cleans up redundant serializer fields.

Entity relationship diagram for node attribute enrichment with page path

erDiagram
    PAGE {
        id int
    }
    PAGE_CONTENT {
        id int
        page_id int
        language varchar
    }
    NODE {
        id int
        attr json
        path varchar
    }
    PAGE ||--o| PAGE_CONTENT : has
    PAGE_CONTENT ||--o| NODE : creates
Loading

Class diagram for updated NavigationNodeSerializer and node attribute enrichment

classDiagram
    class NavigationNodeSerializer {
        +namespace: CharField
        +title: CharField
        +url: URLField
        +api_endpoint: URLField
        +visible: BooleanField
        +selected: BooleanField
        +attr: dict
        +to_representation(obj: NavigationNode) dict
    }
    class NavigationNode {
        +attr: dict
        +title: str
        +url: str
        +visible: bool
        +selected: bool
    }
    NavigationNodeSerializer --> NavigationNode : serializes
    NavigationNode o-- "attr: dict (now includes 'path')" dict
Loading

File-Level Changes

Change Details Files
Condensed endpoint return logic.
  • Merge multi-line conditional return into a single-line expression
djangocms_rest/cms_config.py
Embedded page path into node attributes to avoid extra API calls.
  • Assign page.get_path() result to node.attr['path'] in the node-creation wrapper
djangocms_rest/cms_config.py
Streamlined menu patching and rendering condition formatting.
  • Convert patch_get_menu_node_for_page_content assignment to one-liner
  • Collapse REST_JSON_RENDERING default check into a single-line getattr
djangocms_rest/cms_config.py
Removed redundant 'path' field from menu serializer.
  • Drop path field declaration in NavigationNodeSerializer
  • Omit path from to_representation output
djangocms_rest/serializers/menus.py

Assessment against linked issues

Issue Objective Addressed Explanation
#77 Ensure that the 'path' attribute in the menu API response contains the page path (e.g., 'schulen/primar-wolfhausen/schulportrait') rather than the REST API endpoint path (e.g., '/api/cms/de/pages/schulen/primar-wolfhausen/schulportrait/').

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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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

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 there - I've reviewed your changes and they look great!


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.

@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.83%. Comparing base (eb3d4c9) to head (8583770).

Files with missing lines Patch % Lines
djangocms_rest/cms_config.py 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #78   +/-   ##
=======================================
  Coverage   90.83%   90.83%           
=======================================
  Files          18       18           
  Lines         851      851           
  Branches       98       98           
=======================================
  Hits          773      773           
  Misses         48       48           
  Partials       30       30           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

if getattr(
settings, "REST_JSON_RENDERING", not getattr(settings, "CMS_TEMPLATES", False)
):
if getattr(settings, "REST_JSON_RENDERING", not getattr(settings, "CMS_TEMPLATES", False)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

@fsbraun can you explain to me why we use a different output for REST_JSON_RENDERING or CMS_TEMPLATES?

Copy link
Member Author

Choose a reason for hiding this comment

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

REST_JSON_RENDERING toggles the JSON rendering. It is also selected when no CMS_TEMPLATES are available. If they are, the templates are used for rendering.

@fsbraun fsbraun merged commit 2a129da into main Nov 5, 2025
55 of 56 checks passed
@fsbraun fsbraun deleted the fix/path branch November 5, 2025 21:21
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.

menu path attribute includes rest api endpoint - this is unexpected

3 participants