Skip to content

Commit

Permalink
fix: ensure task_id field is always included with submissions (#1589)
Browse files Browse the repository at this point in the history
* build: update osm-fieldwork --> 0.12.2 for latest xlsform task_id fix

* refactor(backend): rename of task_id --> task_filter in xlsforms

* build: update osm-fieldwork --> 0.12.3 for latest xlsform

* refactor(backend): task_id field on submission not nested under 'all' group
  • Loading branch information
spwoodcock authored Jun 20, 2024
1 parent fa3b235 commit 56baab2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
20 changes: 10 additions & 10 deletions src/backend/app/central/central_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ async def modify_xform_xml(
The 'id' field is set to random UUID (xFormId) unless existing_id is specified
The 'name' field is set to the category name.
The upload media must be equal to 'features.csv'.
The task_id options are populated as choices in the form.
The task_filter options are populated as choices in the form.
The form_category value is also injected to display in the instructions.
Args:
Expand Down Expand Up @@ -504,23 +504,23 @@ async def modify_xform_xml(
# NOTE add the task ID choices to the XML
# <instance> must be defined inside <model></model> root element
model_element = root.find(".//xforms:model", namespaces)
# The existing dummy value for task_id must be removed
# The existing dummy value for task_filter must be removed
existing_instance = model_element.find(
".//xforms:instance[@id='task_id']", namespaces
".//xforms:instance[@id='task_filter']", namespaces
)
if existing_instance is not None:
model_element.remove(existing_instance)
# Create a new instance element
instance_task_ids = Element("instance", id="task_id")
root_element = SubElement(instance_task_ids, "root")
instance_task_filters = Element("instance", id="task_filter")
root_element = SubElement(instance_task_filters, "root")
# Create sub-elements for each task ID, <itextId> <name> pairs
for task_id in range(1, task_count + 1):
item = SubElement(root_element, "item")
SubElement(item, "itextId").text = f"task_id-{task_id}"
SubElement(item, "itextId").text = f"task_filter-{task_id}"
SubElement(item, "name").text = str(task_id)
model_element.append(instance_task_ids)
model_element.append(instance_task_filters)

# Add task_id choice translations (necessary to be visible in form)
# Add task_filter choice translations (necessary to be visible in form)
itext_element = root.find(".//xforms:itext", namespaces)
if itext_element is not None:
existing_translations = itext_element.findall(
Expand All @@ -529,14 +529,14 @@ async def modify_xform_xml(
for translation in existing_translations:
# Remove dummy value from existing translations
existing_text = translation.find(
".//xforms:text[@id='task_id-0']", namespaces
".//xforms:text[@id='task_filter-0']", namespaces
)
if existing_text is not None:
translation.remove(existing_text)

# Append new <text> elements for each task_id
for task_id in range(1, task_count + 1):
new_text = Element("text", id=f"task_id-{task_id}")
new_text = Element("text", id=f"task_filter-{task_id}")
value_element = Element("value")
value_element.text = str(task_id)
new_text.append(value_element)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/submissions/submission_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
# submissions = [
# sub
# for sub in submissions
# if sub.get("all", {}).get("task_id") == str(task_id)
# if sub.get("task_id") == str(task_id)
# ]

# if not submissions:
Expand Down
6 changes: 1 addition & 5 deletions src/backend/app/submissions/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,7 @@ async def submission_table(
submissions = data.get("value", [])

if task_id:
submissions = [
sub
for sub in submissions
if sub.get("all", {}).get("task_id") == str(task_id)
]
submissions = [sub for sub in submissions if sub.get("task_id") == str(task_id)]

pagination = await project_crud.get_pagination(page, count, results_per_page, count)
response = submission_schemas.PaginatedSubmissions(
Expand Down
8 changes: 4 additions & 4 deletions src/backend/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
"cryptography>=42.0.1",
"defusedxml>=0.7.1",
"osm-login-python==1.0.3",
"osm-fieldwork==0.12.1",
"osm-fieldwork==0.12.3",
"osm-rawdata==0.3.0",
"fmtm-splitter==1.2.2",
]
Expand Down

0 comments on commit 56baab2

Please sign in to comment.