本文整理汇总了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])
)
示例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)