Skip to content

Commit 8b7f82b

Browse files
committed
fix handling of form data
1 parent 95304b7 commit 8b7f82b

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

backend/src/collective/volto/formsupport/interfaces.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class FormSubmissionContext:
5555
context: DexterityContent
5656
block: dict
5757
form_data: dict
58+
attachments: dict
5859
request: BaseRequest
5960

6061

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
def filter_parameters(data, block):
22
"""
3-
do not send attachments fields.
3+
TODO do not send attachments fields.
44
"""
5-
# TODO: handle attachments for schemaForm block
6-
if block["@type"] == "schemaForm":
7-
return [{
8-
"field_id": k,
9-
"value": v,
10-
"label": block["schema"]["properties"].get(k, {}).get("title", k),
11-
} for k, v in data["data"].items()]
12-
13-
skip_fields = [
14-
x.get("field_id", "")
15-
for x in block.get("subblocks", [])
16-
if x.get("field_type", "") == "attachment"
17-
]
18-
return [
19-
x
20-
for x in data.get("data", [])
21-
if x.get("field_id", "") not in skip_fields
22-
]
5+
return [{
6+
"field_id": k,
7+
"value": v,
8+
"label": block["schema"]["properties"].get(k, {}).get("title", k),
9+
} for k, v in data.items()]

backend/src/collective/volto/formsupport/processors/email.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ class EmailFormProcessor:
3232

3333
order = 1
3434

35-
def __init__(self, context):
35+
def __init__(self, context: FormSubmissionContext):
3636
self.context = context.context
3737
self.request = context.request
3838
self.block = context.block
3939
self.form_data = context.form_data
40+
self.attachments = context.attachments
4041

4142
def __call__(self):
4243
if not self.block.get("send"):
@@ -161,9 +162,9 @@ def substitute_variables(self, value):
161162

162163
def get_value(self, field_id, default=None):
163164
if self.block.get("@type") == "schemaForm":
164-
return self.form_data["data"].get(field_id, default)
165+
return self.form_data.get(field_id, default)
165166

166-
for field in self.form_data.get("data", []):
167+
for field in self.form_data:
167168
if field.get("field_id") == field_id:
168169
return field.get("value", default)
169170
return default
@@ -182,7 +183,7 @@ def get_bcc(self):
182183
if field_id not in bcc_fields:
183184
bcc_fields.append(field_id)
184185
bcc = []
185-
for field in self.form_data.get("data", []):
186+
for field in self.form_data:
186187
value = field.get("value", "")
187188
if not value:
188189
continue
@@ -223,7 +224,7 @@ def prepare_message(self):
223224
return message_template(**parameters)
224225

225226
def manage_attachments(self, msg):
226-
attachments = self.form_data.get("attachments", {})
227+
attachments = self.attachments
227228

228229
if not attachments:
229230
return []
@@ -262,6 +263,6 @@ def get_acknowledgement_field_value(self):
262263
acknowledgementField = self.block["acknowledgementFields"]
263264
for field in self.block.get("subblocks", []):
264265
if field.get("field_id") == acknowledgementField:
265-
for submitted in self.form_data.get("data", []):
266+
for submitted in self.form_data:
266267
if submitted.get("field_id", "") == field.get("field_id"):
267268
return submitted.get("value")

backend/src/collective/volto/formsupport/restapi/services/submit_form/post.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def reply(self):
5858
context=self.context,
5959
request=self.request,
6060
block=self.block,
61-
form_data=self.form_data,
61+
form_data=self.form_data.get("data", {}),
62+
attachments=self.form_data.get("attachments", {}),
6263
)
6364
for handler in sorted(subscribers((form_submission_context,), IFormSubmissionProcessor), key=lambda h: h.order):
6465
try:

0 commit comments

Comments
 (0)