当前位置: 首页>>代码示例>>Python>>正文


Python CaseReminderHandler.retire方法代码示例

本文整理汇总了Python中corehq.apps.reminders.models.CaseReminderHandler.retire方法的典型用法代码示例。如果您正苦于以下问题:Python CaseReminderHandler.retire方法的具体用法?Python CaseReminderHandler.retire怎么用?Python CaseReminderHandler.retire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.apps.reminders.models.CaseReminderHandler的用法示例。


在下文中一共展示了CaseReminderHandler.retire方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cache

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import retire [as 别名]
    def test_cache(self, check_state_mock):
        domain = 'reminder-cache-test'

        # Nothing expected at first
        self.assertEqual(
            CaseReminderHandler.get_handler_ids(domain),
            []
        )

        # Create two reminder definitions of different types
        handler1 = CaseReminderHandler(
            domain=domain,
            reminder_type=REMINDER_TYPE_DEFAULT,
        )
        handler1.save()
        self.addCleanup(handler1.delete)

        handler2 = CaseReminderHandler(
            domain=domain,
            reminder_type=REMINDER_TYPE_ONE_TIME,
        )
        handler2.save()
        self.addCleanup(handler2.delete)

        self.assertEqual(
            CaseReminderHandler.get_handler_ids(domain, reminder_type_filter=REMINDER_TYPE_DEFAULT),
            [handler1._id]
        )

        self.assertEqual(
            CaseReminderHandler.get_handler_ids(domain, reminder_type_filter=REMINDER_TYPE_ONE_TIME),
            [handler2._id]
        )

        self.assertEqual(
            sorted(CaseReminderHandler.get_handler_ids(domain)),
            sorted([handler1._id, handler2._id])
        )

        # Add another with default type
        handler3 = CaseReminderHandler(
            domain=domain,
            reminder_type=REMINDER_TYPE_DEFAULT,
        )
        handler3.save()
        self.addCleanup(handler3.delete)

        self.assertEqual(
            sorted(CaseReminderHandler.get_handler_ids(domain, reminder_type_filter=REMINDER_TYPE_DEFAULT)),
            sorted([handler1._id, handler3._id])
        )

        self.assertEqual(
            CaseReminderHandler.get_handler_ids(domain, reminder_type_filter=REMINDER_TYPE_ONE_TIME),
            [handler2._id]
        )

        self.assertEqual(
            sorted(CaseReminderHandler.get_handler_ids(domain)),
            sorted([handler1._id, handler2._id, handler3._id])
        )

        # Retire the one-time reminder
        handler2.retire()

        self.assertEqual(
            sorted(CaseReminderHandler.get_handler_ids(domain, reminder_type_filter=REMINDER_TYPE_DEFAULT)),
            sorted([handler1._id, handler3._id])
        )

        self.assertEqual(
            CaseReminderHandler.get_handler_ids(domain, reminder_type_filter=REMINDER_TYPE_ONE_TIME),
            []
        )

        self.assertEqual(
            sorted(CaseReminderHandler.get_handler_ids(domain)),
            sorted([handler1._id, handler3._id])
        )
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:81,代码来源:test_cache.py

示例2: add_survey

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import retire [as 别名]

#.........这里部分代码省略.........
                    name = name,
                    waves = wave_list,
                    followups = followups,
                    samples = samples,
                    send_automatically = send_automatically,
                    send_followup = send_followup
                )
            else:
                current_waves = survey.waves
                survey.waves = []
                unchanged_wave_json = []
                
                # Keep any waves that didn't change in case the surveys are in progress
                for wave in current_waves:
                    for wave_json in waves:
                        parsed_date = parse(wave_json["date"]).date()
                        parsed_time = parse(wave_json["time"]).time()
                        if parsed_date == wave.date and parsed_time == wave.time and wave_json["form_id"] == wave.form_id:
                            wave.end_date = parse(wave_json["end_date"]).date()
                            survey.waves.append(wave)
                            unchanged_wave_json.append(wave_json)
                            continue
                
                for wave in survey.waves:
                    current_waves.remove(wave)
                
                for wave_json in unchanged_wave_json:
                    waves.remove(wave_json)
                
                # Retire reminder definitions / close delegation tasks for old waves
                for wave in current_waves:
                    for sample_id, handler_id in wave.reminder_definitions.items():
                        handler = CaseReminderHandler.get(handler_id)
                        handler.retire()
                    for sample_id, delegation_data in wave.delegation_tasks.items():
                        for case_id, delegation_case_id in delegation_data.items():
                            close_task(domain, delegation_case_id, request.couch_user.get_id)
                
                # Add in new waves
                for wave_json in waves:
                    survey.waves.append(SurveyWave(
                        date=parse(wave_json["date"]).date(),
                        time=parse(wave_json["time"]).time(),
                        end_date=parse(wave_json["end_date"]).date(),
                        form_id=wave_json["form_id"],
                        reminder_definitions={},
                        delegation_tasks={},
                    ))
                
                # Retire reminder definitions that are no longer needed
                if send_automatically:
                    new_sample_ids = [sample_json["sample_id"] for sample_json in samples if sample_json["method"] == "SMS"]
                else:
                    new_sample_ids = []
                
                for wave in survey.waves:
                    for sample_id, handler_id in wave.reminder_definitions.items():
                        if sample_id not in new_sample_ids:
                            handler = CaseReminderHandler.get(handler_id)
                            handler.retire()
                            del wave.reminder_definitions[sample_id]
                
                # Update existing reminder definitions
                for wave in survey.waves:
                    for sample_id, handler_id in wave.reminder_definitions.items():
                        handler = CaseReminderHandler.get(handler_id)
开发者ID:tsinkala,项目名称:core-hq,代码行数:70,代码来源:views.py


注:本文中的corehq.apps.reminders.models.CaseReminderHandler.retire方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。