Skip to content

Commit a6b058c

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 7f7b5b2 + 18bc760 commit a6b058c

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

tests/fields/test_fields.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ def test_dropdown_field(self):
108108
cls = wsf_fields.DropdownField()
109109
field = cls.get_formfield(data)
110110

111+
block_value = {
112+
"label": "dropdown",
113+
"help_text": "",
114+
"required": False,
115+
"empty_label": "",
116+
"choices": ["choice 1", "choice 2", "choice 3"],
117+
}
118+
options = wsf_fields.DropdownField().get_options(block_value=block_value)
119+
assert options == {
120+
"label": "dropdown",
121+
"help_text": "",
122+
"required": False,
123+
"initial": None,
124+
"choices": [
125+
("choice 1", "choice 1"),
126+
("choice 2", "choice 2"),
127+
("choice 3", "choice 3"),
128+
],
129+
}
130+
111131
self.assertIsInstance(field, forms.ChoiceField)
112132
self.assertIsInstance(field.widget, forms.widgets.Select)
113133
self.assertEqual(field.label, data["label"])

tests/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from django.urls import include, re_path
21
from django.contrib import admin
2+
from django.urls import include, re_path
33
from wagtail.admin import urls as wagtailadmin_urls
44
from wagtail.core import urls as wagtail_urls
55

tests/views/test_submission_list.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
23
from django.conf import settings
34
from django.contrib.auth.models import Permission, User
45
from django.urls import reverse

wagtailstreamforms/wagtail_hooks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from django.urls import include
21
from django.contrib import messages
32
from django.contrib.admin.utils import quote
43
from django.contrib.auth.decorators import login_required
54
from django.shortcuts import redirect
65
from django.template.response import TemplateResponse
7-
from django.urls import path, reverse
6+
from django.urls import include, path, reverse
87
from django.utils.decorators import method_decorator
98
from django.utils.translation import gettext_lazy as _
109
from wagtail.admin import messages as wagtail_messages

wagtailstreamforms/wagtailstreamforms_fields.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List, Tuple
2+
13
from django import forms
24
from django.utils.translation import gettext_lazy as _
35
from wagtail.core import blocks
@@ -53,7 +55,13 @@ class DropdownField(BaseField):
5355

5456
def get_options(self, block_value):
5557
options = super().get_options(block_value)
56-
choices = [(c.strip(), c.strip()) for c in block_value.get("choices")]
58+
choices: List[Tuple[str, str]] = []
59+
for c in block_value.get("choices"):
60+
if isinstance(c, dict) and c.get("value"):
61+
choices.append((c["value"].strip(), c["value"].strip()))
62+
else:
63+
choices.append((c.strip(), c.strip()))
64+
5765
if block_value.get("empty_label"):
5866
choices.insert(0, ("", block_value.get("empty_label")))
5967
options.update({"choices": choices})
@@ -80,7 +88,12 @@ class MultiSelectField(BaseField):
8088

8189
def get_options(self, block_value):
8290
options = super().get_options(block_value)
83-
choices = [(c.strip(), c.strip()) for c in block_value.get("choices")]
91+
choices: List[Tuple[str, str]] = []
92+
for c in block_value.get("choices"):
93+
if isinstance(c, dict) and c.get("value"):
94+
choices.append((c["value"].strip(), c["value"].strip()))
95+
else:
96+
choices.append((c.strip(), c.strip()))
8497
options.update({"choices": choices})
8598
return options
8699

@@ -105,7 +118,12 @@ class RadioField(BaseField):
105118

106119
def get_options(self, block_value):
107120
options = super().get_options(block_value)
108-
choices = [(c.strip(), c.strip()) for c in block_value.get("choices")]
121+
choices: List[Tuple[str, str]] = []
122+
for c in block_value.get("choices"):
123+
if isinstance(c, dict) and c.get("value"):
124+
choices.append((c["value"].strip(), c["value"].strip()))
125+
else:
126+
choices.append((c.strip(), c.strip()))
109127
options.update({"choices": choices})
110128
return options
111129

@@ -130,7 +148,12 @@ class CheckboxesField(BaseField):
130148

131149
def get_options(self, block_value):
132150
options = super().get_options(block_value)
133-
choices = [(c.strip(), c.strip()) for c in block_value.get("choices")]
151+
choices: List[Tuple[str, str]] = []
152+
for c in block_value.get("choices"):
153+
if isinstance(c, dict) and c.get("value"):
154+
choices.append((c["value"].strip(), c["value"].strip()))
155+
else:
156+
choices.append((c.strip(), c.strip()))
134157
options.update({"choices": choices})
135158
return options
136159

0 commit comments

Comments
 (0)