mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Converted ConnectionStatusCSVField to a ChoiceField
This commit is contained in:
parent
d122f9f700
commit
3924063060
@ -50,25 +50,29 @@ def get_device_by_name_or_pk(name):
|
|||||||
return device
|
return device
|
||||||
|
|
||||||
|
|
||||||
class ConnectionStatusCSVField(forms.CharField):
|
class ConnectionStatusCSVField(forms.ChoiceField):
|
||||||
"""
|
"""
|
||||||
This field accepts either "planned" or "connected" as a connection status for CSV imports.
|
This field accepts either "planned" or "connected" as a connection status for CSV imports.
|
||||||
"""
|
"""
|
||||||
|
default_error_messages = {
|
||||||
|
'invalid_choice': '%(value)s is not a valid connection status. It must be either "planned" or "connected."',
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
kwargs['choices'] = (
|
||||||
|
('planned', 'planned'),
|
||||||
|
('connected', 'connected'),
|
||||||
|
)
|
||||||
super(ConnectionStatusCSVField, self).__init__(*args, **kwargs)
|
super(ConnectionStatusCSVField, self).__init__(*args, **kwargs)
|
||||||
if not self.help_text:
|
if not self.help_text:
|
||||||
self.help_text = 'Connection status ("planned" or "connected")'
|
self.help_text = 'Connection status'
|
||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
value = super(ConnectionStatusCSVField, self).clean(value)
|
value = super(ConnectionStatusCSVField, self).clean(value)
|
||||||
try:
|
return {
|
||||||
return {
|
'planned': CONNECTION_STATUS_PLANNED,
|
||||||
'planned': CONNECTION_STATUS_PLANNED,
|
'connected': CONNECTION_STATUS_CONNECTED,
|
||||||
'connected': CONNECTION_STATUS_CONNECTED,
|
}[value.lower()]
|
||||||
}[value.lower()]
|
|
||||||
except KeyError:
|
|
||||||
raise ValidationError(
|
|
||||||
'Invalid connection status ({}); must be either "planned" or "connected".'.format(value))
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceComponentForm(BootstrapMixin, forms.Form):
|
class DeviceComponentForm(BootstrapMixin, forms.Form):
|
||||||
|
Loading…
Reference in New Issue
Block a user