Skip to content

Commit

Permalink
Merge pull request #1200 from rcpch/mbarton/crash-downloading-org-audit
Browse files Browse the repository at this point in the history
Fix crash exporting org audit
  • Loading branch information
mbarton authored Feb 3, 2025
2 parents 33b5fde + f7686a4 commit 5d20bab
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions epilepsy12/organisational_audit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import pandas as pd

from django.forms.fields import TypedChoiceField
Expand All @@ -12,6 +14,10 @@

from .forms_folder import OrganisationalAuditSubmissionForm


logger = logging.getLogger(__name__)


MULTISELECT_FIELD_MAPPINGS = {
'S01ESNFunctions': {
"1": 'S01ESNEDVisit',
Expand Down Expand Up @@ -153,14 +159,20 @@ def export_submission_period_as_csv(submission_period):
'SiteCode': site_code
}

logger.info(f"Exporting submission {submission.id} for {site_name} ({site_code})")

for field in OrganisationalAuditSubmissionForm():
value = getattr(submission, field.name)

if type(field.field) is MultiSelectFormField:
selected_choices = list(value)

for choice, column in MULTISELECT_FIELD_MAPPINGS[field.name].items():
row[column] = "1" if choice in selected_choices else "2"
if value is None:
logger.warn(f"No value for MultiSelectFormField {field.name} for {site_name} ({site_code})")
row[field.name] = None
else:
selected_choices = list(value)

for choice, column in MULTISELECT_FIELD_MAPPINGS[field.name].items():
row[column] = "1" if choice in selected_choices else "2"
else:
row[field.name] = value

Expand Down

0 comments on commit 5d20bab

Please sign in to comment.