Skip to content

Commit

Permalink
fix handling of form data
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Sep 20, 2024
1 parent 95304b7 commit 8b7f82b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 26 deletions.
1 change: 1 addition & 0 deletions backend/src/collective/volto/formsupport/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class FormSubmissionContext:
context: DexterityContent
block: dict
form_data: dict
attachments: dict
request: BaseRequest


Expand Down
25 changes: 6 additions & 19 deletions backend/src/collective/volto/formsupport/processors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
def filter_parameters(data, block):
"""
do not send attachments fields.
TODO do not send attachments fields.
"""
# TODO: handle attachments for schemaForm block
if block["@type"] == "schemaForm":
return [{
"field_id": k,
"value": v,
"label": block["schema"]["properties"].get(k, {}).get("title", k),
} for k, v in data["data"].items()]

skip_fields = [
x.get("field_id", "")
for x in block.get("subblocks", [])
if x.get("field_type", "") == "attachment"
]
return [
x
for x in data.get("data", [])
if x.get("field_id", "") not in skip_fields
]
return [{
"field_id": k,
"value": v,
"label": block["schema"]["properties"].get(k, {}).get("title", k),
} for k, v in data.items()]
13 changes: 7 additions & 6 deletions backend/src/collective/volto/formsupport/processors/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class EmailFormProcessor:

order = 1

def __init__(self, context):
def __init__(self, context: FormSubmissionContext):
self.context = context.context
self.request = context.request
self.block = context.block
self.form_data = context.form_data
self.attachments = context.attachments

def __call__(self):
if not self.block.get("send"):
Expand Down Expand Up @@ -161,9 +162,9 @@ def substitute_variables(self, value):

def get_value(self, field_id, default=None):
if self.block.get("@type") == "schemaForm":
return self.form_data["data"].get(field_id, default)
return self.form_data.get(field_id, default)

for field in self.form_data.get("data", []):
for field in self.form_data:
if field.get("field_id") == field_id:
return field.get("value", default)
return default
Expand All @@ -182,7 +183,7 @@ def get_bcc(self):
if field_id not in bcc_fields:
bcc_fields.append(field_id)
bcc = []
for field in self.form_data.get("data", []):
for field in self.form_data:
value = field.get("value", "")
if not value:
continue
Expand Down Expand Up @@ -223,7 +224,7 @@ def prepare_message(self):
return message_template(**parameters)

def manage_attachments(self, msg):
attachments = self.form_data.get("attachments", {})
attachments = self.attachments

if not attachments:
return []
Expand Down Expand Up @@ -262,6 +263,6 @@ def get_acknowledgement_field_value(self):
acknowledgementField = self.block["acknowledgementFields"]
for field in self.block.get("subblocks", []):
if field.get("field_id") == acknowledgementField:
for submitted in self.form_data.get("data", []):
for submitted in self.form_data:
if submitted.get("field_id", "") == field.get("field_id"):
return submitted.get("value")
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def reply(self):
context=self.context,
request=self.request,
block=self.block,
form_data=self.form_data,
form_data=self.form_data.get("data", {}),
attachments=self.form_data.get("attachments", {}),
)
for handler in sorted(subscribers((form_submission_context,), IFormSubmissionProcessor), key=lambda h: h.order):
try:
Expand Down

0 comments on commit 8b7f82b

Please sign in to comment.