From 6939ae4a47192d3d6e87061cc741a9b51f7ea215 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Tue, 12 Dec 2023 11:31:39 -0800 Subject: [PATCH] 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 --- netbox/extras/forms/model_forms.py | 7 ++++--- netbox/extras/tests/test_views.py | 9 ++++++++- netbox/utilities/forms/widgets/misc.py | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/netbox/extras/forms/model_forms.py b/netbox/extras/forms/model_forms.py index 83a346420..4e4a6e0de 100644 --- a/netbox/extras/forms/model_forms.py +++ b/netbox/extras/forms/model_forms.py @@ -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:' - ) + ' choice1,First Choice') + 'colon. Example:' + ) + ' choice1:First Choice') ) 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'(?