Skip to content

Instantly share code, notes, and snippets.

@dirkcuys
Created May 27, 2019 11:32
Show Gist options
  • Select an option

  • Save dirkcuys/3d24a3426abc3a7fa4a8a00868f9bdfc to your computer and use it in GitHub Desktop.

Select an option

Save dirkcuys/3d24a3426abc3a7fa4a8a00868f9bdfc to your computer and use it in GitHub Desktop.

Revisions

  1. dirkcuys created this gist May 27, 2019.
    21 changes: 21 additions & 0 deletions tasks.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # ...

    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

    # ...