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


Python CaseReminderHandler.get方法代码示例

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


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

示例1: reminder_handler

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
 def reminder_handler(self):
     try:
         handler = CaseReminderHandler.get(self.handler_id)
         assert handler.domain == self.domain
         assert handler.doc_type == "CaseReminderHandler"
         return handler
     except (ResourceNotFound, AssertionError):
         raise Http404()
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:10,代码来源:views.py

示例2: delete_broadcast

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
    def delete_broadcast(self, broadcast_id):
        try:
            broadcast = CaseReminderHandler.get(broadcast_id)
        except:
            raise Http404()

        if broadcast.doc_type != 'CaseReminderHandler' or broadcast.domain != self.domain:
            raise Http404()

        broadcast.retire()
        return HttpResponse()
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:13,代码来源:views.py

示例3: _case_changed

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
def _case_changed(case_id, handler_ids):
    subcases = None
    case = CommCareCase.get(case_id)
    for handler_id in handler_ids:
        handler = CaseReminderHandler.get(handler_id)
        if handler.start_condition_type == CASE_CRITERIA:
            handler.case_changed(case)
            if handler.uses_parent_case_property:
                if subcases is None:
                    subcases = get_subcases(case)
                for subcase in subcases:
                    handler.case_changed(subcase)
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:14,代码来源:tasks.py

示例4: broadcast

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
    def broadcast(self):
        try:
            broadcast = CaseReminderHandler.get(self.broadcast_id)
        except:
            raise Http404()

        if (
            broadcast.doc_type != 'CaseReminderHandler' or
            broadcast.domain != self.domain or
            broadcast.reminder_type != REMINDER_TYPE_ONE_TIME
        ):
            raise Http404()

        return broadcast
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:16,代码来源:views.py

示例5: add_reminder

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
def add_reminder(request, domain, handler_id=None, template="reminders/partial/add_reminder.html"):

    if handler_id:
        handler = CaseReminderHandler.get(handler_id)
        if handler.doc_type != 'CaseReminderHandler' or handler.domain != domain:
            raise Http404
    else:
        handler = None
        
    if request.method == "POST":
        reminder_form = CaseReminderForm(request.POST)
        if reminder_form.is_valid():
            if not handler:
                handler = CaseReminderHandler(domain=domain)
                handler.ui_type = UI_SIMPLE_FIXED
            for key, value in reminder_form.cleaned_data.items():
                if (key != "frequency") and (key != "message"):
                    handler[key] = value
            handler.max_iteration_count = REPEAT_SCHEDULE_INDEFINITELY
            handler.schedule_length = reminder_form.cleaned_data["frequency"]
            handler.event_interpretation = EVENT_AS_OFFSET
            handler.events = [
                CaseReminderEvent(
                    day_num = 0
                   ,fire_time = time(hour=0,minute=0,second=0)
                   ,message = reminder_form.cleaned_data["message"]
                   ,callback_timeout_intervals = []
               )
            ]
            handler.save()
            print handler.events[0].message
            return HttpResponseRedirect(reverse('list_reminders', args=[domain]))
    elif handler:
        initial = {}
        for key in handler.to_json():
            if (key != "max_iteration_count") and (key != "schedule_length") and (key != "events") and (key != "event_interpretation"):
                initial[key] = handler[key]
        initial["message"] = json.dumps(handler.events[0].message)
        initial["frequency"] = handler.schedule_length
        reminder_form = CaseReminderForm(initial=initial)
    else:
        reminder_form = CaseReminderForm()

    return render_to_response(request, template, {
        'reminder_form': reminder_form,
        'domain': domain
    })
开发者ID:mchampanis,项目名称:core-hq,代码行数:49,代码来源:views.py

示例6: get_reminder_display

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
    def get_reminder_display(self, handler_id, content_cache):
        if handler_id in content_cache:
            return content_cache[handler_id]
        try:
            reminder_definition = CaseReminderHandler.get(handler_id)
            if reminder_definition.deleted():
                display = '%s %s' % (reminder_definition.nickname, _('(Deleted Reminder)'))
            else:
                urlname = EditScheduledReminderView.urlname
                display = '<a target="_blank" href="%s">%s</a>' % (
                    reverse(urlname, args=[reminder_definition.domain, handler_id]),
                    reminder_definition.nickname,
                )
        except ResourceNotFound:
            display = '-'

        content_cache[handler_id] = display
        return display
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:20,代码来源:sms.py

