Skip to content

Commit

Permalink
fix FormDataStore for schemaForm
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Aug 26, 2024
1 parent ca4632c commit ff5348e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
40 changes: 16 additions & 24 deletions backend/src/collective/volto/formsupport/datamanager/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,24 @@ def block_id(self):

def get_form_fields(self):
blocks = get_blocks(self.context)

if not blocks:
return {}
form_block = {}
for id_, block in blocks.items():
if id_ != self.block_id:
continue
block_type = block.get("@type", "")
if block_type == "form" or block_type == "schemaForm":
form_block = deepcopy(block)
if not form_block:
return {}

# TODO: get fields for schemaForm block
if block["@type"] == "schemaForm":
return block.get("data", {})

subblocks = form_block.get("subblocks", [])

# Add the 'custom_field_id' field back in as this isn't stored with each
# subblock
for index, field in enumerate(subblocks):
if form_block.get(field["field_id"]):
subblocks[index]["custom_field_id"] = form_block.get(field["field_id"])

return subblocks
block = blocks.get(self.block_id, {})
block_type = block.get("@type", "")
if block_type == "schemaForm":
return [
{"field_id": name, "label": field.get("title", name)}
for name, field in block["schema"]["properties"].items()
]
elif block_type == "form":
subblocks = block.get("subblocks", [])
# Add the 'custom_field_id' field back in as this isn't stored with each
# subblock
for index, field in enumerate(subblocks):
if block.get(field["field_id"]):
subblocks[index]["custom_field_id"] = block.get(field["field_id"])
return subblocks
return {}

def add(self, data):
form_fields = self.get_form_fields()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __call__(self, expand=False):
return {}
if self.block_id:
service_id = (
f"{self.context.absolute_url()}/@form-data?block_id{self.block_id}"
f"{self.context.absolute_url()}/@form-data?block_id={self.block_id}"
)
else:
service_id = f"{self.context.absolute_url()}/@form-data"
Expand All @@ -81,7 +81,7 @@ def form_block(self):
if not blocks:
return {}
for id_, block in blocks.items():
if block.get("@type", "") == "form" and block.get("store", False):
if block.get("@type", "") in ("form", "schemaForm") and block.get("store", False):
if not self.block_id or self.block_id == id_:
return block
return {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def filter_parameters(self):
# TODO: handle attachments for schemaForm block
if self.block["@type"] == "schemaForm":
return [{
"field_id": k,
"value": v,
"label": self.block["schema"]["properties"].get(k, {}).get("title", k),
} for k, v in self.form_data["data"].items()]
Expand Down

0 comments on commit ff5348e

Please sign in to comment.