mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merge branch 'develop' into feature
This commit is contained in:
@@ -31,6 +31,7 @@ __all__ = (
|
||||
'CSVDataField',
|
||||
'CSVFileField',
|
||||
'CSVModelChoiceField',
|
||||
'CSVMultipleChoiceField',
|
||||
'CSVMultipleContentTypeField',
|
||||
'CSVTypedChoiceField',
|
||||
'DynamicModelChoiceField',
|
||||
@@ -168,11 +169,11 @@ class ContentTypeChoiceMixin:
|
||||
|
||||
|
||||
class ContentTypeChoiceField(ContentTypeChoiceMixin, forms.ModelChoiceField):
|
||||
pass
|
||||
widget = widgets.StaticSelect
|
||||
|
||||
|
||||
class ContentTypeMultipleChoiceField(ContentTypeChoiceMixin, forms.ModelMultipleChoiceField):
|
||||
pass
|
||||
widget = widgets.StaticSelectMultiple
|
||||
|
||||
|
||||
#
|
||||
@@ -263,10 +264,7 @@ class CSVFileField(forms.FileField):
|
||||
return value
|
||||
|
||||
|
||||
class CSVChoiceField(forms.ChoiceField):
|
||||
"""
|
||||
Invert the provided set of choices to take the human-friendly label as input, and return the database value.
|
||||
"""
|
||||
class CSVChoicesMixin:
|
||||
STATIC_CHOICES = True
|
||||
|
||||
def __init__(self, *, choices=(), **kwargs):
|
||||
@@ -274,6 +272,25 @@ class CSVChoiceField(forms.ChoiceField):
|
||||
self.choices = unpack_grouped_choices(choices)
|
||||
|
||||
|
||||
class CSVChoiceField(CSVChoicesMixin, forms.ChoiceField):
|
||||
"""
|
||||
A CSV field which accepts a single selection value.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class CSVMultipleChoiceField(CSVChoicesMixin, forms.MultipleChoiceField):
|
||||
"""
|
||||
A CSV field which accepts multiple selection values.
|
||||
"""
|
||||
def to_python(self, value):
|
||||
if not value:
|
||||
return []
|
||||
if not isinstance(value, str):
|
||||
raise forms.ValidationError(f"Invalid value for a multiple choice field: {value}")
|
||||
return value.split(',')
|
||||
|
||||
|
||||
class CSVTypedChoiceField(forms.TypedChoiceField):
|
||||
STATIC_CHOICES = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user