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: 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