[change] Migrate from django-admin-autocomplete-filter to dalf #582
Replace the unmaintained and license-incompatible django-admin-autocomplete-filter with django-admin-list-filter (dalf), an actively maintained MIT-licensed alternative that uses Django's native admin autocomplete infrastructure.
Changes:
- Updated dependencies in setup.py to use dalf>=0.7.0,<1.0.0
- Rewrote AutocompleteFilter to extend DALFRelatedFieldAjax
- Simplified AutocompleteJsonView to use Django's native implementation
- Added robust error handling for invalid filter parameters (e.g., invalid UUIDs)
- Updated admin classes to inherit from DALFModelAdmin
- Modified filter usage from custom classes to tuple format
- Updated documentation and templates
- Fixed reverse relation support in autocomplete view
Fixes #582
Checklist
- [x] I have read the OpenWISP Contributing Guidelines.
- [x] I have manually tested the changes proposed in this pull request.
- [x] I have written new test cases for new code and/or updated existing tests for changes to existing code.
- [x] I have updated the documentation.
Reference to Existing Issue
Closes #582 .
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] βΆοΈ Resume reviews
- [ ] π Trigger review
π Walkthrough
Walkthrough
Replaces django-admin-autocomplete-filter with django-admin-list-filter (DALF) across code and docs. Updates dependency, tests, templates, JS, templatetags, admin integration, and examples to use DALF APIs and tuple-based list_filter syntax. AutocompleteFilter now subclasses DALFRelatedFieldAjax with an explicit init and persistent init-error handling. AutocompleteJsonView now extends Djangoβs native AutocompleteJsonView and implements get_queryset to handle reverse relations. Adds OpenwispAdminSite.autocomplete_view to dispatch the configured view. Includes tests, Selenium updates, and a migration adding related_name="books" to Book.shelf.
Sequence Diagram(s)
sequenceDiagram
participant Browser
participant DALF_JS as "DALF JS (ow-auto-filter.js)"
participant DjangoView as "AutocompleteJsonView (server)"
participant ORM as "Django ORM / DB"
Browser->>DALF_JS: user types in autocomplete/selects filter
DALF_JS->>DjangoView: AJAX GET /autocomplete/?q=... & data-field-name
DjangoView->>ORM: build queryset (handle reverse relations / related_name)
ORM-->>DjangoView: queryset results
DjangoView-->>DALF_JS: JSON response (choices)
DALF_JS-->>Browser: render/update select inputs / hidden fields
Estimated code review effort
π― 4 (Complex) | β±οΈ ~50 minutes
π₯ Pre-merge checks | β 4
β Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | β Passed | The title clearly and accurately summarizes the main objective of the pull request: migrating from django-admin-autocomplete-filter to dalf, which is the primary change across the codebase. |
| Description check | β Passed | The description includes completed checklist items, clear reference to the linked issue (#582), comprehensive summary of changes across multiple files and components, and acknowledges all key aspects of the migration. |
| Linked Issues check | β Passed | The pull request successfully addresses all acceptance criteria from issue #582: removes django-admin-autocomplete-filter dependency, achieves feature parity with AutocompleteFilter and AutocompleteJsonView rewrites, maintains Django version compatibility, introduces MIT-licensed dalf, and includes documentation updates. |
| Out of Scope Changes check | β Passed | All changes are directly scoped to the autocomplete filter migration. Minor additions like the _js_click helper method and migration file for related_name support are necessary supporting changes for the migration to function properly. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
@nemesifier whenever I run openwisp-qa-format it also goes through the env/ folder, which returns errror from the files inside it.
Ideally I think this shouldn't happen the format command shall ignore the env/ content .
https://github.com/user-attachments/assets/71832429-89ab-4d49-8093-f226a4a624dd
[!NOTE] DALF requires Python 3.11+ and Django 4.2+ for full compatibility. Projects using older versions may experience compatibility issues.
@nemesifier kindly review
@nemesifier whenever I run `openwisp-qa-format` it also goes through the `env/` folder, which returns errror from the files inside it. Ideally I think this shouldn't happen the format command shall ignore the `env/` content .
put the env in parent dir and then it would be fine
Hi @SAMurai-16 π,
This pull request has been marked as stale due to 30 days of inactivity after changes were requested.
As a result, the linked issue(s) have been unassigned from you to allow other contributors to work on it.
However, you can still continue working on this PR! If you push new commits or respond to the review feedback:
- The issue will be reassigned to you
- Your contribution is still very welcome
If you need more time or have questions about the requested changes, please let us know. We're happy to help! π€
If there's no further activity within 30 more days, this PR will be automatically closed (but can be reopened anytime).
Test Failures in openwisp-utils
Hello @SAMurai-16 and @nemesifier, (Analysis for commit 85091a5)
There is one test failure:
- Test Failure: The
test_autocomplete_shelf_filterintest_project.tests.test_seleniumis failing due to aTimeoutExceptionandNoSuchElementException. This indicates that the Selenium test could not find the element with the CSS selectorselect[data-field-name="shelf"] + span.select2 .select2-selectionwithin the expected timeout.
Fix: This often happens when the UI element is not present or takes longer to load than anticipated. Consider increasing the timeout in the wait_for_presence call or debugging the test to ensure the element's selector is correct and that the element is indeed rendered before the test attempts to interact with it. If the element's structure or class names have changed, update the selector accordingly.
Hi @SAMurai-16 π,
This pull request has been automatically closed due to 89 days of inactivity. After changes were requested, the PR remained inactive.
We understand that life gets busy, and we appreciate your initial contribution! π
The door is always open for you to come back:
- You can reopen this PR at any time if you'd like to continue working on it
- Feel free to push new commits addressing the requested changes
- If you reopen the PR, the linked issue will be reassigned to you
If you have any questions or need help, don't hesitate to reach out. We're here to support you!
Thank you for your interest in contributing to OpenWISP! π
Hi @SAMurai-16 π,
This pull request has been automatically closed due to 90 days of inactivity. After changes were requested, the PR remained inactive.
We understand that life gets busy, and we appreciate your initial contribution! π
The door is always open for you to come back:
- You can reopen this PR at any time if you'd like to continue working on it
- Feel free to push new commits addressing the requested changes
- If you reopen the PR, the linked issue will be reassigned to you
If you have any questions or need help, don't hesitate to reach out. We're here to support you!
Thank you for your interest in contributing to OpenWISP! π
Hi @SAMurai-16 π,
This pull request has been automatically closed due to 91 days of inactivity. After changes were requested, the PR remained inactive.
We understand that life gets busy, and we appreciate your initial contribution! π
The door is always open for you to come back:
- You can reopen this PR at any time if you'd like to continue working on it
- Feel free to push new commits addressing the requested changes
- If you reopen the PR, the linked issue will be reassigned to you
If you have any questions or need help, don't hesitate to reach out. We're here to support you!
Thank you for your interest in contributing to OpenWISP! π
@nemesifier whenever I run `openwisp-qa-format` it also goes through the `env/` folder, which returns errror from the files inside it. Ideally I think this shouldn't happen the format command shall ignore the `env/` content .