示例7: handle

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
    def handle(self, *args, **options):
        num_dups = 0
        make_fixes = options["fix"]
        ids = {}
        rows = CaseReminder.view("reminders/by_domain_handler_case",
            include_docs=False).all()

        for row in rows:
            row_key = row["key"]
            if row_key[2]:
                ids_key = "|".join(row_key)
                if ids_key in ids:
                    ids[ids_key].append(row["id"])
                else:
                    ids[ids_key] = [row["id"]]

        for k, v in ids.items():
            if len(v) > 1:
                num_dups += 1
                split_key = k.split("|")
                print "Duplicate found: ", split_key

                handler = CaseReminderHandler.get(split_key[1])
                if handler.start_condition_type != CASE_CRITERIA:
                    print ("ERROR: Duplicate with the above key is not a case "
                        "criteria reminder")
                    continue

                all_match = True
                reminders = [CaseReminder.get(i) for i in v]
                for r in reminders[1:]:
                    all_match = all_match and self.reminders_match(reminders[0], r)
                if all_match:
                    if make_fixes:
                        print "Removing duplicate(s)..."
                        for r in reminders[1:]:
                            r.retire()
                        c = CommCareCase.get(split_key[2])
                        case_changed_receiver(None, c)
                else:
                    print "ERROR: Not all of the reminders with the above key match"

        print "%s Duplicate(s) were found" % num_dups
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:45,代码来源:remove_dup_reminders.py

示例8: get_reminder_display

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
    def get_reminder_display(self, handler_id, content_cache):
        if handler_id in content_cache:
            args = content_cache[handler_id]
            return self.table_cell(*args)
        try:
            reminder_definition = CaseReminderHandler.get(handler_id)
            if reminder_definition.deleted():
                display = '%s %s' % (reminder_definition.nickname, _('(Deleted Reminder)'))
                display_text = display
            else:
                urlname = EditScheduledReminderView.urlname
                display = '<a target="_blank" href="%s">%s</a>' % (
                    reverse(urlname, args=[reminder_definition.domain, handler_id]),
                    reminder_definition.nickname,
                )
                display_text = reminder_definition.nickname
            args = (display_text, display)
        except ResourceNotFound:
            args = ('-', '-')

        content_cache[handler_id] = args
        return self.table_cell(*args)
开发者ID:ekush,项目名称:commcare-hq,代码行数:24,代码来源:sms.py

示例9: reminder

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
 def reminder(self):
     return CaseReminderHandler.get(self.reminder_id)
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:4,代码来源:views.py

示例10: delete_reminder

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
def delete_reminder(request, domain, handler_id):
    handler = CaseReminderHandler.get(handler_id)
    if handler.doc_type != 'CaseReminderHandler' or handler.domain != domain:
        raise Http404
    handler.retire()
    return HttpResponseRedirect(reverse('list_reminders', args=[domain]))
开发者ID:mchampanis,项目名称:core-hq,代码行数:8,代码来源:views.py

示例11: add_complex_reminder_schedule

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
def add_complex_reminder_schedule(request, domain, handler_id=None):
    if handler_id:
        h = CaseReminderHandler.get(handler_id)
        if h.doc_type != 'CaseReminderHandler' or h.domain != domain:
            raise Http404
    else:
        h = None
    
    form_list = get_form_list(domain)
    
    if request.method == "POST":
        form = ComplexCaseReminderForm(request.POST)
        if form.is_valid():
            if h is None:
                h = CaseReminderHandler(domain=domain)
                h.ui_type = UI_COMPLEX
            h.case_type = form.cleaned_data["case_type"]
            h.nickname = form.cleaned_data["nickname"]
            h.default_lang = form.cleaned_data["default_lang"]
            h.method = form.cleaned_data["method"]
            h.recipient = form.cleaned_data["recipient"]
            h.start_property = form.cleaned_data["start_property"]
            h.start_value = form.cleaned_data["start_value"]
            h.start_date = form.cleaned_data["start_date"]
            h.start_offset = form.cleaned_data["start_offset"]
            h.start_match_type = form.cleaned_data["start_match_type"]
            h.schedule_length = form.cleaned_data["schedule_length"]
            h.event_interpretation = form.cleaned_data["event_interpretation"]
            h.max_iteration_count = form.cleaned_data["max_iteration_count"]
            h.until = form.cleaned_data["until"]
            h.events = form.cleaned_data["events"]
            h.save()
            return HttpResponseRedirect(reverse('list_reminders', args=[domain]))
    else:
        if h is not None:
            initial = {
                "case_type"             : h.case_type
               ,"nickname"              : h.nickname
               ,"default_lang"          : h.default_lang
               ,"method"                : h.method
               ,"recipient"             : h.recipient
               ,"start_property"        : h.start_property
               ,"start_value"           : h.start_value
               ,"start_date"            : h.start_date
               ,"start_match_type"      : h.start_match_type
               ,"start_offset"          : h.start_offset
               ,"schedule_length"       : h.schedule_length
               ,"event_interpretation"  : h.event_interpretation
               ,"max_iteration_count"   : h.max_iteration_count
               ,"until"                 : h.until
               ,"events"                : h.events
            }
        else:
            initial = {}
        
        form = ComplexCaseReminderForm(initial=initial)
    
    return render_to_response(request, "reminders/partial/add_complex_reminder.html", {
        "domain":       domain
       ,"form":         form
       ,"form_list":    form_list
    })
