From 6ce4b0b8da5aa1ef65878dc97e0314352a263658 Mon Sep 17 00:00:00 2001 From: sujanadh Date: Fri, 29 Dec 2023 21:45:40 +0545 Subject: [PATCH 1/2] feat: submission form fields for the submision table --- .../app/submission/submission_routes.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/backend/app/submission/submission_routes.py b/src/backend/app/submission/submission_routes.py index 0f5d5832bb..d19a6c0437 100644 --- a/src/backend/app/submission/submission_routes.py +++ b/src/backend/app/submission/submission_routes.py @@ -29,6 +29,8 @@ from app.config import settings from app.db import database from app.projects import project_crud, project_schemas +from app.central import central_crud +from app.tasks import tasks_crud from app.submission import submission_crud @@ -332,4 +334,24 @@ async def get_submission_page( submission_crud.update_submission_in_s3, db, project_id, background_task_id ) - return data \ No newline at end of file + return data + + +@router.get("/submission_form_fields/{project_id}") +async def get_submission_form_fields(project_id: int, db: Session = Depends(database.get_db)): + """ + Retrieves the submission form for a specific project. + + Args: + project_id (int): The ID of the project. + db (Session, optional): The database session. Defaults to Depends(database.get_db). + + Returns: + Any: The response from the submission form API. + """ + + project = await project_crud.get_project(db, project_id) + task_list = await tasks_crud.get_task_id_list(db, project_id) + odk_form = central_crud.get_odk_form(project) + response = odk_form.form_fields(project.odkid, str(task_list[0])) + return response \ No newline at end of file From 03b41177ff1c729b66a0e45b97844b4cffbee6bf Mon Sep 17 00:00:00 2001 From: sujanadh Date: Tue, 2 Jan 2024 14:10:05 +0545 Subject: [PATCH 2/2] fix: updated get submission function by including missing parameters --- src/backend/app/central/central_routes.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/backend/app/central/central_routes.py b/src/backend/app/central/central_routes.py index 371c68bf68..6e42b0c806 100644 --- a/src/backend/app/central/central_routes.py +++ b/src/backend/app/central/central_routes.py @@ -229,13 +229,13 @@ async def get_submission( odk_central_password=first.odk_central_password, ) - submissions = list() + submissions = [] if xmlFormId and submission_id: data = central_crud.download_submissions( first.odkid, xmlFormId, submission_id, True, odk_credentials ) - if len(submissions) == 0: + if submissions != 0: submissions.append(json.loads(data[0])) if len(data) >= 2: for entry in range(1, len(data)): @@ -243,30 +243,31 @@ async def get_submission( else: if not xmlFormId: - xforms = central_crud.list_odk_xforms(first.odkid) + xforms = central_crud.list_odk_xforms(first.odkid, odk_credentials) for xform in xforms: try: data = central_crud.download_submissions( first.odkid, - xform["xml_form_id"], + xform["xmlFormId"], None, True, odk_credentials, ) except Exception: continue - if len(submissions) == 0: - submissions.append(json.loads(data[0])) + # if len(submissions) == 0: + submissions.append(json.loads(data[0])) if len(data) >= 2: for entry in range(1, len(data)): submissions.append(json.loads(data[entry])) else: - data = central_crud.download_submissions(first.odkid, xmlFormId) - if len(submissions) == 0: - submissions.append(json.loads(data[0])) + data = central_crud.download_submissions(first.odkid, xmlFormId, None, True, odk_credentials) + submissions.append(json.loads(data[0])) if len(data) >= 2: for entry in range(1, len(data)): submissions.append(json.loads(data[entry])) + if len(submissions) == 1: + return submissions[0] return submissions except Exception as e: