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

Submission form fields for the submision table #1072

Merged
merged 3 commits into from
Jan 3, 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
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