1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

7376 csv tags (#10802)

* 7376 add tags to CSV import

* 7376 change help text

* 7376 validate tags

* 7376 fix tests

* 7376 add tag validation tests

* Introduce CSVModelMultipleChoiceField for CSV import tag assignment

* Clean up CSVImportTestCase

Co-authored-by: jeremystretch <jstretch@ns1.com>
This commit is contained in:
Arthur Hanson
2022-11-04 07:50:43 -07:00
committed by GitHub
parent bc6b5bc4be
commit cdeb65e2fb
9 changed files with 165 additions and 61 deletions

View File

@@ -16,6 +16,7 @@ __all__ = (
'CSVDataField',
'CSVFileField',
'CSVModelChoiceField',
'CSVModelMultipleChoiceField',
'CSVMultipleChoiceField',
'CSVMultipleContentTypeField',
'CSVTypedChoiceField',
@@ -142,7 +143,7 @@ class CSVModelChoiceField(forms.ModelChoiceField):
Extends Django's `ModelChoiceField` to provide additional validation for CSV values.
"""
default_error_messages = {
'invalid_choice': 'Object not found.',
'invalid_choice': 'Object not found: %(value)s',
}
def to_python(self, value):
@@ -154,6 +155,19 @@ class CSVModelChoiceField(forms.ModelChoiceField):
)
class CSVModelMultipleChoiceField(forms.ModelMultipleChoiceField):
"""
Extends Django's `ModelMultipleChoiceField` to support comma-separated values.
"""
default_error_messages = {
'invalid_choice': 'Object not found: %(value)s',
}
def clean(self, value):
value = value.split(',') if value else []
return super().clean(value)
class CSVContentTypeField(CSVModelChoiceField):
"""
CSV field for referencing a single content type, in the form `<app>.<model>`.