Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: various fixes #738

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 if submission.last_phone_number else '',
] + [
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 if sib.last_phone_number else '',
] + [
sib.location.make_path().get(loc_type.name, '')
for loc_type in location_types
Expand Down