Skip to content

Commit

Permalink
feat(backend): form fields for the submision table (#1072)
Browse files Browse the repository at this point in the history
* feat: submission form fields for the submision table

* fix: updated get submission function by including missing parameters

---------

Co-authored-by: sujanadh <[email protected]>
  • Loading branch information
Sujanadh and sujanadh authored Jan 3, 2024
1 parent d728fa7 commit 04bc3ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/backend/app/central/central_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,44 +229,45 @@ 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)):
submissions.append(json.loads(data[entry]))

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:
Expand Down
24 changes: 23 additions & 1 deletion src/backend/app/submission/submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -332,4 +334,24 @@ async def get_submission_page(
submission_crud.update_submission_in_s3, db, project_id, background_task_id
)

return data
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

0 comments on commit 04bc3ed

Please sign in to comment.