1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #13283: Add context to dropdown options (#15104)

* Initial work on #13283

* Enable passing TomSelect HTML template attibutes on DynamicModelChoiceField

* Merge disabled_indicator into option_attrs

* Add support for annotating a numeric count on dropdown options

* Annotate parent object on relevant fields

* Improve rendering of color options

* Improve rendering of color options

* Rename option_attrs to context

* Expose option context on ObjectVar for custom scripts

* Document dropdown context variables
This commit is contained in:
Jeremy Stretch
2024-02-13 16:31:17 -05:00
committed by GitHub
parent f41105d5e3
commit 20824ceb25
13 changed files with 176 additions and 34 deletions

View File

@@ -557,6 +557,9 @@ class DeviceBulkEditForm(NetBoxModelBulkEditForm):
label=_('Device type'),
queryset=DeviceType.objects.all(),
required=False,
context={
'parent': 'manufacturer',
},
query_params={
'manufacturer_id': '$manufacturer'
}
@@ -640,6 +643,9 @@ class ModuleBulkEditForm(NetBoxModelBulkEditForm):
required=False,
query_params={
'manufacturer_id': '$manufacturer'
},
context={
'parent': 'manufacturer',
}
)
status = forms.ChoiceField(

View File

@@ -30,7 +30,9 @@ def get_cable_form(a_type, b_type):
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
queryset=term_cls.objects.all(),
label=term_cls._meta.verbose_name.title(),
disabled_indicator='_occupied',
context={
'disabled': '_occupied',
},
query_params={
'device_id': f'$termination_{cable_end}_device',
'kind': 'physical', # Exclude virtual interfaces
@@ -52,7 +54,9 @@ def get_cable_form(a_type, b_type):
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
queryset=term_cls.objects.all(),
label=_('Power Feed'),
disabled_indicator='_occupied',
context={
'disabled': '_occupied',
},
query_params={
'power_panel_id': f'$termination_{cable_end}_powerpanel',
}
@@ -72,7 +76,9 @@ def get_cable_form(a_type, b_type):
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
queryset=term_cls.objects.all(),
label=_('Side'),
disabled_indicator='_occupied',
context={
'disabled': '_occupied',
},
query_params={
'circuit_id': f'$termination_{cable_end}_circuit',
}

View File

@@ -426,7 +426,7 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
widget=APISelect(
api_url='/api/dcim/racks/{{rack}}/elevation/',
attrs={
'disabled-indicator': 'device',
'ts-disabled-field': 'device',
'data-dynamic-params': '[{"fieldName":"face","queryParam":"face"}]'
},
)
@@ -434,6 +434,9 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all(),
context={
'parent': 'manufacturer',
},
selector=True
)
role = DynamicModelChoiceField(
@@ -461,6 +464,9 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
label=_('Virtual chassis'),
queryset=VirtualChassis.objects.all(),
required=False,
context={
'parent': 'master',
},
selector=True
)
vc_position = forms.IntegerField(
@@ -568,6 +574,9 @@ class ModuleForm(ModuleCommonForm, NetBoxModelForm):
module_type = DynamicModelChoiceField(
label=_('Module type'),
queryset=ModuleType.objects.all(),
context={
'parent': 'manufacturer',
},
selector=True
)
comments = CommentField()
@@ -774,7 +783,10 @@ class VCMemberSelectForm(forms.Form):
class ComponentTemplateForm(forms.ModelForm):
device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all()
queryset=DeviceType.objects.all(),
context={
'parent': 'manufacturer',
}
)
def __init__(self, *args, **kwargs):
@@ -789,12 +801,18 @@ class ModularComponentTemplateForm(ComponentTemplateForm):
device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all().all(),
required=False
required=False,
context={
'parent': 'manufacturer',
}
)
module_type = DynamicModelChoiceField(
label=_('Module type'),
queryset=ModuleType.objects.all(),
required=False
required=False,
context={
'parent': 'manufacturer',
}
)
def __init__(self, *args, **kwargs):