Skip to content

Conversation

@fsbraun
Copy link
Member

@fsbraun fsbraun commented May 27, 2025

By default, template components are autodetected from the cms_components folder. This PR adds a setting DJANGOCMS_FRONTEND_COMPONENT_FOLDER to allow setting a different folder.

This would allow to have more than one set of components in an app and select the relevant through the component folder.

Example

image

By default, the button.html component would be discovered. With

DJANGOCMS_FRONTEND_COMPONENT_FOLDER="my_components"

the discovery will find test_component.htm.

Summary by Sourcery

Allow configuring the template component subfolder via a new setting and update discovery logic accordingly

Enhancements:

  • Introduce DJANGOCMS_FRONTEND_COMPONENT_FOLDER setting (defaulting to “cms_components”) to specify the component templates directory
  • Update find_cms_component_templates to accept a configurable subfolder and adjust discovered paths
  • Wire the autodiscovery process to use the new setting instead of a hardcoded folder

Documentation:

  • Document the new DJANGOCMS_FRONTEND_COMPONENT_FOLDER setting in the reference guide

Tests:

  • Add tests for discovering components in the default, custom, and nonexistent folders

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 27, 2025

Reviewer's Guide

Introduce a configurable component folder by adding a new setting and refactoring template discovery and registration to use it, along with tests to verify folder-based selection and a minor inline-field comment update.

Sequence Diagram for Configurable Template Component Discovery

sequenceDiagram
    participant CAD as CMSAutoComponentDiscovery
    participant Settings as djangocms_frontend.settings
    participant FCT as find_cms_component_templates

    CAD->>+Settings: Read settings.COMPONENT_FOLDER
    Settings-->>-CAD: COMPONENT_FOLDER value ("new_folder")
    CAD->>+FCT: find_cms_component_templates(subfolder="new_folder")
    FCT-->>-CAD: List of templates from "new_folder"
Loading

Class Diagram of Changes for Configurable Component Folder

classDiagram
    direction LR

    class Settings_djangocms_frontend {
      +COMPONENT_FOLDER: string
    }

    class CMSAutoComponentDiscovery {
      +__init__(register_to)
    }

    class find_cms_component_templates_function {
      <<Function>>
      +find_cms_component_templates(subfolder: str) : list
    }

    CMSAutoComponentDiscovery ..> Settings_djangocms_frontend : Uses
    CMSAutoComponentDiscovery ..> find_cms_component_templates_function : Calls
Loading

File-Level Changes

Change Details Files
Make component folder configurable
  • Add COMPONENT_FOLDER setting with default 'cms_components'
  • Refactor find_cms_component_templates to accept subfolder and use it in path resolution and template naming
  • Update CMSAutoComponentDiscovery to pass settings.COMPONENT_FOLDER into the discovery function
djangocms_frontend/settings.py
djangocms_frontend/component_pool.py
Add tests for custom component folders
  • Create test_component_folder_selection to assert discovery for default, custom, and empty folders
tests/test_autocomponent.py
Clarify inline-field behavior in templating
  • Insert comment explaining autodetection of inline fields before update_component_properties
djangocms_frontend/templatetags/frontend.py

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

@codecov
Copy link

codecov bot commented May 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.89%. Comparing base (56e16ee) to head (74cf4df).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #285      +/-   ##
==========================================
+ Coverage   88.69%   88.89%   +0.20%     
==========================================
  Files         124      124              
  Lines        3387     3385       -2     
  Branches      289      288       -1     
==========================================
+ Hits         3004     3009       +5     
+ Misses        265      259       -6     
+ Partials      118      117       -1     

☔ 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.

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.

@fsbraun fsbraun merged commit 9726001 into master May 28, 2025
34 checks passed
@fsbraun fsbraun deleted the feat/component-themes branch July 17, 2025 18: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.

2 participants