Skip to content

Commit 98b8478

Browse files
Backend: Enhance CSV writer in tests to quote all fields for participant teams and submissions (#4812)
* Enhance CSV writer to quote all fields in download responses * Enhance CSV writer in tests to quote all fields for participant teams and submissions * Fix tests * Increase pylint fail-under threshold to 7.5
1 parent 902fafd commit 98b8478

File tree

5 files changed

+612
-671
lines changed

5 files changed

+612
-671
lines changed

apps/analytics/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def download_all_participants(request, challenge_pk):
346346
challenge_pk
347347
)
348348
)
349-
writer = csv.writer(response)
349+
writer = csv.writer(response, quoting=csv.QUOTE_ALL)
350350
writer.writerow(["Team Name", "Team Members", "Email Id"])
351351
for team in teams.data:
352352
writer.writerow(

apps/challenges/views.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def add_participant_team_to_challenge(
611611
"challenge_id": int(challenge_pk),
612612
"participant_team_id": int(participant_team_pk),
613613
}
614-
return Response(response_data, status=status.HTTP_200_OK)
614+
return Response(response_data, status=status.HTTP_406_NOT_ACCEPTABLE)
615615
else:
616616
challenge.participant_teams.add(participant_team)
617617
return Response(status=status.HTTP_201_CREATED)
@@ -2302,7 +2302,7 @@ def download_all_submissions(
23022302
response["Content-Disposition"] = (
23032303
f'attachment; filename="{filename}"'
23042304
)
2305-
writer = csv.writer(response)
2305+
writer = csv.writer(response, quoting=csv.QUOTE_ALL)
23062306
writer.writerow(
23072307
[
23082308
"id",
@@ -2329,9 +2329,6 @@ def download_all_submissions(
23292329
"Submission Meta Attributes",
23302330
]
23312331
)
2332-
# Issue: "#" isn't parsed by writer.writerow(), hence it is replaced by "-"
2333-
# TODO: Find a better way to solve the above issue.
2334-
23352332
# Process submissions efficiently using prefetched data
23362333
logger.info(
23372334
f"Starting to process {submission_count} submissions"
@@ -2399,16 +2396,8 @@ def download_all_submissions(
23992396
if submission.submission_metadata_file
24002397
else ""
24012398
),
2402-
(
2403-
submission.method_name.replace("#", "-")
2404-
if submission.method_name
2405-
else ""
2406-
),
2407-
(
2408-
submission.method_description.replace("#", "-")
2409-
if submission.method_description
2410-
else ""
2411-
),
2399+
submission.method_name or "",
2400+
submission.method_description or "",
24122401
submission.publication_url or "",
24132402
submission.project_url or "",
24142403
submission_meta_attributes,
@@ -2457,7 +2446,7 @@ def download_all_submissions(
24572446
response["Content-Disposition"] = (
24582447
f'attachment; filename="{filename}"'
24592448
)
2460-
writer = csv.writer(response)
2449+
writer = csv.writer(response, quoting=csv.QUOTE_ALL)
24612450
writer.writerow(
24622451
[
24632452
"Team Name",
@@ -2547,7 +2536,7 @@ def download_all_submissions(
25472536
response["Content-Disposition"] = (
25482537
f'attachment; filename="{filename}"'
25492538
)
2550-
writer = csv.writer(response)
2539+
writer = csv.writer(response, quoting=csv.QUOTE_ALL)
25512540
fields = [fields_to_export[field] for field in request.data]
25522541
fields.insert(0, "id")
25532542
writer.writerow(fields)

0 commit comments

Comments
 (0)