예제 #1
0
파일: tasks.py 프로젝트: dimagi/commcare-hq
 def save_instance(instance):
     if isinstance(instance, AlertScheduleInstance):
         save_alert_schedule_instance(instance)
     elif isinstance(instance, TimedScheduleInstance):
         save_timed_schedule_instance(instance)
     elif isinstance(instance, (CaseAlertScheduleInstance, CaseTimedScheduleInstance)):
         save_case_schedule_instance(instance)
     else:
         raise TypeError("Unexpected type: %s" % type(instance))
예제 #2
0
 def save_instance(instance):
     if isinstance(instance, AlertScheduleInstance):
         save_alert_schedule_instance(instance)
     elif isinstance(instance, TimedScheduleInstance):
         save_timed_schedule_instance(instance)
     elif isinstance(
             instance,
         (CaseAlertScheduleInstance, CaseTimedScheduleInstance)):
         save_case_schedule_instance(instance)
     else:
         raise TypeError("Unexpected type: %s" % type(instance))
예제 #3
0
    if existing_instances:
        # Don't refresh AlertSchedules that have already been sent
        # to avoid sending old alerts to new recipients
        return

    recipients = set(convert_to_tuple_of_tuples(action_definition.recipients))
    for recipient_type, recipient_id in recipients:
        instance = CaseAlertScheduleInstance.create_for_recipient(
            schedule,
            recipient_type,
            recipient_id,
            move_to_next_event_not_in_the_past=False,
            case_id=case.case_id,
            rule_id=rule.pk
        )
        save_case_schedule_instance(instance)


def refresh_case_timed_schedule_instances(case, schedule, action_definition, rule, start_date=None):
    """
    :param case: the CommCareCase/SQL
    :param schedule: the TimedSchedule
    :param action_definition: the CreateScheduleInstanceActionDefinition that is
    causing the schedule instances to be refreshed
    :param rule: the AutomaticUpdateRule that is causing the schedule instances
    to be refreshed
    :param start_date: the date to start the TimedSchedule
    """

    existing_instances = {
        (instance.recipient_type, instance.recipient_id): instance