Skip to content

fix: Respect site-specific language configurations #480

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Aug 8, 2025

Description

The language fake filters only offered languages of the current site, ignored the site provided by the request object.

The changes in admin.py are in lines 660ff - the rest are ruff format changes. Essentially, the lookup function now can get two parameters (request, and model_admin). If it does not accept them, the fake filter falls back to the original lookup call.

Related resources

  • #...
  • #...

Checklist

  • I have opened this pull request against master
  • 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 #workgroup-pr-review on
    Slack to find a “pr review buddy” who is going to review my pull request.

Copy link
Contributor

sourcery-ai bot commented Aug 8, 2025

Reviewer's Guide

This PR refactors the language filtering mechanism in the admin to respect the site specified in the incoming request by extending the FakeFilter lookups to accept the request context and updating the version_list_filter_lookups to derive languages from the current site.

Sequence diagram for language filter lookups with site-specific context

sequenceDiagram
    participant AdminUser as actor Admin User
    participant AdminView as Admin View
    participant FakeFilter as FakeFilter
    participant LookupsFunc as Language Lookups Function
    participant Site as Site

    AdminUser->>AdminView: Request admin changelist (with site context)
    AdminView->>FakeFilter: get_list_filter(request)
    FakeFilter->>LookupsFunc: lookups_(request, model_admin)
    LookupsFunc->>Site: get_current_site(request)
    Site-->>LookupsFunc: Return site-specific languages
    LookupsFunc-->>FakeFilter: Return language choices
    FakeFilter-->>AdminView: Return filter options
    AdminView-->>AdminUser: Render changelist with site-specific language filter
Loading

Class diagram for updated FakeFilter and language lookups

classDiagram
    class FakeFilter {
        +lookups(request, model_admin)
    }
    class VersioningCMSConfig {
        +version_list_filter_lookups
    }
    class get_language_tuple {
        +__call__(site_id)
    }
    class get_current_site {
        +__call__(request)
    }
    VersioningCMSConfig --> FakeFilter : uses
    FakeFilter --> get_language_tuple : calls
    get_language_tuple --> get_current_site : uses site_id
    FakeFilter --> VersioningCMSConfig : uses version_list_filter_lookups
Loading

File-Level Changes

Change Details Files
Language fake filters now accept request-aware lookup functions
  • Changed FakeFilter.lookups to call lookups_(request, model_admin)
  • Added try/except to fall back to legacy signature when TypeError
  • Adjusted queryset generation for SimpleListFilter in get_list_filter
djangocms_versioning/admin.py
Language filter configuration uses current site ID
  • Replaced static get_language_tuple with a lambda that passes get_current_site(request).pk
  • Updated version_list_filter_lookups in VersioningCMSConfig
djangocms_versioning/cms_config.py

Possibly linked issues

  • #0: The PR fixes the language filter to show all options by respecting site-specific language configurations.

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 @fsbraun - I've reviewed your changes - here's some feedback:

  • fake_filter_factory’s fallback via a broad TypeError catch may hide unrelated errors; consider using inspect.signature to detect zero‐ vs two‐arg lookups (and emit a clear deprecation warning) instead of catching all TypeErrors.
  • Add a focused test to verify that the language FakeFilter now calls get_language_tuple with get_current_site(request) so that per-site language settings are actually respected.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- fake_filter_factory’s fallback via a broad TypeError catch may hide unrelated errors; consider using inspect.signature to detect zero‐ vs two‐arg lookups (and emit a clear deprecation warning) instead of catching all TypeErrors.
- Add a focused test to verify that the language FakeFilter now calls get_language_tuple with get_current_site(request) so that per-site language settings are actually respected.

## Individual Comments

### Comment 1
<location> `djangocms_versioning/cms_config.py:344` </location>
<code_context>
             grouper_field_name="page",
             extra_grouping_fields=["language"],
-            version_list_filter_lookups={"language": get_language_tuple},
+            version_list_filter_lookups={
+                "language": lambda request, _: get_language_tuple(site_id=get_current_site(request).pk)
+            },
             copy_function=copy_page_content,
</code_context>

<issue_to_address>
The lambda for 'language' in version_list_filter_lookups may not be compatible with all usages.

Check that all calls to version_list_filter_lookups now provide both arguments, or update the lambda to handle both one and two arguments for compatibility.
</issue_to_address>

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.

@@ -1449,7 +1409,7 @@ def changelist_view(self, request, extra_context=None):

if grouper:
# CAVEAT: as the breadcrumb trails expect a value for latest content in the template
extra_context["latest_content"] = ({"pk": None})
extra_context["latest_content"] = {"pk": None}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Extract code out into method (extract-method)

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>
Copy link

codecov bot commented Aug 8, 2025

Codecov Report

❌ Patch coverage is 91.30435% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.70%. Comparing base (a132204) to head (531f6a2).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
djangocms_versioning/admin.py 92.30% 3 Missing ⚠️
djangocms_versioning/cms_config.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #480      +/-   ##
==========================================
+ Coverage   90.55%   93.70%   +3.15%     
==========================================
  Files          72       76       +4     
  Lines        2732     2702      -30     
  Branches      322        0     -322     
==========================================
+ Hits         2474     2532      +58     
+ Misses        182      170      -12     
+ Partials       76        0      -76     

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

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.

1 participant