8000 fix: Grouper models must not assume language grouper by fsbraun · Pull Request #8194 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Grouper models must not assume language grouper #8194

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 9 commits into from
Mar 31, 2025

Conversation

fsbraun
Copy link
Member
@fsbraun fsbraun commented Mar 31, 2025

Description

Fixes #8193 Needs to be backported to CMS 4.1

The whole test of the cms.admin.utils module assume the presence of a language field. This PR adds the same tests for a grouper/content model without language as a grouping field.

Related resources

Checklist

  • I have opened this pull request against main
  • 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

Add support for grouper models without a language field in the admin interface

Bug Fixes:

  • Fix validation logic in content form to handle models without a language field
  • Update admin change list and form handling for models without explicit language support

Enhancements:

  • Extend the admin utilities to support grouper models that do not have a language grouping field
  • Create a new test setup for simple grouper models without language-specific content

Tests:

  • Add comprehensive test cases for simple grouper models
  • Implement test scenarios for creating, updating, and displaying content for non-language-specific grouper models

@fsbraun fsbraun added needs to be backported Commits need to be backported 4.1 5.0 labels Mar 31, 2025
Copy link
Contributor
sourcery-ai bot commented Mar 31, 2025

Reviewer's Guide by Sourcery

This pull request adds tests for grouper models without a language field, ensuring that the admin interface functions correctly in these cases. It also fixes a validation error that occurred when the language field was not present.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added tests for grouper models without a language field.
  • Created a new SimpleGrouperModel and SimpleGrouperModelContent model for testing.
  • Created a SimpleGrouperAdmin to manage the new models in the admin interface.
  • Added a SimpleSetupMixin to set up the test environment for the new models.
  • Created SimpleChangeListActionsTestCase, SimpleGrouperChangeListTestCase, and SimpleGrouperChangeTestCase to test the admin functionality for the new models.
cms/tests/test_grouper_admin.py
cms/test_utils/project/sampleapp/models.py
cms/test_utils/project/sampleapp/admin.py
Modified existing tests to work with both types of grouper models.
  • Adjusted assertions in ChangeListActionsTestCase to accommodate models without a language field.
  • Reordered the inheritance of ChangeListActionsTestCase to inherit from SimpleChangeListActionsTestCase.
cms/tests/test_grouper_admin.py
Fixed a validation error in cms.admin.utils when the language field is not present.
  • Added a check to ensure that the CONTENT_PREFIX + "language" key exists in self.cleaned_data before attempting to access its value.
cms/admin/utils.py

Assessment against linked issues

Issue Objective Addressed Explanation
#8193 Allow creation of model instances in the admin interface when the model does not have a language field.
#8193 Ensure the admin interface functions correctly for grouper/content models without language fields.

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

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 renaming SimpleChangeListActionsTestCase to ChangeListActionsTestCase and ChangeListActionsTestCase to LanguageAwareChangeListActionsTestCase to better reflect their purpose.
  • It might be cleaner to use inheritance or mixins to avoid duplicating the setup logic in SetupMixin and SimpleSetupMixin.
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 and others added 8 commits March 31, 2025 11:47
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@fsbraun fsbraun changed the title fix: Grouper models w/o language grouper fix: Grouper models w/o must not assume language grouper Mar 31, 2025
@fsbraun fsbraun requested a review from Copilot March 31, 2025 09:52
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the assumption that all grouper models must have a language field by adding support and tests for simple grouper models without a language grouping field.

  • Added new test mixins and test cases for SimpleGrouperModel and SimpleGrouperModelContent.
  • Introduced new fields (region, uptodate, secret_greeting) in GrouperModelContent and similar definitions for simple grouper models.
  • Updated URL construction in tests and modified validation logic in the admin utilities module to handle models lacking a language field.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
cms/tests/test_grouper_admin.py Added new test classes for simple grouper models; updated URL formatting and checks.
cms/test_utils/project/sampleapp/models.py Added new fields and model definitions for handling content groupers without language.
cms/test_utils/project/sampleapp/admin.py Introduced SimpleGrouperAdmin to display simple grouper model details in the admin.
cms/admin/utils.py Modified language field validation to use get_language_list instead of get_language_dict.
Comments suppressed due to low confidence (2)

cms/tests/test_grouper_admin.py:30

  • [nitpick] The variable 'groupermodel' is defined alongside 'grouper_model', which could be confusing. Consider using a consistent naming convention to clearly differentiate the two or merge them if they serve the same purpose.
self.groupermodel = "groupermodel"

cms/tests/test_grouper_admin.py:347

  • [nitpick] There appears to be a duplicate check for the hidden input field for content language. Verify if the extra check is intentional or if it should be removed to avoid redundancy.
self.assertContains(response, '<input type="hidden" name="content__language" value="en" id="id_content__language">',)

@vinitkumar vinitkumar merged commit 2efae8e into develop-4 Mar 31, 2025
65 checks passed
@fsbraun fsbraun deleted the fix/grouper-admin branch April 2, 2025 16:23
fsbraun added a commit that referenced this pull request Apr 2, 2025
* fix: Grouper models w/o language grouper

* Keep language field, but not as grouper

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/admin/utils.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix ruff issues

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
fsbraun added a commit that referenced this pull request Apr 2, 2025
* fix: Grouper models w/o must not assume language grouper (#8194)

* fix: Grouper models w/o language grouper

* Keep language field, but not as grouper

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/admin/utils.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update cms/tests/test_grouper_admin.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix ruff issues

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Fix ruff linting

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@fsbraun fsbraun changed the title fix: Grouper models w/o must not assume language grouper fix: Grouper models must not assume language grouper May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.1 5.0 needs to be backported Commits need to be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] CMS4: Unable to create model instances via the admin when not using language field
2 participants
0