Skip to content

Commit

Permalink
Export form serials (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
dodumosu authored May 22, 2021
1 parent 4c0b55b commit b14c05b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
24 changes: 17 additions & 7 deletions apollo/submissions/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,20 @@ def export_list(self, query):

sample_headers = [s.name for s in samples]

dataset_headers = [
if form.form_type == 'SURVEY':
dataset_headers = [_('Serial')]
else:
dataset_headers = []

dataset_headers.extend([
_('Participant ID'), _('Name'), _('DB Phone'), _('Recent Phone')
] + [
loc_type.name for loc_type in location_types
] + [
_('Location'), _('Location Code'), _('Latitude'), _('Longitude')
] + extra_field_headers + [
_('Registered Voters')
] + tags + [_('Timestamp')]
] + tags + [_('Timestamp')])

if form.form_type == 'INCIDENT':
dataset_headers.extend([_('Status'), _('Description')])
Expand All @@ -85,14 +90,16 @@ def export_list(self, query):
else:
extra_data_columns = [''] * len(extra_fields)

record = [
record = [submission.serial_no] if form.form_type == 'SURVEY' else [] # noqa

record.extend([
submission.participant.participant_id
if submission.participant else '',
submission.participant.name
if submission.participant else '',
submission.participant.primary_phone
if submission.participant else '',
submission.last_phone_number if submission.last_phone_number else '',
submission.last_phone_number if submission.last_phone_number else '', # noqa
] + [
submission.location.make_path().get(loc_type.name, '')
for loc_type in location_types
Expand All @@ -106,7 +113,7 @@ def export_list(self, query):
] + [
export_field_value(form, submission, tag)
for tag in tags
]
])

record += [
submission.updated.strftime('%Y-%m-%d %H:%M:%S')
Expand All @@ -130,7 +137,10 @@ def export_list(self, query):
]
else:
extra_data_columns = [''] * len(extra_fields)
record = [

record = [sib.serial_no] if form.form_type == 'SURVEY' else []

record.extend([
sib.participant.participant_id
if sib.participant else '',
sib.participant.name
Expand All @@ -150,7 +160,7 @@ def export_list(self, query):
sib.location.registered_voters
] + [
export_field_value(form, submission, tag)
for tag in tags]
for tag in tags])

record += [
sib.updated.strftime('%Y-%m-%d %H:%M:%S')
Expand Down
4 changes: 2 additions & 2 deletions apollo/submissions/views_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ def submission_list(form_id):
'participant': s.participant.name,
'participant_id': s.participant.participant_id,
'phone': s.participant.primary_phone,
'last_updated': s.participant_updated.strftime('%b %d, %Y %l:%M %p'), # noqa
'last_updated_timestamp': s.participant_updated.strftime('%s'), # noqa
'last_updated': s.participant_updated.strftime('%b %d, %Y %l:%M %p') if s.participant_updated else None, # noqa
'last_updated_timestamp': s.participant_updated.strftime('%s') if s.participant_updated else None, # noqa
}))
feature_collection = geojson.FeatureCollection(features)

Expand Down

0 comments on commit b14c05b

Please sign in to comment.