Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure task_id field is always included with submissions #1589

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading