Remove unused arguments from APISelect widget

This commit is contained in:
Jeremy Stretch 2020-08-12 13:57:34 -04:00
parent e9e77fc689
commit 9e14e28d89
2 changed files with 6 additions and 28 deletions

View File

@ -1686,9 +1686,9 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
help_text="The lowest-numbered unit occupied by the device", help_text="The lowest-numbered unit occupied by the device",
widget=APISelect( widget=APISelect(
api_url='/api/dcim/racks/{{rack}}/elevation/', api_url='/api/dcim/racks/{{rack}}/elevation/',
disabled_indicator='device', attrs={
additional_query_params={ 'disabled-indicator': 'device',
'face': '$face' 'data-additional-query-param-face': "[\"$face\"]",
} }
) )
) )
@ -2077,9 +2077,7 @@ class DeviceFilterForm(BootstrapMixin, LocalConfigContextFilterForm, TenancyFilt
role = DynamicModelMultipleChoiceField( role = DynamicModelMultipleChoiceField(
queryset=DeviceRole.objects.all(), queryset=DeviceRole.objects.all(),
to_field_name='slug', to_field_name='slug',
required=False, required=False
widget=APISelectMultiple(
)
) )
manufacturer = DynamicModelMultipleChoiceField( manufacturer = DynamicModelMultipleChoiceField(
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),

View File

@ -123,22 +123,9 @@ class APISelect(SelectWithDisabled):
A select widget populated via an API call A select widget populated via an API call
:param api_url: API endpoint URL. Required if not set automatically by the parent field. :param api_url: API endpoint URL. Required if not set automatically by the parent field.
:param display_field: (Optional) Field to display for child in selection list. Defaults to `name`. :param full: Omit brief=true when fetching REST API results
:param disabled_indicator: (Optional) Mark option as disabled if this field equates true.
:param additional_query_params: Optional) A dict of query params to append to the API request. The key is the
name of the query param and the value if the query param's value.
""" """
def __init__( def __init__(self, api_url=None, full=False, *args, **kwargs):
self,
api_url=None,
display_field=None,
disabled_indicator=None,
additional_query_params=None,
full=False,
*args,
**kwargs
):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.attrs['class'] = 'netbox-select2-api' self.attrs['class'] = 'netbox-select2-api'
@ -146,13 +133,6 @@ class APISelect(SelectWithDisabled):
self.attrs['data-url'] = '/{}{}'.format(settings.BASE_PATH, api_url.lstrip('/')) # Inject BASE_PATH self.attrs['data-url'] = '/{}{}'.format(settings.BASE_PATH, api_url.lstrip('/')) # Inject BASE_PATH
if full: if full:
self.attrs['data-full'] = full self.attrs['data-full'] = full
if display_field:
self.attrs['display-field'] = display_field
if disabled_indicator:
self.attrs['disabled-indicator'] = disabled_indicator
if additional_query_params:
for key, value in additional_query_params.items():
self.add_additional_query_param(key, value)
def add_additional_query_param(self, name, value): def add_additional_query_param(self, name, value):
""" """