Skip to content

Conversation

@fsbraun
Copy link
Member

@fsbraun fsbraun commented Mar 28, 2025

instance.get_classes simplifies using mixins for spacing, background, etc. in template components

Summary by Sourcery

Add get_classes method to simplify class management for template components and improve mixin handling

New Features:

  • Introduced instance.get_classes() method to easily retrieve and combine CSS classes for template components

Enhancements:

  • Refactored class generation logic to use a new get_classes() method
  • Modified mixin import order to support more flexible class application

Documentation:

  • Added example template components demonstrating the usage of get_classes() method

Tests:

  • Added example template components as practical demonstrations of the new functionality

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 28, 2025

Reviewer's Guide by Sourcery

This pull request introduces a get_classes method to the base model class for frontend components, refactors the get_attributes method to use the new method, reverses the order of mixins, and adds example template components.

Sequence diagram for get_attributes method

sequenceDiagram
  participant Instance as FrontendComponent Instance
  Instance->>Instance: get_attributes()
  Instance->>Instance: get_classes()
  Instance->>Instance: config.get("attributes", {})
  Instance->>Instance: additional_classes
  Instance->>Instance: conditional_escape(" ".join(classes))
  Instance-->>Instance: return classes
  Instance->>Instance: f'class="{classes}"'
  Instance->>Instance: attributes.items()
  Instance->>Instance: f'{item}="{conditional_escape(value)}"'
  Instance->>Instance: (classes + " " + parts).strip()
  Instance->>Instance: mark_safe(" " + attributes_string)
  Instance-->>Instance: return attributes_string
Loading

Updated class diagram for FrontendComponent

classDiagram
  class FrontendComponent {
    +config
    +additional_classes
    +add_attribute(attr, value)
    +get_attributes()
    +get_classes()
    +save(*args, **kwargs)
  }

  note for FrontendComponent.get_classes "New method to get classes from attributes and additional classes"
  note for FrontendComponent.get_attributes "Refactored to use get_classes method"
Loading

File-Level Changes

Change Details Files
Introduces a get_classes method to the base model class for frontend components.
  • Added a get_classes method to the base model class.
  • Refactored the get_attributes method to use the new get_classes method.
djangocms_frontend/models.py
Reverses the order of mixins to ensure correct application.
  • Reversed the order in which mixins are applied in the _get_mixin_classes function.
djangocms_frontend/component_base.py
Adds example template components.
  • Added a feature_icon template component.
  • Added a feature_hanging template component.
  • Added an icon_grid template component.
examples/templates/examples/cms_components/feature_icon.html
examples/templates/examples/cms_components/feature_hanging.html
examples/templates/examples/cms_components/icon_grid.html

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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 Mar 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.65%. Comparing base (15aecbb) to head (a9aa9cc).
Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #268      +/-   ##
==========================================
+ Coverage   88.64%   88.65%   +0.01%     
==========================================
  Files         124      124              
  Lines        3363     3367       +4     
  Branches      284      284              
==========================================
+ Hits         2981     2985       +4     
  Misses        264      264              
  Partials      118      118              

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

@fsbraun fsbraun marked this pull request as ready for review March 28, 2025 22:09
@fsbraun fsbraun merged commit 0f736a6 into master Mar 28, 2025
34 checks passed
@fsbraun fsbraun deleted the feat/get_classes branch March 28, 2025 22:09
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 - here's some feedback:

Overall Comments:

  • Consider adding a test case that specifically targets the get_classes method to ensure it functions as expected with different mixin combinations.
  • The change in component_base.py reverses the order of mixins; confirm this is intentional and doesn't break existing functionality.
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.

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