开发者ID:mchampanis,项目名称:core-hq,代码行数:64,代码来源:views.py

示例12: add_survey

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
def add_survey(request, domain, survey_id=None):
    survey = None
    
    if survey_id is not None:
        survey = Survey.get(survey_id)
    
    if request.method == "POST":
        form = SurveyForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data.get("name")
            waves = form.cleaned_data.get("waves")
            followups = form.cleaned_data.get("followups")
            samples = form.cleaned_data.get("samples")
            send_automatically = form.cleaned_data.get("send_automatically")
            send_followup = form.cleaned_data.get("send_followup")
            
            sample_data = {}
            for sample in samples:
                sample_data[sample["sample_id"]] = sample
            
            if send_followup:
                timeout_intervals = [int(followup["interval"]) * 1440 for followup in followups]
            else:
                timeout_intervals = []
            
            timeout_duration = sum(timeout_intervals) / 1440
            final_timeout = lambda wave : [((wave.end_date - wave.date).days - timeout_duration) * 1440]
            
            if survey is None:
                wave_list = []
                for wave in waves:
                    wave_list.append(SurveyWave(
                        date=parse(wave["date"]).date(),
                        time=parse(wave["time"]).time(),
                        end_date=parse(wave["end_date"]).date(),
                        form_id=wave["form_id"],
                        reminder_definitions={},
                        delegation_tasks={},
                    ))
                
                if send_automatically:
                    for wave in wave_list:
                        for sample in samples:
                            if sample["method"] == "SMS":
                                handler = CaseReminderHandler(
                                    domain = domain,
                                    nickname = "Survey '%s'" % name,
                                    default_lang = "en",
                                    method = "survey",
                                    recipient = RECIPIENT_SURVEY_SAMPLE,
                                    start_condition_type = ON_DATETIME,
                                    start_datetime = datetime.combine(wave.date, time(0,0)),
                                    start_offset = 0,
                                    events = [CaseReminderEvent(
                                        day_num = 0,
                                        fire_time = wave.time,
                                        form_unique_id = wave.form_id,
                                        callback_timeout_intervals = timeout_intervals + final_timeout(wave),
                                    )],
                                    schedule_length = 1,
                                    event_interpretation = EVENT_AS_SCHEDULE,
                                    max_iteration_count = 1,
                                    sample_id = sample["sample_id"],
                                    survey_incentive = sample["incentive"],
                                    submit_partial_forms = True,
                                )
                                handler.save()
                                wave.reminder_definitions[sample["sample_id"]] = handler._id
                
                survey = Survey (
                    domain = domain,
                    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)
                
#.........这里部分代码省略.........
开发者ID:tsinkala,项目名称:core-hq,代码行数:103,代码来源:views.py

示例13: add_complex_reminder_schedule

