Created
May 27, 2019 11:32
-
-
Save dirkcuys/3d24a3426abc3a7fa4a8a00868f9bdfc to your computer and use it in GitHub Desktop.
Sending logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
def send_facilitator_survey(study_group): | |
""" send survey to all facilitators two days before their second to last meeting """ | |
now = timezone.now() | |
end_of_window = now.replace(minute=0, second=0, microsecond=0) | |
start_of_window = end_of_window - datetime.timedelta(hours=1) | |
last_two_meetings = study_group.meeting_set.active().order_by('-meeting_date', '-meeting_time')[:2] | |
time_to_send = None | |
if last_two_meetings.count() == 2: | |
penultimate_meeting = last_two_meetings[1] | |
time_to_send = penultimate_meeting.meeting_datetime() - datetime.timedelta(days=2, hours=1) | |
if time_to_send and time_to_send > start_of_window and time_to_send <= end_of_window: | |
facilitator_name = study_group.facilitator.first_name | |
path = reverse('studygroups_facilitator_survey', kwargs={'study_group_id': study_group.id}) | |
base_url = f'{settings.PROTOCOL}://{settings.DOMAIN}' | |
survey_url = base_url + path | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will send an ~hour later than intended. The time_to_send will be in the period before the period we're currently in.
time_to_send
- this is when we want to sendnow.replace(minute=0, second=0, microsecond=0)
is the start of the period we are currently inThe reasonable condition to satisfy is
Iow, trigger the event in the same period than the intended time to trigger the event.