-
Notifications
You must be signed in to change notification settings - Fork 33
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
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis 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 contextsequenceDiagram
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
Class diagram for updated FakeFilter and language lookupsclassDiagram
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
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>
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} |
There was a problem hiding this comment.
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>
…s-versioning into fix/site-lang-config
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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
, andmodel_admin
). If it does not accept them, the fake filter falls back to the original lookup call.Related resources
Checklist
master
Slack to find a “pr review buddy” who is going to review my pull request.