Remove boilerplate error messages from CSV model choice fields

This commit is contained in:
Jeremy Stretch 2020-05-06 09:58:12 -04:00
parent 70d0a5f665
commit 270d61ce1b
7 changed files with 85 additions and 324 deletions

View File

@ -189,18 +189,12 @@ class CircuitCSVForm(CustomFieldModelCSVForm):
provider = CSVModelChoiceField( provider = CSVModelChoiceField(
queryset=Provider.objects.all(), queryset=Provider.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned provider', help_text='Assigned provider'
error_messages={
'invalid_choice': 'Provider not found.'
}
) )
type = CSVModelChoiceField( type = CSVModelChoiceField(
queryset=CircuitType.objects.all(), queryset=CircuitType.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Type of circuit', help_text='Type of circuit'
error_messages={
'invalid_choice': 'Invalid circuit type.'
}
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=CircuitStatusChoices, choices=CircuitStatusChoices,
@ -211,10 +205,7 @@ class CircuitCSVForm(CustomFieldModelCSVForm):
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.'
}
) )
class Meta: class Meta:

View File

@ -198,10 +198,7 @@ class RegionCSVForm(CSVModelForm):
queryset=Region.objects.all(), queryset=Region.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Name of parent region', help_text='Name of parent region'
error_messages={
'invalid_choice': 'Region not found.',
}
) )
class Meta: class Meta:
@ -277,19 +274,13 @@ class SiteCSVForm(CustomFieldModelCSVForm):
queryset=Region.objects.all(), queryset=Region.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned region', help_text='Assigned region'
error_messages={
'invalid_choice': 'Region not found.',
}
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.',
}
) )
class Meta: class Meta:
@ -392,10 +383,7 @@ class RackGroupCSVForm(CSVModelForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned site', help_text='Assigned site'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
parent = CSVModelChoiceField( parent = CSVModelChoiceField(
queryset=RackGroup.objects.all(), queryset=RackGroup.objects.all(),
@ -521,27 +509,18 @@ class RackForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
class RackCSVForm(CustomFieldModelCSVForm): class RackCSVForm(CustomFieldModelCSVForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
group = CSVModelChoiceField( group = CSVModelChoiceField(
queryset=RackGroup.objects.all(), queryset=RackGroup.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Rack group not found.',
}
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Name of assigned tenant', help_text='Name of assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.',
}
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=RackStatusChoices, choices=RackStatusChoices,
@ -552,10 +531,7 @@ class RackCSVForm(CustomFieldModelCSVForm):
queryset=RackRole.objects.all(), queryset=RackRole.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Name of assigned role', help_text='Name of assigned role'
error_messages={
'invalid_choice': 'Role not found.',
}
) )
type = CSVChoiceField( type = CSVChoiceField(
choices=RackTypeChoices, choices=RackTypeChoices,
@ -804,27 +780,18 @@ class RackReservationCSVForm(CSVModelForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Parent site', help_text='Parent site'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
rack_group = CSVModelChoiceField( rack_group = CSVModelChoiceField(
queryset=RackGroup.objects.all(), queryset=RackGroup.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text="Rack's group (if any)", help_text="Rack's group (if any)"
error_messages={
'invalid_choice': 'Rack group not found.',
}
) )
rack = CSVModelChoiceField( rack = CSVModelChoiceField(
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Rack', help_text='Rack'
error_messages={
'invalid_choice': 'Rack not found.',
}
) )
units = SimpleArrayField( units = SimpleArrayField(
base_field=forms.IntegerField(), base_field=forms.IntegerField(),
@ -835,10 +802,7 @@ class RackReservationCSVForm(CSVModelForm):
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.',
}
) )
class Meta: class Meta:
@ -1680,10 +1644,7 @@ class PlatformCSVForm(CSVModelForm):
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Limit platform assignments to this manufacturer', help_text='Limit platform assignments to this manufacturer'
error_messages={
'invalid_choice': 'Manufacturer not found.',
}
) )
class Meta: class Meta:
@ -1893,44 +1854,29 @@ class BaseDeviceCSVForm(CustomFieldModelCSVForm):
device_role = CSVModelChoiceField( device_role = CSVModelChoiceField(
queryset=DeviceRole.objects.all(), queryset=DeviceRole.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned role', help_text='Assigned role'
error_messages={
'invalid_choice': 'Invalid device role.',
}
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.',
}
) )
manufacturer = CSVModelChoiceField( manufacturer = CSVModelChoiceField(
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Device type manufacturer', help_text='Device type manufacturer'
error_messages={
'invalid_choice': 'Manufacturer not found.',
}
) )
device_type = CSVModelChoiceField( device_type = CSVModelChoiceField(
queryset=DeviceType.objects.all(), queryset=DeviceType.objects.all(),
to_field_name='model', to_field_name='model',
help_text='Device type model', help_text='Device type model'
error_messages={
'invalid_choice': 'Device type not found.',
}
) )
platform = CSVModelChoiceField( platform = CSVModelChoiceField(
queryset=Platform.objects.all(), queryset=Platform.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned platform', help_text='Assigned platform'
error_messages={
'invalid_choice': 'Invalid platform.',
}
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=DeviceStatusChoices, choices=DeviceStatusChoices,
@ -1940,10 +1886,7 @@ class BaseDeviceCSVForm(CustomFieldModelCSVForm):
queryset=Cluster.objects.all(), queryset=Cluster.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Virtualization cluster', help_text='Virtualization cluster'
error_messages={
'invalid_choice': 'Invalid cluster name.',
}
) )
class Meta: class Meta:
@ -1964,28 +1907,19 @@ class DeviceCSVForm(BaseDeviceCSVForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned site', help_text='Assigned site'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
rack_group = CSVModelChoiceField( rack_group = CSVModelChoiceField(
queryset=RackGroup.objects.all(), queryset=RackGroup.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text="Rack's group (if any)", help_text="Rack's group (if any)"
error_messages={
'invalid_choice': 'Rack group not found.',
}
) )
rack = CSVModelChoiceField( rack = CSVModelChoiceField(
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text="Assigned rack", help_text="Assigned rack"
error_messages={
'invalid_choice': 'Rack not found.',
}
) )
face = CSVChoiceField( face = CSVChoiceField(
choices=DeviceFaceChoices, choices=DeviceFaceChoices,
@ -2020,18 +1954,12 @@ class ChildDeviceCSVForm(BaseDeviceCSVForm):
parent = CSVModelChoiceField( parent = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Parent device', help_text='Parent device'
error_messages={
'invalid_choice': 'Parent device not found.',
}
) )
device_bay = CSVModelChoiceField( device_bay = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Device bay in which this device is installed', help_text='Device bay in which this device is installed'
error_messages={
'invalid_choice': 'Devie bay not found.',
}
) )
class Meta(BaseDeviceCSVForm.Meta): class Meta(BaseDeviceCSVForm.Meta):
@ -2342,10 +2270,7 @@ class ConsolePortBulkEditForm(
class ConsolePortCSVForm(CSVModelForm): class ConsolePortCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
class Meta: class Meta:
@ -2445,10 +2370,7 @@ class ConsoleServerPortBulkDisconnectForm(ConfirmationForm):
class ConsoleServerPortCSVForm(CSVModelForm): class ConsoleServerPortCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
class Meta: class Meta:
@ -2544,10 +2466,7 @@ class PowerPortBulkEditForm(
class PowerPortCSVForm(CSVModelForm): class PowerPortCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
class Meta: class Meta:
@ -2694,19 +2613,13 @@ class PowerOutletBulkDisconnectForm(ConfirmationForm):
class PowerOutletCSVForm(CSVModelForm): class PowerOutletCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
power_port = CSVModelChoiceField( power_port = CSVModelChoiceField(
queryset=PowerPort.objects.all(), queryset=PowerPort.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Local power port which feeds this outlet', help_text='Local power port which feeds this outlet'
error_messages={
'invalid_choice': 'Power port not found.',
}
) )
feed_leg = CSVChoiceField( feed_leg = CSVChoiceField(
choices=PowerOutletFeedLegChoices, choices=PowerOutletFeedLegChoices,
@ -3017,27 +2930,18 @@ class InterfaceCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
virtual_machine = CSVModelChoiceField( virtual_machine = CSVModelChoiceField(
queryset=VirtualMachine.objects.all(), queryset=VirtualMachine.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Virtual machine not found.',
}
) )
lag = CSVModelChoiceField( lag = CSVModelChoiceField(
queryset=Interface.objects.all(), queryset=Interface.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Parent LAG interface', help_text='Parent LAG interface'
error_messages={
'invalid_choice': 'LAG interface not found.',
}
) )
type = CSVChoiceField( type = CSVChoiceField(
choices=InterfaceTypeChoices, choices=InterfaceTypeChoices,
@ -3229,18 +3133,12 @@ class FrontPortBulkDisconnectForm(ConfirmationForm):
class FrontPortCSVForm(CSVModelForm): class FrontPortCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
rear_port = CSVModelChoiceField( rear_port = CSVModelChoiceField(
queryset=RearPort.objects.all(), queryset=RearPort.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Corresponding rear port', help_text='Corresponding rear port'
error_messages={
'invalid_choice': 'Rear Port not found.',
}
) )
type = CSVChoiceField( type = CSVChoiceField(
choices=PortTypeChoices, choices=PortTypeChoices,
@ -3370,10 +3268,7 @@ class RearPortBulkDisconnectForm(ConfirmationForm):
class RearPortCSVForm(CSVModelForm): class RearPortCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
type = CSVChoiceField( type = CSVChoiceField(
help_text='Physical medium classification', help_text='Physical medium classification',
@ -3481,10 +3376,7 @@ class DeviceBayBulkRenameForm(BulkRenameForm):
class DeviceBayCSVForm(CSVModelForm): class DeviceBayCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
installed_device = CSVModelChoiceField( installed_device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
@ -3774,10 +3666,7 @@ class CableCSVForm(CSVModelForm):
side_a_device = CSVModelChoiceField( side_a_device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Side A device', help_text='Side A device'
error_messages={
'invalid_choice': 'Side A device not found',
}
) )
side_a_type = CSVModelChoiceField( side_a_type = CSVModelChoiceField(
queryset=ContentType.objects.all(), queryset=ContentType.objects.all(),
@ -3793,10 +3682,7 @@ class CableCSVForm(CSVModelForm):
side_b_device = CSVModelChoiceField( side_b_device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Side B device', help_text='Side B device'
error_messages={
'invalid_choice': 'Side B device not found',
}
) )
side_b_type = CSVModelChoiceField( side_b_type = CSVModelChoiceField(
queryset=ContentType.objects.all(), queryset=ContentType.objects.all(),
@ -4126,18 +4012,12 @@ class InventoryItemCreateForm(BootstrapMixin, forms.Form):
class InventoryItemCSVForm(CSVModelForm): class InventoryItemCSVForm(CSVModelForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
manufacturer = CSVModelChoiceField( manufacturer = CSVModelChoiceField(
queryset=Manufacturer.objects.all(), queryset=Manufacturer.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False
error_messages={
'invalid_choice': 'Invalid manufacturer.',
}
) )
class Meta: class Meta:
@ -4438,18 +4318,12 @@ class PowerPanelCSVForm(CSVModelForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Name of parent site', help_text='Name of parent site'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
rack_group = CSVModelChoiceField( rack_group = CSVModelChoiceField(
queryset=RackGroup.objects.all(), queryset=RackGroup.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name'
error_messages={
'invalid_choice': 'Rack group not found.',
}
) )
class Meta: class Meta:
@ -4582,36 +4456,24 @@ class PowerFeedCSVForm(CustomFieldModelCSVForm):
site = CSVModelChoiceField( site = CSVModelChoiceField(
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned site', help_text='Assigned site'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
power_panel = CSVModelChoiceField( power_panel = CSVModelChoiceField(
queryset=PowerPanel.objects.all(), queryset=PowerPanel.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Upstream power panel', help_text='Upstream power panel'
error_messages={
'invalid_choice': 'Power panel not found.',
}
) )
rack_group = CSVModelChoiceField( rack_group = CSVModelChoiceField(
queryset=RackGroup.objects.all(), queryset=RackGroup.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text="Rack's group (if any)", help_text="Rack's group (if any)"
error_messages={
'invalid_choice': 'Rack group not found.',
}
) )
rack = CSVModelChoiceField( rack = CSVModelChoiceField(
queryset=Rack.objects.all(), queryset=Rack.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Rack', help_text='Rack'
error_messages={
'invalid_choice': 'Rack not found.',
}
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=PowerFeedStatusChoices, choices=PowerFeedStatusChoices,

View File

@ -55,10 +55,7 @@ class VRFCSVForm(CustomFieldModelCSVForm):
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.',
}
) )
class Meta: class Meta:
@ -166,10 +163,7 @@ class AggregateCSVForm(CustomFieldModelCSVForm):
rir = CSVModelChoiceField( rir = CSVModelChoiceField(
queryset=RIR.objects.all(), queryset=RIR.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned RIR', help_text='Assigned RIR'
error_messages={
'invalid_choice': 'RIR not found.',
}
) )
class Meta: class Meta:
@ -329,46 +323,31 @@ class PrefixCSVForm(CustomFieldModelCSVForm):
queryset=VRF.objects.all(), queryset=VRF.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Assigned VRF', help_text='Assigned VRF'
error_messages={
'invalid_choice': 'VRF not found.',
}
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.',
}
) )
site = CSVModelChoiceField( site = CSVModelChoiceField(
queryset=Site.objects.all(), queryset=Site.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned site', help_text='Assigned site'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
vlan_group = CSVModelChoiceField( vlan_group = CSVModelChoiceField(
queryset=VLANGroup.objects.all(), queryset=VLANGroup.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text="VLAN's group (if any)", help_text="VLAN's group (if any)"
error_messages={
'invalid_choice': 'VLAN group not found.',
}
) )
vlan = CSVModelChoiceField( vlan = CSVModelChoiceField(
queryset=VLAN.objects.all(), queryset=VLAN.objects.all(),
required=False, required=False,
to_field_name='vid', to_field_name='vid',
help_text="Assigned VLAN", help_text="Assigned VLAN"
error_messages={
'invalid_choice': 'VLAN not found.',
}
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=PrefixStatusChoices, choices=PrefixStatusChoices,
@ -378,10 +357,7 @@ class PrefixCSVForm(CustomFieldModelCSVForm):
queryset=Role.objects.all(), queryset=Role.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Functional role', help_text='Functional role'
error_messages={
'invalid_choice': 'Invalid role.',
}
) )
class Meta: class Meta:
@ -721,19 +697,13 @@ class IPAddressCSVForm(CustomFieldModelCSVForm):
queryset=VRF.objects.all(), queryset=VRF.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Assigned VRF', help_text='Assigned VRF'
error_messages={
'invalid_choice': 'VRF not found.',
}
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.',
}
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=IPAddressStatusChoices, choices=IPAddressStatusChoices,
@ -748,28 +718,19 @@ class IPAddressCSVForm(CustomFieldModelCSVForm):
queryset=Device.objects.all(), queryset=Device.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Parent device of assigned interface (if any)', help_text='Parent device of assigned interface (if any)'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
virtual_machine = CSVModelChoiceField( virtual_machine = CSVModelChoiceField(
queryset=VirtualMachine.objects.all(), queryset=VirtualMachine.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Parent VM of assigned interface (if any)', help_text='Parent VM of assigned interface (if any)'
error_messages={
'invalid_choice': 'Virtual machine not found.',
}
) )
interface = CSVModelChoiceField( interface = CSVModelChoiceField(
queryset=Interface.objects.all(), queryset=Interface.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned interface', help_text='Assigned interface'
error_messages={
'invalid_choice': 'Interface not found.',
}
) )
is_primary = forms.BooleanField( is_primary = forms.BooleanField(
help_text='Make this the primary IP for the assigned device', help_text='Make this the primary IP for the assigned device',
@ -979,10 +940,7 @@ class VLANGroupCSVForm(CSVModelForm):
queryset=Site.objects.all(), queryset=Site.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned site', help_text='Assigned site'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
slug = SlugField() slug = SlugField()
@ -1064,28 +1022,19 @@ class VLANCSVForm(CustomFieldModelCSVForm):
queryset=Site.objects.all(), queryset=Site.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned site', help_text='Assigned site'
error_messages={
'invalid_choice': 'Site not found.',
}
) )
group = CSVModelChoiceField( group = CSVModelChoiceField(
queryset=VLANGroup.objects.all(), queryset=VLANGroup.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned VLAN group', help_text='Assigned VLAN group'
error_messages={
'invalid_choice': 'VLAN group not found.',
}
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.',
}
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=VLANStatusChoices, choices=VLANStatusChoices,
@ -1095,10 +1044,7 @@ class VLANCSVForm(CustomFieldModelCSVForm):
queryset=Role.objects.all(), queryset=Role.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Functional role', help_text='Functional role'
error_messages={
'invalid_choice': 'Invalid role.',
}
) )
class Meta: class Meta:
@ -1275,19 +1221,13 @@ class ServiceCSVForm(CustomFieldModelCSVForm):
queryset=Device.objects.all(), queryset=Device.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Required if not assigned to a VM', help_text='Required if not assigned to a VM'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
virtual_machine = CSVModelChoiceField( virtual_machine = CSVModelChoiceField(
queryset=VirtualMachine.objects.all(), queryset=VirtualMachine.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Required if not assigned to a device', help_text='Required if not assigned to a device'
error_messages={
'invalid_choice': 'Virtual machine not found.',
}
) )
protocol = CSVChoiceField( protocol = CSVChoiceField(
choices=ServiceProtocolChoices, choices=ServiceProtocolChoices,

View File

@ -120,18 +120,12 @@ class SecretCSVForm(CustomFieldModelCSVForm):
device = CSVModelChoiceField( device = CSVModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned device', help_text='Assigned device'
error_messages={
'invalid_choice': 'Device not found.',
}
) )
role = CSVModelChoiceField( role = CSVModelChoiceField(
queryset=SecretRole.objects.all(), queryset=SecretRole.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned role', help_text='Assigned role'
error_messages={
'invalid_choice': 'Invalid secret role.',
}
) )
plaintext = forms.CharField( plaintext = forms.CharField(
help_text='Plaintext secret data' help_text='Plaintext secret data'

View File

@ -37,10 +37,7 @@ class TenantGroupCSVForm(CSVModelForm):
queryset=TenantGroup.objects.all(), queryset=TenantGroup.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Parent group', help_text='Parent group'
error_messages={
'invalid_choice': 'Tenant group not found.',
}
) )
slug = SlugField() slug = SlugField()
@ -77,10 +74,7 @@ class TenantCSVForm(CustomFieldModelCSVForm):
queryset=TenantGroup.objects.all(), queryset=TenantGroup.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned group', help_text='Assigned group'
error_messages={
'invalid_choice': 'Group not found.'
}
) )
class Meta: class Meta:

View File

@ -500,6 +500,10 @@ class CSVModelChoiceField(forms.ModelChoiceField):
""" """
Provides additional validation for model choices entered as CSV data. Provides additional validation for model choices entered as CSV data.
""" """
default_error_messages = {
'invalid_choice': 'Object not found.',
}
def to_python(self, value): def to_python(self, value):
try: try:
return super().to_python(value) return super().to_python(value)

View File

@ -98,37 +98,25 @@ class ClusterCSVForm(CustomFieldModelCSVForm):
type = CSVModelChoiceField( type = CSVModelChoiceField(
queryset=ClusterType.objects.all(), queryset=ClusterType.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Type of cluster', help_text='Type of cluster'
error_messages={
'invalid_choice': 'Invalid cluster type name.',
}
) )
group = CSVModelChoiceField( group = CSVModelChoiceField(
queryset=ClusterGroup.objects.all(), queryset=ClusterGroup.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Assigned cluster group', help_text='Assigned cluster group'
error_messages={
'invalid_choice': 'Invalid cluster group name.',
}
) )
site = CSVModelChoiceField( site = CSVModelChoiceField(
queryset=Site.objects.all(), queryset=Site.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Assigned site', help_text='Assigned site'
error_messages={
'invalid_choice': 'Invalid site name.',
}
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
to_field_name='name', to_field_name='name',
required=False, required=False,
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Invalid tenant name'
}
) )
class Meta: class Meta:
@ -404,10 +392,7 @@ class VirtualMachineCSVForm(CustomFieldModelCSVForm):
cluster = CSVModelChoiceField( cluster = CSVModelChoiceField(
queryset=Cluster.objects.all(), queryset=Cluster.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Assigned cluster', help_text='Assigned cluster'
error_messages={
'invalid_choice': 'Invalid cluster name.',
}
) )
role = CSVModelChoiceField( role = CSVModelChoiceField(
queryset=DeviceRole.objects.filter( queryset=DeviceRole.objects.filter(
@ -415,28 +400,19 @@ class VirtualMachineCSVForm(CustomFieldModelCSVForm):
), ),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Functional role', help_text='Functional role'
error_messages={
'invalid_choice': 'Invalid role name.'
}
) )
tenant = CSVModelChoiceField( tenant = CSVModelChoiceField(
queryset=Tenant.objects.all(), queryset=Tenant.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned tenant', help_text='Assigned tenant'
error_messages={
'invalid_choice': 'Tenant not found.'
}
) )
platform = CSVModelChoiceField( platform = CSVModelChoiceField(
queryset=Platform.objects.all(), queryset=Platform.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Assigned platform', help_text='Assigned platform'
error_messages={
'invalid_choice': 'Invalid platform.',
}
) )
class Meta: class Meta: