mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Remove StaticSelect, StaticSelectMultiple form widgets * Tag custom ChoiceField, MultipleChoiceField classes for removal in v3.6
This commit is contained in:
committed by
jeremystretch
parent
c73829fe92
commit
b9bd96f0c7
@@ -27,11 +27,11 @@ class ContentTypeChoiceField(ContentTypeChoiceMixin, forms.ModelChoiceField):
|
||||
"""
|
||||
Selection field for a single content type.
|
||||
"""
|
||||
widget = widgets.StaticSelect
|
||||
pass
|
||||
|
||||
|
||||
class ContentTypeMultipleChoiceField(ContentTypeChoiceMixin, forms.ModelMultipleChoiceField):
|
||||
"""
|
||||
Selection field for one or more content types.
|
||||
"""
|
||||
widget = widgets.StaticSelectMultiple
|
||||
pass
|
||||
|
@@ -68,7 +68,6 @@ class TagFilterField(forms.MultipleChoiceField):
|
||||
|
||||
:param model: The model of the filter
|
||||
"""
|
||||
widget = widgets.StaticSelectMultiple
|
||||
|
||||
def __init__(self, model, *args, **kwargs):
|
||||
def get_choices():
|
||||
@@ -137,13 +136,16 @@ class MACAddressField(forms.Field):
|
||||
|
||||
class ChoiceField(forms.ChoiceField):
|
||||
"""
|
||||
Overrides Django's built-in `ChoiceField` to use NetBox's `StaticSelect` widget
|
||||
Previously used to override Django's built-in `ChoiceField` to use NetBox's now-obsolete `StaticSelect` widget.
|
||||
"""
|
||||
widget = widgets.StaticSelect
|
||||
# TODO: Remove in v3.6
|
||||
pass
|
||||
|
||||
|
||||
class MultipleChoiceField(forms.MultipleChoiceField):
|
||||
"""
|
||||
Overrides Django's built-in `MultipleChoiceField` to use NetBox's `StaticSelectMultiple` widget
|
||||
Previously used to override Django's built-in `MultipleChoiceField` to use NetBox's now-obsolete
|
||||
`StaticSelectMultiple` widget.
|
||||
"""
|
||||
widget = widgets.StaticSelectMultiple
|
||||
# TODO: Remove in v3.6
|
||||
pass
|
||||
|
@@ -9,7 +9,7 @@ from django.utils.translation import gettext as _
|
||||
|
||||
from utilities.choices import ImportFormatChoices
|
||||
from utilities.forms.utils import parse_csv
|
||||
from .widgets import APISelect, APISelectMultiple, ClearableFileInput, StaticSelect
|
||||
from .widgets import APISelect, APISelectMultiple, ClearableFileInput
|
||||
|
||||
__all__ = (
|
||||
'BootstrapMixin',
|
||||
@@ -37,27 +37,27 @@ class BootstrapMixin:
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
exempt_widgets = [
|
||||
forms.CheckboxInput,
|
||||
forms.FileInput,
|
||||
forms.RadioSelect,
|
||||
forms.Select,
|
||||
APISelect,
|
||||
APISelectMultiple,
|
||||
ClearableFileInput,
|
||||
StaticSelect,
|
||||
]
|
||||
|
||||
for field_name, field in self.fields.items():
|
||||
css = field.widget.attrs.get('class', '')
|
||||
|
||||
if field.widget.__class__ not in exempt_widgets:
|
||||
field.widget.attrs['class'] = f'{css} form-control'
|
||||
if field.widget.__class__ in exempt_widgets:
|
||||
continue
|
||||
|
||||
elif isinstance(field.widget, forms.CheckboxInput):
|
||||
field.widget.attrs['class'] = f'{css} form-check-input'
|
||||
|
||||
elif isinstance(field.widget, forms.Select):
|
||||
field.widget.attrs['class'] = f'{css} form-select'
|
||||
field.widget.attrs['class'] = f'{css} netbox-static-select'
|
||||
|
||||
else:
|
||||
field.widget.attrs['class'] = f'{css} form-control'
|
||||
|
||||
if field.required and not isinstance(field.widget, forms.FileInput):
|
||||
field.widget.attrs['required'] = 'required'
|
||||
@@ -165,8 +165,7 @@ class ImportForm(BootstrapMixin, forms.Form):
|
||||
)
|
||||
format = forms.ChoiceField(
|
||||
choices=ImportFormatChoices,
|
||||
initial=ImportFormatChoices.AUTO,
|
||||
widget=StaticSelect()
|
||||
initial=ImportFormatChoices.AUTO
|
||||
)
|
||||
|
||||
data_field = 'data'
|
||||
|
@@ -21,8 +21,6 @@ __all__ = (
|
||||
'SelectSpeedWidget',
|
||||
'SelectWithPK',
|
||||
'SlugWidget',
|
||||
'StaticSelect',
|
||||
'StaticSelectMultiple',
|
||||
'TimePicker',
|
||||
)
|
||||
|
||||
@@ -68,26 +66,7 @@ class BulkEditNullBooleanSelect(forms.NullBooleanSelect):
|
||||
self.attrs['class'] = 'netbox-static-select'
|
||||
|
||||
|
||||
class StaticSelect(forms.Select):
|
||||
"""
|
||||
A static <select/> form widget which is client-side rendered.
|
||||
"""
|
||||
option_template_name = 'widgets/select_option.html'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.attrs['class'] = 'netbox-static-select'
|
||||
|
||||
|
||||
class StaticSelectMultiple(StaticSelect, forms.SelectMultiple):
|
||||
"""
|
||||
Extends `StaticSelect` to support multiple selections.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class SelectWithPK(StaticSelect):
|
||||
class SelectWithPK(forms.Select):
|
||||
"""
|
||||
Include the primary key of each option in the option label (e.g. "Router7 (4721)").
|
||||
"""
|
||||
|
Reference in New Issue
Block a user