# 需要导入模块: from corehq.apps.reminders.models import CaseReminderHandler [as 别名]
# 或者: from corehq.apps.reminders.models.CaseReminderHandler import get [as 别名]
def add_complex_reminder_schedule(request, domain, handler_id=None):
    if handler_id:
        h = CaseReminderHandler.get(handler_id)
        if h.doc_type != 'CaseReminderHandler' or h.domain != domain:
            raise Http404
    else:
        h = None
    
    form_list = get_form_list(domain)
    sample_list = get_sample_list(domain)
    
    if request.method == "POST":
        form = ComplexCaseReminderForm(request.POST)
        if form.is_valid():
            if h is None:
                h = CaseReminderHandler(domain=domain)
                h.ui_type = UI_COMPLEX
            else:
                if h.start_condition_type != form.cleaned_data["start_condition_type"]:
                    for reminder in h.get_reminders():
                        reminder.retire()
            h.active = form.cleaned_data["active"]
            h.case_type = form.cleaned_data["case_type"]
            h.nickname = form.cleaned_data["nickname"]
            h.default_lang = form.cleaned_data["default_lang"]
            h.method = form.cleaned_data["method"]
            h.recipient = form.cleaned_data["recipient"]
            h.start_property = form.cleaned_data["start_property"]
            h.start_value = form.cleaned_data["start_value"]
            h.start_date = form.cleaned_data["start_date"]
            h.start_offset = form.cleaned_data["start_offset"]
            h.start_match_type = form.cleaned_data["start_match_type"]
            h.schedule_length = form.cleaned_data["schedule_length"]
            h.event_interpretation = form.cleaned_data["event_interpretation"]
            h.max_iteration_count = form.cleaned_data["max_iteration_count"]
            h.until = form.cleaned_data["until"]
            h.events = form.cleaned_data["events"]
            h.submit_partial_forms = form.cleaned_data["submit_partial_forms"]
            h.include_case_side_effects = form.cleaned_data["include_case_side_effects"]
            h.ui_frequency = form.cleaned_data["frequency"]
            h.start_condition_type = form.cleaned_data["start_condition_type"]
            h.max_question_retries = form.cleaned_data["max_question_retries"]
            if form.cleaned_data["start_condition_type"] == "ON_DATETIME":
                dt = parse(form.cleaned_data["start_datetime_date"]).date()
                tm = parse(form.cleaned_data["start_datetime_time"]).time()
                h.start_datetime = datetime.combine(dt, tm)
            else:
                h.start_datetime = None
            h.sample_id = form.cleaned_data["sample_id"]
            h.save()
            return HttpResponseRedirect(reverse('list_reminders', args=[domain]))
    else:
        if h is not None:
            initial = {
                "active"                : h.active,
                "case_type"             : h.case_type,
                "nickname"              : h.nickname,
                "default_lang"          : h.default_lang,
                "method"                : h.method,
                "recipient"             : h.recipient,
                "start_property"        : h.start_property,
                "start_value"           : h.start_value,
                "start_date"            : h.start_date,
                "start_match_type"      : h.start_match_type,
                "start_offset"          : h.start_offset,
                "schedule_length"       : h.schedule_length,
                "event_interpretation"  : h.event_interpretation,
                "max_iteration_count"   : h.max_iteration_count,
                "until"                 : h.until,
                "events"                : h.events,
                "submit_partial_forms"  : h.submit_partial_forms,
                "include_case_side_effects" : h.include_case_side_effects,
                "start_condition_type"  : h.start_condition_type,
                "start_datetime_date"   : str(h.start_datetime.date()) if isinstance(h.start_datetime, datetime) else None,
                "start_datetime_time"   : str(h.start_datetime.time()) if isinstance(h.start_datetime, datetime) else None,
                "frequency"             : h.ui_frequency,
                "sample_id"             : h.sample_id,
                "use_until"             : "Y" if h.until is not None else "N",
                "max_question_retries"  : h.max_question_retries,
            }
        else:
            initial = {
                "events"    : [CaseReminderEvent(day_num=0, fire_time=time(0,0), message={"":""}, callback_timeout_intervals=[], form_unique_id=None)],
                "use_until" : "N",
                "max_question_retries" : QUESTION_RETRY_CHOICES[-1],
                "active" : True,
            }
        
        form = ComplexCaseReminderForm(initial=initial)
    
    return render(request, "reminders/partial/add_complex_reminder.html", {
        "domain":       domain,
        "form":         form,
        "form_list":    form_list,
        "handler_id":   handler_id,
        "sample_list":  sample_list,
    })
开发者ID:tsinkala,项目名称:core-hq,代码行数:99,代码来源:views.py


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