mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-11 10:59:36 -06:00
Closes #20068: Enable defining profile attributes when importing module types
This commit is contained in:
parent
922b08c0ff
commit
ebf8f7fa1b
@ -472,14 +472,30 @@ class ModuleTypeImportForm(NetBoxModelImportForm):
|
|||||||
required=False,
|
required=False,
|
||||||
help_text=_('Unit for module weight')
|
help_text=_('Unit for module weight')
|
||||||
)
|
)
|
||||||
|
attribute_data = forms.JSONField(
|
||||||
|
label=_('Attributes'),
|
||||||
|
required=False,
|
||||||
|
help_text=_('Attribute values for the assigned profile, passed as a dictionary')
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ModuleType
|
model = ModuleType
|
||||||
fields = [
|
fields = [
|
||||||
'manufacturer', 'model', 'part_number', 'description', 'airflow', 'weight', 'weight_unit', 'profile',
|
'manufacturer', 'model', 'part_number', 'description', 'airflow', 'weight', 'weight_unit', 'profile',
|
||||||
'comments', 'tags'
|
'attribute_data', 'comments', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
# Attribute data may be included only if a profile is specified
|
||||||
|
if self.cleaned_data.get('attribute_data') and not self.cleaned_data.get('profile'):
|
||||||
|
raise forms.ValidationError(_("Profile must be specified if attribute data is provided."))
|
||||||
|
|
||||||
|
# Default attribute_data to an empty dictionary if a profile is specified (to enforce schema validation)
|
||||||
|
if self.cleaned_data.get('profile') and not self.cleaned_data.get('attribute_data'):
|
||||||
|
self.cleaned_data['attribute_data'] = {}
|
||||||
|
|
||||||
|
|
||||||
class DeviceRoleImportForm(NetBoxModelImportForm):
|
class DeviceRoleImportForm(NetBoxModelImportForm):
|
||||||
parent = CSVModelChoiceField(
|
parent = CSVModelChoiceField(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user