mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 19:19:22 -06:00
Fix CSV import forms
This commit is contained in:
parent
f1d1e8b537
commit
cd655d289b
@ -3296,15 +3296,31 @@ class PowerPanelCSVForm(forms.ModelForm):
|
|||||||
'invalid_choice': 'Site not found.',
|
'invalid_choice': 'Site not found.',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
rackgroup_name = forms.CharField(
|
rack_group_name = forms.CharField(
|
||||||
help_text='Name of rack group',
|
required=False,
|
||||||
required=False
|
help_text="Rack group name (optional)"
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PowerPanel
|
model = PowerPanel
|
||||||
fields = PowerPanel.csv_headers
|
fields = PowerPanel.csv_headers
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
site = self.cleaned_data.get('site')
|
||||||
|
rack_group_name = self.cleaned_data.get('rack_group_name')
|
||||||
|
|
||||||
|
# Validate rack group
|
||||||
|
if rack_group_name:
|
||||||
|
try:
|
||||||
|
self.instance.rack_group = RackGroup.objects.get(site=site, name=rack_group_name)
|
||||||
|
except RackGroup.DoesNotExist:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
"Rack group {} not found in site {}".format(rack_group_name, site)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PowerPanelFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
class PowerPanelFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
||||||
model = PowerPanel
|
model = PowerPanel
|
||||||
@ -3375,6 +3391,30 @@ class PowerFeedForm(BootstrapMixin, CustomFieldForm):
|
|||||||
|
|
||||||
|
|
||||||
class PowerFeedCSVForm(forms.ModelForm):
|
class PowerFeedCSVForm(forms.ModelForm):
|
||||||
|
site = forms.ModelChoiceField(
|
||||||
|
queryset=Site.objects.all(),
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Name of parent site',
|
||||||
|
error_messages={
|
||||||
|
'invalid_choice': 'Site not found.',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
panel_name = forms.ModelChoiceField(
|
||||||
|
queryset=PowerPanel.objects.all(),
|
||||||
|
to_field_name='name',
|
||||||
|
help_text='Name of upstream power panel',
|
||||||
|
error_messages={
|
||||||
|
'invalid_choice': 'Power panel not found.',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
rack_group = forms.CharField(
|
||||||
|
required=False,
|
||||||
|
help_text="Rack group name (optional)"
|
||||||
|
)
|
||||||
|
rack_name = forms.CharField(
|
||||||
|
required=False,
|
||||||
|
help_text="Rack name (optional)"
|
||||||
|
)
|
||||||
status = CSVChoiceField(
|
status = CSVChoiceField(
|
||||||
choices=POWERFEED_STATUS_CHOICES,
|
choices=POWERFEED_STATUS_CHOICES,
|
||||||
required=False,
|
required=False,
|
||||||
@ -3390,11 +3430,43 @@ class PowerFeedCSVForm(forms.ModelForm):
|
|||||||
required=False,
|
required=False,
|
||||||
help_text='AC/DC'
|
help_text='AC/DC'
|
||||||
)
|
)
|
||||||
|
phase = CSVChoiceField(
|
||||||
|
choices=POWERFEED_PHASE_CHOICES,
|
||||||
|
required=False,
|
||||||
|
help_text='Single or three-phase'
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PowerFeed
|
model = PowerFeed
|
||||||
fields = PowerFeed.csv_headers
|
fields = PowerFeed.csv_headers
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
|
||||||
|
super().clean()
|
||||||
|
|
||||||
|
site = self.cleaned_data.get('site')
|
||||||
|
panel_name = self.cleaned_data.get('panel_name')
|
||||||
|
rack_group = self.cleaned_data.get('rack_group')
|
||||||
|
rack_name = self.cleaned_data.get('rack_name')
|
||||||
|
|
||||||
|
# Validate power panel
|
||||||
|
if panel_name:
|
||||||
|
try:
|
||||||
|
self.instance.power_panel = PowerPanel.objects.get(site=site, name=panel_name)
|
||||||
|
except Rack.DoesNotExist:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
"Power panel {} not found in site {}".format(panel_name, site)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Validate rack
|
||||||
|
if rack_name:
|
||||||
|
try:
|
||||||
|
self.instance.rack = Rack.objects.get(site=site, rack_group=rack_group, name=rack_name)
|
||||||
|
except Rack.DoesNotExist:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
"Rack {} not found in site {}, group {}".format(rack_name, site, rack_group)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PowerFeedBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
class PowerFeedBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm):
|
||||||
pk = forms.ModelMultipleChoiceField(
|
pk = forms.ModelMultipleChoiceField(
|
||||||
|
@ -2729,7 +2729,7 @@ class PowerPanel(ChangeLoggedModel):
|
|||||||
max_length=50
|
max_length=50
|
||||||
)
|
)
|
||||||
|
|
||||||
csv_headers = ['site', 'rack_group', 'name']
|
csv_headers = ['site', 'rack_group_name', 'name']
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['site', 'name']
|
ordering = ['site', 'name']
|
||||||
@ -2819,8 +2819,8 @@ class PowerFeed(ChangeLoggedModel, CableTermination, CustomFieldModel):
|
|||||||
tags = TaggableManager(through=TaggedItem)
|
tags = TaggableManager(through=TaggedItem)
|
||||||
|
|
||||||
csv_headers = [
|
csv_headers = [
|
||||||
'power_panel', 'rack', 'name', 'status', 'type', 'supply', 'phase', 'voltage', 'amperage', 'max_utilization',
|
'site', 'panel_name', 'rack_group', 'rack_name', 'name', 'status', 'type', 'supply', 'phase', 'voltage',
|
||||||
'comments',
|
'amperage', 'max_utilization', 'comments',
|
||||||
]
|
]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
Loading…
Reference in New Issue
Block a user