mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Add brief_mode to DynamicModelChoiceMixin
This commit is contained in:
@@ -251,16 +251,18 @@ class DynamicModelChoiceMixin:
|
||||
:param null_option: The string used to represent a null selection (if any)
|
||||
:param disabled_indicator: The name of the field which, if populated, will disable selection of the
|
||||
choice (optional)
|
||||
:param brief_mode: Use the "brief" format (?brief=true) when making API requests (default)
|
||||
"""
|
||||
filter = django_filters.ModelChoiceFilter
|
||||
widget = widgets.APISelect
|
||||
|
||||
def __init__(self, *args, display_field='name', query_params=None, null_option=None, disabled_indicator=None,
|
||||
**kwargs):
|
||||
def __init__(self, display_field='name', query_params=None, null_option=None, disabled_indicator=None,
|
||||
brief_mode=True, *args, **kwargs):
|
||||
self.display_field = display_field
|
||||
self.query_params = query_params or {}
|
||||
self.null_option = null_option
|
||||
self.disabled_indicator = disabled_indicator
|
||||
self.brief_mode = brief_mode
|
||||
|
||||
# to_field_name is set by ModelChoiceField.__init__(), but we need to set it early for reference
|
||||
# by widget_attrs()
|
||||
@@ -285,6 +287,10 @@ class DynamicModelChoiceMixin:
|
||||
if self.disabled_indicator is not None:
|
||||
attrs['disabled-indicator'] = self.disabled_indicator
|
||||
|
||||
# Toggle brief mode
|
||||
if not self.brief_mode:
|
||||
attrs['data-full'] = 'true'
|
||||
|
||||
# Attach any static query parameters
|
||||
for key, value in self.query_params.items():
|
||||
widget.add_query_param(key, value)
|
||||
|
@@ -123,7 +123,6 @@ class APISelect(SelectWithDisabled):
|
||||
A select widget populated via an API call
|
||||
|
||||
:param api_url: API endpoint URL. Required if not set automatically by the parent field.
|
||||
:param full: Omit brief=true when fetching REST API results
|
||||
"""
|
||||
def __init__(self, api_url=None, full=False, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -131,8 +130,6 @@ class APISelect(SelectWithDisabled):
|
||||
self.attrs['class'] = 'netbox-select2-api'
|
||||
if api_url:
|
||||
self.attrs['data-url'] = '/{}{}'.format(settings.BASE_PATH, api_url.lstrip('/')) # Inject BASE_PATH
|
||||
if full:
|
||||
self.attrs['data-full'] = full
|
||||
|
||||
def add_query_param(self, name, value):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user