Skip to content

Commit

Permalink
fix: various fixes
Browse files Browse the repository at this point in the history
this pull request attempts to address:

- nditech/apollo-issues#89, where the "recent phone" was inaccurate
- nditech/apollo-issues#90, where the "db phone" and "recent phone" were to be updated
- nditech/apollo-issues#91, where a specific order for participant phone numbers was to be set
- nditech/apollo-issues#92, where the "db phone" and "recent phone" for location submission export was to match the observer export
  • Loading branch information
dodumosu committed Sep 18, 2020
1 parent 73f2e1b commit 8d42cef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions apollo/formsframework/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def save(self, commit=True):
submission.sender_verified = phone_contact.verified

if commit:
phone_contact.touch()
phone_contact.save()
else:
if submission.id is None:
Expand All @@ -254,6 +255,7 @@ def save(self, commit=True):
number=phone_num, participant_id=participant.id)

if commit:
phone_contact.touch()
phone_contact.save()

if commit:
Expand Down
7 changes: 6 additions & 1 deletion apollo/participants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ def phones(self):
if not hasattr(self, '_phones'):
phones = PhoneContact.query.filter_by(
participant_id=self.id
).order_by(PhoneContact.updated).all()
).order_by(
PhoneContact.verified.desc(),
PhoneContact.updated.desc()).all()
self._phones = phones

return self._phones
Expand Down Expand Up @@ -391,6 +393,9 @@ class PhoneContact(BaseModel):

participant = db.relationship('Participant')

def touch(self):
self.updated = utils.current_timestamp()


class ContactHistory(BaseModel):
id = db.Column(db.Integer, nullable=False, primary_key=True)
Expand Down
4 changes: 2 additions & 2 deletions apollo/participants/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from apollo.participants.models import (
ParticipantSet,
Participant, ParticipantGroup, ParticipantGroupType, ParticipantPartner,
ParticipantRole, PhoneContact, Sample, samples_participants)
ParticipantRole, PhoneContact, samples_participants)

number_regex = re.compile('[^0-9]')

Expand Down Expand Up @@ -59,7 +59,7 @@ def export_list(self, query):
output_buffer.close()

for participant in query:
phones = participant.phone_contacts
phones = participant.phones
if phones:
phone_numbers = [p.number for p in phones[:3]]
phone_numbers += [''] * (3 - len(phone_numbers))
Expand Down
8 changes: 2 additions & 6 deletions apollo/submissions/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def export_list(self, query):
if submission.participant else '',
submission.participant.primary_phone
if submission.participant else '',
sorted(submission.participant.phone_contacts, key=lambda p: p.updated, reverse=True)[0].number # noqa
if submission.participant and
submission.participant.phone_contacts else '',
submission.last_phone_number,
] + [
submission.location.make_path().get(loc_type.name, '')
for loc_type in location_types
Expand Down Expand Up @@ -137,9 +135,7 @@ def export_list(self, query):
if sib.participant else '',
sib.participant.primary_phone
if sib.participant else '',
sib.participant.phone_contacts[0].number
if sib.participant and sib.participant.phone_contacts
else '',
sib.last_phone_number,
] + [
sib.location.make_path().get(loc_type.name, '')
for loc_type in location_types
Expand Down

0 comments on commit 8d42cef

Please sign in to comment.