Skip to content

fix: Use Django admin autocomplete widgets in alias plugin form - #397

Merged
fsbraun merged 3 commits into
masterfrom
fix/361-admin-autocomplete-widgets
Aug 27, 2026
Merged

fix: Use Django admin autocomplete widgets in alias plugin form#397
fsbraun merged 3 commits into
masterfrom
fix/361-admin-autocomplete-widgets

Conversation

@fsbraun

@fsbraun fsbraun commented Aug 27, 2026

Copy link
Copy Markdown
Member

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:

  • Use Django admin autocomplete widgets for alias plugin category and alias selection with site, category, and language-aware filtering.

Bug Fixes:

  • Ensure autocomplete choices are limited to valid aliases and categories for the current plugin context.

Enhancements:

  • Deprecate the legacy alias and category Select2 endpoints in favor of Django admin's autocomplete endpoint.

Tests:

  • Add coverage for widget configuration, autocomplete permissions, filtering, ordering, language, site, and deprecation warnings.

Related resources

Checklist

fsbraun and others added 2 commits August 27, 2026 16:48
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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry @fsbraun, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The 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 autocomplete

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Replace custom Select2 endpoints and widgets with Django admin autocomplete integration.
  • Build category and alias fields with AutocompleteSelect and preserve form placeholders.
  • Customize admin search results for language, category, site, alias availability, and stable ordering.
  • Add client-side autocomplete initialization that forwards selected site and category filters.
djangocms_alias/admin.py
djangocms_alias/forms.py
djangocms_alias/static/djangocms_alias/js/alias_plugin.js
djangocms_alias/static/djangocms_alias/css/autocomplete.css
Retain legacy autocomplete endpoints as deprecated compatibility APIs.
  • Emit DeprecationWarning from both legacy Select2 views.
  • Document migration to admin:autocomplete.
djangocms_alias/views.py
Validate widget configuration, autocomplete filtering, ordering, permissions, and deprecation behavior.
  • Test admin autocomplete widget attributes and media ordering.
  • Test language, search-term, category, site, and category-availability filtering.
  • Test staff access requirements and legacy endpoint warnings.
tests/test_cms_plugins.py
tests/test_views.py
Remove obsolete custom Select2 initialization and endpoint-specific form wiring.
  • Delete the legacy create.js asset.
  • Remove custom endpoint URL construction and old widget rendering logic.
djangocms_alias/static/djangocms_alias/js/create.js
djangocms_alias/forms.py

Assessment against linked issues

Issue Objective Addressed Explanation
#361 Replace the alias plugin form's outdated custom Select2 widgets with Django admin's autocomplete widgets, using Django admin's jQuery and Select2 assets.
#361 Ensure category and alias autocomplete requests provide the plugin's site/category context and return appropriately filtered, language-aware choices.
#361 Retain compatibility for the previous Select2 endpoints while directing new integrations to the Django admin autocomplete endpoint.

Possibly linked issues


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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@fsbraun
fsbraun merged commit 35e90ac into master Aug 27, 2026
7 checks passed
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
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.

BUG: forms use outdated CMS select2 widget

1 participant