Skip to content

Commit

Permalink
Add URL column and format address. (#4354)
Browse files Browse the repository at this point in the history
Fixes #4027
  • Loading branch information
frjo authored Jan 21, 2025
1 parent 0e4ac94 commit 1bfde70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions hypha/apply/funds/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,25 @@ def get_statuses_as_params(statuses):
return params


def export_submissions_to_csv(submissions_list):
def export_submissions_to_csv(submissions_list, request):
csv_stream = StringIO()
header_row = ["Application #"]
index = 1
header_row = ["Application #", "URL"]
index = 2
data_list = []

for submission in submissions_list:
values = {}
values["Application #"] = submission.id
values["URL"] = request.build_absolute_uri(submission.get_absolute_url())
for field_id in submission.question_text_field_ids:
question_field = submission.serialize(field_id)
field_name = question_field["question"]
field_value = question_field["answer"]
if field_id == "address":
address = []
for key, value in field_value.items():
address.append(f"{key}: {value}")
field_value = "\n".join(address)
if field_name not in header_row:
if field_id not in submission.named_blocks:
header_row.append(field_name)
Expand Down
2 changes: 1 addition & 1 deletion hypha/apply/funds/views/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def submissions_all(
if request.GET.get("format") == "csv" and permissions.can_export_submissions(
request.user
):
csv_data = export_submissions_to_csv(qs)
csv_data = export_submissions_to_csv(qs, request)
response = HttpResponse(csv_data.readlines(), content_type="text/csv")
response["Content-Disposition"] = "attachment; filename=submissions.csv"
return response
Expand Down

0 comments on commit 1bfde70

Please sign in to comment.