-
Notifications
You must be signed in to change notification settings - Fork 65
fix: Show internal links in the language of the plugin #250
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 GuideAdds language awareness to internal link widgets by passing the plugin’s language through widget initialization, URL generation, form fields, and plugin form rendering. Sequence diagram for plugin form rendering with language-aware internal linkssequenceDiagram
participant Admin as actor Admin User
participant PluginAdmin as PluginAdmin
participant PluginForm as PluginForm
participant LinkWidget as LinkWidget
participant InternalLinkWidget as LinkAutoCompleteWidget
Admin->>PluginAdmin: Open plugin add/edit form
PluginAdmin->>PluginForm: get_form(request, obj)
PluginForm->>LinkWidget: Initialize with language=plugin.language
LinkWidget->>InternalLinkWidget: Set language attribute
InternalLinkWidget->>InternalLinkWidget: get_url() includes ?language=plugin.language
PluginForm-->>PluginAdmin: Return form with language-aware widgets
PluginAdmin-->>Admin: Render form with internal links in plugin language
Class diagram for language-aware LinkWidget and related classesclassDiagram
class LinkAutoCompleteWidget {
+language: str | None
+get_url()
}
class LinkWidget {
+language: str | None
+__init__(site_selector: bool | None, language: str | None)
}
class LinkFormField {
+widget: LinkWidget
+__init__(..., language: str | None)
}
class LinkField {
+formfield(...)
}
LinkWidget --> LinkAutoCompleteWidget : uses
LinkFormField --> LinkWidget : has
LinkField --> LinkFormField : formfield()
File-Level Changes
Assessment against linked issues
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 and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `djangocms_link/cms_plugins.py:63` </location>
<code_context>
+ language = getattr(obj, "language", None)
+ else:
+ language = request.GET.get("plugin_language", None)
+ for widget in self.fields["link"].widget.widgets:
+ widget.language = language
+ return form
</code_context>
<issue_to_address>
Directly mutating widget.language may cause issues if widgets are shared across forms.
Mutating shared widget instances can cause side effects. Ensure each form uses unique widget instances or clone them before modifying the language attribute.
</issue_to_address>
### Comment 2
<location> `djangocms_link/fields.py:375` </location>
<code_context>
super().__init__(*args, **kwargs)
def formfield(self, **kwargs):
+ print("LinkField.formfield", kwargs)
kwargs.setdefault("form_class", LinkFormField)
return super().formfield(**kwargs)
</code_context>
<issue_to_address>
Debug print statement left in production code.
Please remove this print statement before merging to avoid unnecessary console output and potential information exposure.
</issue_to_address>
### Comment 3
<location> `djangocms_link/fields.py:255` </location>
<code_context>
- },
- ),
- ) # Site selector
+ widgets[index].language = language # Pass on language to the internal link widget
+ if site_selector:
+ widgets.insert(
</code_context>
<issue_to_address>
Assigning language directly to widget may not propagate as expected if widgets are reused.
Directly setting the language on shared widget instances can lead to side effects. Ensure each form uses unique widget instances or use a safer way to handle language context.
</issue_to_address>
### Comment 4
<location> `djangocms_link/fields.py:310` </location>
<code_context>
kwargs.setdefault("initial", {})
kwargs.pop("encoder", None) # Passed from LinkField's JSONField parent class
kwargs.pop("decoder", None) # but not needed
+ self.widget = LinkWidget(language=kwargs.pop("language", None))
super().__init__(*args, **kwargs)
if isinstance(self.initial, dict):
</code_context>
<issue_to_address>
Overriding self.widget in __init__ may break expected widget customization via kwargs.
Setting self.widget here ignores any widget provided in kwargs. To preserve customization, check for a widget in kwargs before assigning a default.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #250 +/- ##
==========================================
- Coverage 96.31% 95.91% -0.40%
==========================================
Files 28 28
Lines 706 735 +29
Branches 98 104 +6
==========================================
+ Hits 680 705 +25
- Misses 9 10 +1
- Partials 17 20 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@krosefield Fallback languages still active? If no, the gap probably should go away. If yes, the fallback title should be shown. |
…k into fix/target-lang
Description
When adding or editing a plugin, the plugin fields are in the language of the plugin (not the admin language). This also needs to hold for the internal links. This PR adjusts the language of the internal link dropdown. (The dropdown still uses fallback languages if necessary and available.)
Additionally, the link to internal pages shown in the structure board now reflects the language that is edited (i.e., show
/it/pagina/
instead of/en/page/
as a short description in the structure board when editing Italian content).Dutch, German and French locales are updated.
Fixes #249
Tests are to be added.
@krosefield Please be invited to test.
Related resources
Checklist
master
Slack to find a “pr review buddy” who is going to review my pull request.