mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-28 19:36:26 -06:00
Make width & u_height optional when setting rack_type on import
This commit is contained in:
parent
538199a8b3
commit
6034b3df7b
@ -272,8 +272,13 @@ class RackImportForm(NetBoxModelImportForm):
|
|||||||
width = forms.ChoiceField(
|
width = forms.ChoiceField(
|
||||||
label=_('Width'),
|
label=_('Width'),
|
||||||
choices=RackWidthChoices,
|
choices=RackWidthChoices,
|
||||||
|
required=False,
|
||||||
help_text=_('Rail-to-rail width (in inches)')
|
help_text=_('Rail-to-rail width (in inches)')
|
||||||
)
|
)
|
||||||
|
u_height = forms.IntegerField(
|
||||||
|
required=False,
|
||||||
|
label=_('Height (U)')
|
||||||
|
)
|
||||||
outer_unit = CSVChoiceField(
|
outer_unit = CSVChoiceField(
|
||||||
label=_('Outer unit'),
|
label=_('Outer unit'),
|
||||||
choices=RackDimensionUnitChoices,
|
choices=RackDimensionUnitChoices,
|
||||||
@ -297,8 +302,8 @@ class RackImportForm(NetBoxModelImportForm):
|
|||||||
model = Rack
|
model = Rack
|
||||||
fields = (
|
fields = (
|
||||||
'site', 'location', 'name', 'facility_id', 'tenant', 'status', 'role', 'rack_type', 'form_factor', 'serial',
|
'site', 'location', 'name', 'facility_id', 'tenant', 'status', 'role', 'rack_type', 'form_factor', 'serial',
|
||||||
'asset_tag', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit', 'mounting_depth',
|
'asset_tag', 'width', 'u_height', 'desc_units', 'outer_width', 'outer_depth', 'outer_unit',
|
||||||
'airflow', 'weight', 'max_weight', 'weight_unit', 'description', 'comments', 'tags',
|
'mounting_depth', 'airflow', 'weight', 'max_weight', 'weight_unit', 'description', 'comments', 'tags',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, data=None, *args, **kwargs):
|
def __init__(self, data=None, *args, **kwargs):
|
||||||
@ -310,6 +315,16 @@ class RackImportForm(NetBoxModelImportForm):
|
|||||||
params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
|
params = {f"site__{self.fields['site'].to_field_name}": data.get('site')}
|
||||||
self.fields['location'].queryset = self.fields['location'].queryset.filter(**params)
|
self.fields['location'].queryset = self.fields['location'].queryset.filter(**params)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
# width & u_height must be set if not specifying a rack type on import
|
||||||
|
if not self.instance.pk:
|
||||||
|
if not self.cleaned_data.get('rack_type') and not self.cleaned_data.get('width'):
|
||||||
|
raise forms.ValidationError(_("Width must be set if not specifying a rack type."))
|
||||||
|
if not self.cleaned_data.get('rack_type') and not self.cleaned_data.get('u_height'):
|
||||||
|
raise forms.ValidationError(_("U height must be set if not specifying a rack type."))
|
||||||
|
|
||||||
|
|
||||||
class RackReservationImportForm(NetBoxModelImportForm):
|
class RackReservationImportForm(NetBoxModelImportForm):
|
||||||
site = CSVModelChoiceField(
|
site = CSVModelChoiceField(
|
||||||
|
Loading…
Reference in New Issue
Block a user