fix: Use Django admin autocomplete widgets in alias plugin form - #397
Merged
Conversation
The alias plugin form rolled its own select2 widgets on top of the `djangocms_alias_select2` / `djangocms_alias_category_list_select2` endpoints. Both fields now use Django admin's autocomplete widget and its `admin:autocomplete` endpoint instead: * `CategorySelectWidget` and `AliasSelectWidget` subclass `AutocompleteSelect` for `Alias.category` and `AliasPlugin.alias`. * `AliasAdmin.get_search_results` and `CategoryAdmin.get_search_results` apply the filtering the legacy views did (current language, categories that have aliases) plus the site/category the plugin form passes along. * `alias_plugin.js` initializes the two widgets the way `admin/js/autocomplete.js` does, but forwards the selected site and category; `create.js` is gone. The legacy select2 views stay in place for third-party code pointing at them. Fixes #361 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwNaBKq7MNLhibbjjiAYHM
`AliasSelect2View` and `CategorySelect2View` are no longer used by the alias plugin form, which autocompletes through `admin:autocomplete` now. Both raise a `DeprecationWarning` on dispatch, announcing removal in djangocms-alias 4.0. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwNaBKq7MNLhibbjjiAYHM
Contributor
Reviewer's GuideThe PR migrates the alias plugin form from custom Select2 endpoints to Django admin’s autocomplete widgets and endpoint, adding server-side contextual filtering and client-side site/category parameters while preserving legacy endpoints with deprecation warnings and expanding coverage. Sequence diagram for contextual alias plugin autocompletesequenceDiagram
participant Form as Alias plugin form
participant JS as alias_plugin.js
participant Admin as Django admin:autocomplete
participant CategoryAdmin
participant AliasAdmin
participant DB as Database
Form->>JS: djangocmsAliasSelect2()
JS->>Admin: autocomplete request with site, category, and search term
alt Category field
Admin->>CategoryAdmin: get_search_results(request, queryset, search_term)
CategoryAdmin->>DB: Filter categories with aliases and selected site
DB-->>CategoryAdmin: Matching categories
CategoryAdmin-->>Admin: Ordered category results
else Alias field
Admin->>AliasAdmin: get_search_results(request, queryset, search_term)
AliasAdmin->>DB: Filter language, category, and selected site
DB-->>AliasAdmin: Matching aliases
AliasAdmin-->>Admin: Ordered alias results
end
Admin-->>JS: JSON autocomplete results
JS-->>Form: Update Select2 choices
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
fsbraun
added a commit
that referenced
this pull request
Aug 27, 2026
#396 and #397 landed upstream in the meantime; #396 was merged before the matrix was trimmed. Resolved every conflict under tests/requirements/, tox.ini and compile.py in favour of this branch, so the trimmed matrix stands: django CMS 5.0 only at py311-dj52 and py314-dj61, django CMS 5.1 across the full Python/Django matrix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwNaBKq7MNLhibbjjiAYHM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Replace the alias plugin's custom Select2 endpoints with Django admin autocomplete integration while preserving context-sensitive choices and compatibility warnings.
New Features:
Bug Fixes:
Enhancements:
Tests:
Related resources
Checklist