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

14467 change ChoiceField separator from comma to colon (#14469)

* 14467 change ChoiceField separator from comma to colon

* 14467 fix test

* 14467 fix test

* 14467 use regex for colon detection

* 14467 update tests
This commit is contained in:
Arthur Hanson
2023-12-12 11:31:39 -08:00
committed by GitHub
parent 81fa4265da
commit 6939ae4a47
3 changed files with 13 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import json
import re
from django import forms
from django.conf import settings
@ -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:
@ -107,7 +108,7 @@ class CustomFieldChoiceSetForm(BootstrapMixin, forms.ModelForm):
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))