mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Add disabled_indicator to DynamicModelChoiceMixin
This commit is contained in:
@ -3422,12 +3422,10 @@ class ConnectCableToConsolePortForm(ConnectCableToDeviceForm):
|
|||||||
termination_b_id = DynamicModelChoiceField(
|
termination_b_id = DynamicModelChoiceField(
|
||||||
queryset=ConsolePort.objects.all(),
|
queryset=ConsolePort.objects.all(),
|
||||||
label='Name',
|
label='Name',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'device_id': '$termination_b_device'
|
'device_id': '$termination_b_device'
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -3435,12 +3433,10 @@ class ConnectCableToConsoleServerPortForm(ConnectCableToDeviceForm):
|
|||||||
termination_b_id = DynamicModelChoiceField(
|
termination_b_id = DynamicModelChoiceField(
|
||||||
queryset=ConsoleServerPort.objects.all(),
|
queryset=ConsoleServerPort.objects.all(),
|
||||||
label='Name',
|
label='Name',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'device_id': '$termination_b_device'
|
'device_id': '$termination_b_device'
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -3448,12 +3444,10 @@ class ConnectCableToPowerPortForm(ConnectCableToDeviceForm):
|
|||||||
termination_b_id = DynamicModelChoiceField(
|
termination_b_id = DynamicModelChoiceField(
|
||||||
queryset=PowerPort.objects.all(),
|
queryset=PowerPort.objects.all(),
|
||||||
label='Name',
|
label='Name',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'device_id': '$termination_b_device'
|
'device_id': '$termination_b_device'
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -3461,12 +3455,10 @@ class ConnectCableToPowerOutletForm(ConnectCableToDeviceForm):
|
|||||||
termination_b_id = DynamicModelChoiceField(
|
termination_b_id = DynamicModelChoiceField(
|
||||||
queryset=PowerOutlet.objects.all(),
|
queryset=PowerOutlet.objects.all(),
|
||||||
label='Name',
|
label='Name',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'device_id': '$termination_b_device'
|
'device_id': '$termination_b_device'
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -3474,13 +3466,11 @@ class ConnectCableToInterfaceForm(ConnectCableToDeviceForm):
|
|||||||
termination_b_id = DynamicModelChoiceField(
|
termination_b_id = DynamicModelChoiceField(
|
||||||
queryset=Interface.objects.all(),
|
queryset=Interface.objects.all(),
|
||||||
label='Name',
|
label='Name',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'device_id': '$termination_b_device',
|
'device_id': '$termination_b_device',
|
||||||
'kind': 'physical',
|
'kind': 'physical',
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -3488,12 +3478,10 @@ class ConnectCableToFrontPortForm(ConnectCableToDeviceForm):
|
|||||||
termination_b_id = DynamicModelChoiceField(
|
termination_b_id = DynamicModelChoiceField(
|
||||||
queryset=FrontPort.objects.all(),
|
queryset=FrontPort.objects.all(),
|
||||||
label='Name',
|
label='Name',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'device_id': '$termination_b_device'
|
'device_id': '$termination_b_device'
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -3501,12 +3489,10 @@ class ConnectCableToRearPortForm(ConnectCableToDeviceForm):
|
|||||||
termination_b_id = DynamicModelChoiceField(
|
termination_b_id = DynamicModelChoiceField(
|
||||||
queryset=RearPort.objects.all(),
|
queryset=RearPort.objects.all(),
|
||||||
label='Name',
|
label='Name',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'device_id': '$termination_b_device'
|
'device_id': '$termination_b_device'
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -3534,12 +3520,10 @@ class ConnectCableToCircuitTerminationForm(BootstrapMixin, forms.ModelForm):
|
|||||||
queryset=CircuitTermination.objects.all(),
|
queryset=CircuitTermination.objects.all(),
|
||||||
label='Side',
|
label='Side',
|
||||||
display_field='term_side',
|
display_field='term_side',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'circuit_id': '$termination_b_circuit'
|
'circuit_id': '$termination_b_circuit'
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -3582,12 +3566,10 @@ class ConnectCableToPowerFeedForm(BootstrapMixin, forms.ModelForm):
|
|||||||
termination_b_id = DynamicModelChoiceField(
|
termination_b_id = DynamicModelChoiceField(
|
||||||
queryset=PowerFeed.objects.all(),
|
queryset=PowerFeed.objects.all(),
|
||||||
label='Name',
|
label='Name',
|
||||||
|
disabled_indicator='cable',
|
||||||
query_params={
|
query_params={
|
||||||
'power_panel_id': '$termination_b_powerpanel'
|
'power_panel_id': '$termination_b_powerpanel'
|
||||||
},
|
}
|
||||||
widget=APISelect(
|
|
||||||
disabled_indicator='cable'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -249,14 +249,18 @@ class DynamicModelChoiceMixin:
|
|||||||
:param display_field: The name of the attribute of an API response object to display in the selection list
|
:param display_field: The name of the attribute of an API response object to display in the selection list
|
||||||
:param query_params: A dictionary of additional key/value pairs to attach to the API request
|
:param query_params: A dictionary of additional key/value pairs to attach to the API request
|
||||||
:param null_option: The string used to represent a null selection (if any)
|
: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)
|
||||||
"""
|
"""
|
||||||
filter = django_filters.ModelChoiceFilter
|
filter = django_filters.ModelChoiceFilter
|
||||||
widget = widgets.APISelect
|
widget = widgets.APISelect
|
||||||
|
|
||||||
def __init__(self, *args, display_field='name', query_params=None, null_option=None, **kwargs):
|
def __init__(self, *args, display_field='name', query_params=None, null_option=None, disabled_indicator=None,
|
||||||
|
**kwargs):
|
||||||
self.display_field = display_field
|
self.display_field = display_field
|
||||||
self.query_params = query_params or {}
|
self.query_params = query_params or {}
|
||||||
self.null_option = null_option
|
self.null_option = null_option
|
||||||
|
self.disabled_indicator = disabled_indicator
|
||||||
|
|
||||||
# to_field_name is set by ModelChoiceField.__init__(), but we need to set it early for reference
|
# to_field_name is set by ModelChoiceField.__init__(), but we need to set it early for reference
|
||||||
# by widget_attrs()
|
# by widget_attrs()
|
||||||
@ -277,6 +281,10 @@ class DynamicModelChoiceMixin:
|
|||||||
if self.null_option is not None:
|
if self.null_option is not None:
|
||||||
attrs['data-null-option'] = self.null_option
|
attrs['data-null-option'] = self.null_option
|
||||||
|
|
||||||
|
# Set the disabled indicator, if any
|
||||||
|
if self.disabled_indicator is not None:
|
||||||
|
attrs['disabled-indicator'] = self.disabled_indicator
|
||||||
|
|
||||||
# Attach any static query parameters
|
# Attach any static query parameters
|
||||||
for key, value in self.query_params.items():
|
for key, value in self.query_params.items():
|
||||||
widget.add_additional_query_param(key, value)
|
widget.add_additional_query_param(key, value)
|
||||||
|
Reference in New Issue
Block a user