Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions netbox/extras/forms/model_forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import re

from django import forms
from django.conf import settings
Expand Down Expand Up @@ -95,8 +96,8 @@ class CustomFieldChoiceSetForm(BootstrapMixin, forms.ModelForm):
required=False,
help_text=mark_safe(_(
'Enter one choice per line. An optional label may be specified for each choice by appending it with a '
'comma. Example:'
) + ' <code>choice1,First Choice</code>')
'colon. Example:'
) + ' <code>choice1:First Choice</code>')
)

class Meta:
Expand All @@ -107,7 +108,7 @@ def clean_extra_choices(self):
data = []
for line in self.cleaned_data['extra_choices'].splitlines():
try:
value, label = line.split(',', maxsplit=1)
value, label = re.split(r'(?<!\\):', line, maxsplit=1)
except ValueError:
value, label = line, line
data.append((value, label))
Expand Down
9 changes: 8 additions & 1 deletion netbox/extras/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def setUpTestData(cls):

cls.form_data = {
'name': 'Choice Set X',
'extra_choices': '\n'.join(['X1,Choice 1', 'X2,Choice 2', 'X3,Choice 3'])
'extra_choices': '\n'.join(['X1:Choice 1', 'X2:Choice 2', 'X3:Choice 3'])
}

cls.csv_data = (
Expand All @@ -119,6 +119,13 @@ def setUpTestData(cls):
'description': 'New description',
}

# This is here as extra_choices field splits on colon, but is returned
# from DB as comma separated.
def assertInstanceEqual(self, instance, data, exclude=None, api=False):
if 'extra_choices' in data:
data['extra_choices'] = data['extra_choices'].replace(':', ',')
return super().assertInstanceEqual(instance, data, exclude, api)


class CustomLinkTestCase(ViewTestCases.PrimaryObjectViewTestCase):
model = CustomLink
Expand Down
2 changes: 1 addition & 1 deletion netbox/utilities/forms/widgets/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ def format_value(self, value):
if not value:
return None
if type(value) is list:
return '\n'.join([f'{k},{v}' for k, v in value])
return '\n'.join([f'{k}:{v}' for k, v in value])
return value