Commit Graph

22 Commits

Author SHA1 Message Date
Jason Novinger
9491356c7e Require registered filterset for filter modifier enhancements
Some checks are pending
CI / build (20.x, 3.12) (push) Waiting to run
CI / build (20.x, 3.13) (push) Waiting to run
Updates FilterModifierMixin to only enhance form fields when the
associated model has a registered filterset. This provides plugin
safety by ensuring unregistered plugin filtersets fall back to
simple filters without lookup modifiers.

Test changes:
- Create TestModel and TestFilterSet using BaseFilterSet for
automatic lookup generation
- Import dcim.filtersets to ensure Device filterset registration
- Adjust tag field expectations to match actual Device filterset
(has exact/n but not empty lookups)
2025-12-04 14:46:27 -06:00
Jason Novinger
807a22db23 Remove comparison symbols from numeric filter labels 2025-12-04 14:46:27 -06:00
Jason Novinger
8de87140cc Fix applied_filters template tag to use field-type-specific lookup labelsresolves
E.g. resolves gt="after" for dates vs "greater than" for numbers
2025-12-04 14:46:27 -06:00
Jason Novinger
a2b1796ffc Switch to sentence case for filter pill text 2025-12-04 14:46:27 -06:00
Jason Novinger
2c73593f1a Removed explicit checks against QueryField and [Null]BooleanField
I did add them to FORM_FIELD_LOOKUPS, though, to underscore that they
were considered and are intentially empty for future devs.
2025-12-04 14:46:27 -06:00
Jason Novinger
9990d9c44f Enables filter modifiers on APISelect based fields 2025-12-04 14:46:27 -06:00
Jason Novinger
fe8563d625 Refactor register_filterset to be more generic and simple 2025-12-04 14:46:27 -06:00
Jason Novinger
c419fe08d4 Address PR feedback: refactor brittle test for APISelect useage
Now checks if widget is actually APISelect, rather than trying to infer
from the class name.
2025-12-04 14:46:27 -06:00
Jason Novinger
0810333334 Fix registry pattern to use model identifiers as keys
Changed filterset registration to use model identifiers ('{app_label}.{model_name}')
as registry keys instead of form classes, matching NetBox's pattern for search indexes.
2025-12-04 14:46:27 -06:00
Jason Novinger
38aae88757 Address PR feedback: Rename FilterModifierWidget parameter to widget 2025-12-04 14:46:27 -06:00
Jason Novinger
1ed357de3b Address PR feedback: Refactor and consolidate field filtering logic
Consolidated field enhancement logic in FilterModifierMixin by:
- Creating QueryField marker type (CharField subclass) for search fields
- Updating FilterForm and NetBoxModelFilterSetForm to use QueryField for 'q'
- Moving all skip logic into _get_lookup_choices() to return empty list for
  fields that shouldn't be enhanced
- Removing separate _should_skip_field() method
- Removing unused field_name parameter from _get_lookup_choices()
- Replacing hardcoded field name check ('q') with type-based detection
2025-12-04 14:46:27 -06:00
Jason Novinger
c7c8cfd5f5 Address PR feedback: Move FORM_FIELD_LOOKUPS to module-level constant
Extracts the field type to lookup mappings from FilterModifierMixin class
attribute to a module-level constant for better reusability.
2025-12-04 14:46:27 -06:00
Jason Novinger
e1404daf8c Address PR feedback: Replace global filterset mappings with registry 2025-12-04 14:46:03 -06:00
Jason Novinger
7c66636f30 Add ChoiceField support to FilterModifierMixin
Enable filter modifiers for single-choice ChoiceFields in addition to the
existing MultipleChoiceField support. ChoiceFields can now display modifier
dropdowns with "Is", "Is Not", "Is Empty", and "Is Not Empty" options when
the corresponding FilterSet defines those lookups.

The mixin correctly verifies lookup availability against the FilterSet, so
modifiers only appear when multiple lookup options are actually supported.
Currently most FilterSets only define 'exact' for single-choice fields, but
this change enables future FilterSet enhancements to expose additional
lookups for ChoiceFields.
2025-12-04 14:46:03 -06:00
Jason Novinger
8445a63786 Fixes #7604: Add filter modifier dropdowns for advanced lookup operators
Implements dynamic filter modifier UI that allows users to select lookup operators
(exact, contains, starts with, regex, negation, empty/not empty) directly in filter
forms without manual URL parameter editing.

Supports filters for all scalar types and strings, as well as some
related object filters. Explicitly does not support filters on fields
that use APIWidget. That has been broken out in to follow up work.

**Backend:**
- FilterModifierWidget: Wraps form widgets with lookup modifier dropdown
- FilterModifierMixin: Auto-enhances filterset fields with appropriate lookups
- Extended lookup support: Adds negation (n), regex, iregex, empty_true/false lookups
- Field-type-aware: CharField gets text lookups, IntegerField gets comparison operators, etc.

**Frontend:**
- TypeScript handler syncs modifier dropdown with URL parameters
- Dynamically updates form field names (serial → serial__ic) on modifier change
- Flexible-width modifier dropdowns with semantic CSS classes
2025-12-04 14:45:20 -06:00
Jeremy Stretch
5df4c63f28 #19891: Fix duplicate background_job fields on bulk edit forms without fieldsets defined 2025-08-14 14:40:01 -04:00
Jeremy Stretch
cebc56e5cc Closes #19891: Bulk operation jobs (#19897)
* Add background_job toggle to BulkEditForm

* Account for bug fix in v4.3.4

* Enable background jobs for bulk edit & bulk delete

* Move background_job field to a mixin

* Cosmetic improvements

* Misc cleanup

* Fix BackgroundJobMixin
2025-07-18 08:24:38 -05:00
Jason Novinger
a2a8779ebc Fixes #19415: Increased Circuit/WirelessLink distance upper limit (#19495)
* Fixes #19415: Increased Circuit/WirelessLink absolute distance upper limit

Also adds form validation that provides a useful message to the user
rather than a 500 error with potentially little information.

* Include forgotten migration files

* Remove unnecessary comments

* Remove more unnecessary comments

* Addresses PR feedback

* Gah, remove django migration header comment

* Clean up new has_field_errors mechanism, fix issue with ObjectAttribute

* Address PR feedback, revert changes to render_fieldset template tag
2025-05-19 08:38:30 -04:00
Jeremy Stretch
da085e60c2 Closes #14740: Remove BootstrapMixin (#14841)
* Introduce custom form widget templates to apply CSS classes

* Apply both mandatory and optional CSS classes to form widgets

* Omit required & placeholder attrs

* Move annotation of field validation failures to CSS

* Remove BootstrapMixin class

* Remove obsolete ComponentTemplateImportForm class

* Remove obsolete custom forms for login & password change

* Clean up obsolete accommodations for 'required' widget attr
2024-01-19 14:02:33 -05:00
Jeremy Stretch
43e6308d90 Closes #11732: Protect against errant overwriting of data via web UI forms 2023-08-01 09:06:51 -04:00
jeremystretch
b7f028fba3 Fixes #12550: Fix rear port selection widget under front port creation form 2023-05-10 10:44:01 -04:00
Jeremy Stretch
d470848b29 Closes #12246: General cleanup of utilities modules
* Clean up base modules

* Clean up forms modules

* Clean up templatetags modules

* Replace custom simplify_decimal filter with floatformat

* Misc cleanup

* Merge ReturnURLForm into ConfirmationForm

* Clean up import statements for utilities.forms

* Fix field class references in docs
2023-04-14 10:33:53 -04:00