Rename option_attrs to context

This commit is contained in:
Jeremy Stretch 2024-02-13 13:16:36 -05:00
parent 80b49aa6b2
commit aec66f77f7
6 changed files with 20 additions and 20 deletions

View File

@ -557,7 +557,7 @@ class DeviceBulkEditForm(NetBoxModelBulkEditForm):
label=_('Device type'),
queryset=DeviceType.objects.all(),
required=False,
option_attrs={
context={
'parent': 'manufacturer',
},
query_params={
@ -644,7 +644,7 @@ class ModuleBulkEditForm(NetBoxModelBulkEditForm):
query_params={
'manufacturer_id': '$manufacturer'
},
option_attrs={
context={
'parent': 'manufacturer',
}
)

View File

@ -30,7 +30,7 @@ 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(),
option_attrs={
context={
'disabled': '_occupied',
},
query_params={
@ -54,7 +54,7 @@ def get_cable_form(a_type, b_type):
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
queryset=term_cls.objects.all(),
label=_('Power Feed'),
option_attrs={
context={
'disabled': '_occupied',
},
query_params={
@ -76,7 +76,7 @@ def get_cable_form(a_type, b_type):
attrs[f'{cable_end}_terminations'] = DynamicModelMultipleChoiceField(
queryset=term_cls.objects.all(),
label=_('Side'),
option_attrs={
context={
'disabled': '_occupied',
},
query_params={

View File

@ -434,7 +434,7 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all(),
option_attrs={
context={
'parent': 'manufacturer',
},
selector=True
@ -464,7 +464,7 @@ class DeviceForm(TenancyForm, NetBoxModelForm):
label=_('Virtual chassis'),
queryset=VirtualChassis.objects.all(),
required=False,
option_attrs={
context={
'parent': 'master',
},
selector=True
@ -574,7 +574,7 @@ class ModuleForm(ModuleCommonForm, NetBoxModelForm):
module_type = DynamicModelChoiceField(
label=_('Module type'),
queryset=ModuleType.objects.all(),
option_attrs={
context={
'parent': 'manufacturer',
},
selector=True
@ -784,7 +784,7 @@ class ComponentTemplateForm(forms.ModelForm):
device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all(),
option_attrs={
context={
'parent': 'manufacturer',
}
)
@ -802,7 +802,7 @@ class ModularComponentTemplateForm(ComponentTemplateForm):
label=_('Device type'),
queryset=DeviceType.objects.all().all(),
required=False,
option_attrs={
context={
'parent': 'manufacturer',
}
)
@ -810,7 +810,7 @@ class ModularComponentTemplateForm(ComponentTemplateForm):
label=_('Module type'),
queryset=ModuleType.objects.all(),
required=False,
option_attrs={
context={
'parent': 'manufacturer',
}
)

View File

@ -269,7 +269,7 @@ class IPAddressForm(TenancyForm, NetBoxModelForm):
interface = DynamicModelChoiceField(
queryset=Interface.objects.all(),
required=False,
option_attrs={
context={
'parent': 'device',
},
selector=True,
@ -278,7 +278,7 @@ class IPAddressForm(TenancyForm, NetBoxModelForm):
vminterface = DynamicModelChoiceField(
queryset=VMInterface.objects.all(),
required=False,
option_attrs={
context={
'parent': 'virtual_machine',
},
selector=True,

View File

@ -63,8 +63,8 @@ class DynamicModelChoiceMixin:
initial_params: A dictionary of child field references to use for selecting a parent field's initial value
null_option: The string used to represent a null selection (if any)
disabled_indicator: The name of the field which, if populated, will disable selection of the
choice (DEPRECATED: pass `option_attrs={'disabled': '$fieldname'}` instead)
option_attrs: A mapping of <option> template variables to their API data keys (optional)
choice (DEPRECATED: pass `context={'disabled': '$fieldname'}` instead)
context: A mapping of <option> template variables to their API data keys (optional)
selector: Include an advanced object selection widget to assist the user in identifying the desired object
"""
filter = django_filters.ModelChoiceFilter
@ -78,7 +78,7 @@ class DynamicModelChoiceMixin:
initial_params=None,
null_option=None,
disabled_indicator=None,
option_attrs=None,
context=None,
selector=False,
**kwargs
):
@ -87,7 +87,7 @@ class DynamicModelChoiceMixin:
self.initial_params = initial_params or {}
self.null_option = null_option
self.disabled_indicator = disabled_indicator
self.option_attrs = option_attrs or {}
self.context = context or {}
self.selector = selector
super().__init__(queryset, **kwargs)
@ -100,7 +100,7 @@ class DynamicModelChoiceMixin:
attrs['data-null-option'] = self.null_option
# Set any custom template attributes for TomSelect
for var, accessor in self.option_attrs.items():
for var, accessor in self.context.items():
attrs[f'ts-{var}-field'] = accessor
# TODO: Remove in v4.1

View File

@ -108,7 +108,7 @@ class WirelessLinkForm(TenancyForm, NetBoxModelForm):
'kind': 'wireless',
'device_id': '$device_a',
},
option_attrs={
context={
'disabled': '_occupied',
},
label=_('Interface')
@ -150,7 +150,7 @@ class WirelessLinkForm(TenancyForm, NetBoxModelForm):
'kind': 'wireless',
'device_id': '$device_b',
},
option_attrs={
context={
'disabled': '_occupied',
},
label=_('Interface')