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


Python models.CaseReminderHandler类代码示例

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


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

示例1: handle

 def handle(self, *args, **options):
     ids = self.get_reminder_definition_ids()
     for handler_doc in iter_docs(CaseReminderHandler.get_db(), ids):
         handler = CaseReminderHandler.wrap(handler_doc)
         if handler.reminder_type == REMINDER_TYPE_DEFAULT:
             self.check_for_ui_type(handler)
             self.check_for_multiple_fire_time_types(handler)
             self.check_for_datetime_criteria(handler)
             self.check_for_case_group_recipient(handler)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:9,代码来源:check_for_old_reminders.py

示例2: fire_ivr_survey_event

def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers, logged_event):
    domain_obj = Domain.get_by_name(reminder.domain, strict=True)
    for recipient in recipients:
        initiate_call = True
        if reminder.callback_try_count > 0 and reminder.event_initiation_timestamp:
            initiate_call = not Call.answered_call_exists(
                recipient.doc_type,
                recipient.get_id,
                reminder.event_initiation_timestamp
            )

        if initiate_call:
            if (is_commcarecase(recipient) and
                not handler.force_surveys_to_use_triggered_case):
                case_id = recipient.case_id
            else:
                case_id = reminder.case_id
            verified_number, unverified_number = get_recipient_phone_number(
                reminder, recipient, verified_numbers)
            if verified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    logged_event.pk,
                    verified_number=verified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            elif domain_obj.send_to_duplicated_case_numbers and unverified_number:
                initiate_outbound_call.delay(
                    recipient,
                    reminder.current_event.form_unique_id,
                    handler.submit_partial_forms,
                    handler.include_case_side_effects,
                    handler.max_question_retries,
                    logged_event.pk,
                    unverified_number=unverified_number,
                    case_id=case_id,
                    case_for_case_submission=handler.force_surveys_to_use_triggered_case,
                    timestamp=CaseReminderHandler.get_now(),
                )
            else:
                # initiate_outbound_call will create the subevent automatically,
                # so since we're not initiating the call here, we have to create
                # the subevent explicitly in order to log the error.
                logged_subevent = logged_event.create_subevent(handler, reminder, recipient)
                logged_subevent.error(MessagingEvent.ERROR_NO_PHONE_NUMBER)
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:51,代码来源:event_handlers.py

示例3: get_broadcast_ajax_response

    def get_broadcast_ajax_response(self, upcoming=True):
        """
        upcoming - True to include only upcoming broadcasts, False to include
                   only past broadcasts.
        """
        if upcoming:
            ids = CaseReminderHandler.get_upcoming_broadcast_ids(self.domain)
        else:
            ids = CaseReminderHandler.get_past_broadcast_ids(self.domain)

        total_records = len(ids)
        ids = ids[self.display_start:self.display_start + self.display_length]
        data = self.format_broadcast_data(ids)
        return self.datatables_ajax_response(data, total_records)
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:14,代码来源:views.py

示例4: _active_reminders

 def _active_reminders(self):
     db = CaseReminderHandler.get_db()
     key = [self.domain.name]
     reminder_rules = db.view(
         'reminders/handlers_by_reminder_type',
         startkey=key,
         endkey=key+[{}],
         reduce=False
     ).all()
     active_reminders = []
     for reminder_doc in iter_docs(db, [r['id'] for r in reminder_rules]):
         if reminder_doc.get('active', True):
             active_reminders.append(CaseReminderHandler.wrap(reminder_doc))
     return active_reminders
开发者ID:pawelreise,项目名称:commcare-hq,代码行数:14,代码来源:subscription_changes.py

示例5: list_reminders

def list_reminders(request, domain, template="reminders/partial/list_reminders.html"):
    handlers = CaseReminderHandler.get_handlers(domain=domain).all()
    print handlers
    return render_to_response(request, template, {
        'domain': domain,
        'reminder_handlers': handlers
    })
开发者ID:mchampanis,项目名称:core-hq,代码行数:7,代码来源:views.py

示例6: get_active_reminders_by_domain_name

def get_active_reminders_by_domain_name(domain_name):
    from corehq.apps.reminders.models import CaseReminderHandler, REMINDER_TYPE_DEFAULT, REMINDER_TYPE_KEYWORD_INITIATED

    db = CaseReminderHandler.get_db()
    key = [domain_name]
    reminder_rules = db.view(
        "reminders/handlers_by_reminder_type", startkey=key, endkey=(key + [{}]), reduce=False
    ).all()
    return [
        CaseReminderHandler.wrap(reminder_doc)
        for reminder_doc in iter_docs(db, [r["id"] for r in reminder_rules])
        if (
            reminder_doc.get("active", True)
            and reminder_doc.get("reminder_type", REMINDER_TYPE_DEFAULT) != REMINDER_TYPE_KEYWORD_INITIATED
        )
    ]
开发者ID:johan--,项目名称:commcare-hq,代码行数:16,代码来源:utils.py

示例7: scheduled_reminders

def scheduled_reminders(request, domain, template="reminders/partial/scheduled_reminders.html"):
    reminders = CaseReminderHandler.get_all_reminders(domain)
    dates = []
    now = datetime.utcnow()
    today = now.date()
    if reminders:
        start_date = reminders[0].next_fire.date()
        if today < start_date:
            start_date = today
        end_date = reminders[-1].next_fire.date()
    else:
        start_date = end_date = today
    # make sure start date is a Monday and enddate is a Sunday
    start_date -= timedelta(days=start_date.weekday())
    end_date += timedelta(days=6-end_date.weekday())
    while start_date <= end_date:
        dates.append(start_date)
        start_date += timedelta(days=1)

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

示例8: case_changed

def case_changed(self, domain, case_id):
    try:
        handler_ids = CaseReminderHandler.get_handler_ids(domain, reminder_type_filter=REMINDER_TYPE_DEFAULT)
        if handler_ids:
            _case_changed(case_id, handler_ids)
    except Exception as e:
        self.retry(exc=e)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:7,代码来源:tasks.py

示例9: setUp

    def setUp(self):
        super(StartConditionReminderTestCase, self).setUp()
        self.domain = self.domain_obj.name
        self.user = CommCareUser.create(self.domain, 'chw.bob5', 'abc', phone_number='99912345')

        self.handler1 = (CaseReminderHandler.create(self.domain, 'test')
            .set_case_criteria_start_condition('case_type_a', 'start_sending1',
                MATCH_REGEX, '^(ok|\d\d\d\d-\d\d-\d\d)')
            .set_case_criteria_start_date(start_date='start_sending1', start_offset=1)
            .set_last_submitting_user_recipient()
            .set_sms_content_type('en')
            .set_schedule_manually(
                EVENT_AS_OFFSET,
                3,
                [
                    CaseReminderEvent(
                        day_num=0,
                        fire_time=time(0, 0),
                        message={'en': 'Message1'},
                        callback_timeout_intervals=[]
                    ),
                ])
            .set_stop_condition(stop_case_property='stop_sending1')
            .set_advanced_options(use_today_if_start_date_is_blank=True))
        self.handler1.save()
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:25,代码来源:test_send_reminders.py

示例10: rule_progress

def rule_progress(request, domain):
    client = get_redis_client()
    handlers = CaseReminderHandler.get_handlers(domain,
        reminder_type_filter=REMINDER_TYPE_DEFAULT)

    response = {}
    for handler in handlers:
        info = {}
        if handler.locked:
            info['complete'] = False
            current = None
            total = None

            try:
                current = client.get('reminder-rule-processing-current-%s' % handler._id)
                total = client.get('reminder-rule-processing-total-%s' % handler._id)
            except:
                continue

            info['current'] = int_or_none(current)
            info['total'] = int_or_none(total)
        else:
            info['complete'] = True

        response[handler._id] = info

    return HttpResponse(json.dumps(response))
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:27,代码来源:views.py

示例11: clean

    def clean(self):
        cleaned_data = self.cleaned_data
        sm = cleaned_data["share_multimedia"]
        license = cleaned_data["license"]
        app_ids = self._get_apps_to_publish()

        if sm and license not in self.dom.most_restrictive_licenses(apps_to_check=app_ids):
            license_choices = [LICENSES[l] for l in self.dom.most_restrictive_licenses(apps_to_check=app_ids)]
            msg = render_to_string('domain/partials/restrictive_license.html', {'licenses': license_choices})
            self._errors["license"] = self.error_class([msg])

            del cleaned_data["license"]

        sr = cleaned_data["share_reminders"]
        if sr:  # check that the forms referenced by the events in each reminders exist in the project
            referenced_forms = CaseReminderHandler.get_referenced_forms(domain=self.dom.name)
            if referenced_forms:
                apps = [Application.get(app_id) for app_id in app_ids]
                app_forms = [f.unique_id for forms in [app.get_forms() for app in apps] for f in forms]
                nonexistent_forms = filter(lambda f: f not in app_forms, referenced_forms)
                nonexistent_forms = [FormBase.get_form(f) for f in nonexistent_forms]
                if nonexistent_forms:
                    msg = """
                        Your reminders reference forms that are not being published.
                        Make sure the following forms are being published: %s
                    """ % str([f.default_name() for f in nonexistent_forms]).strip('[]')
                    self._errors["share_reminders"] = self.error_class([msg])

        return cleaned_data
开发者ID:thedevelopermw,项目名称:commcare-hq,代码行数:29,代码来源:forms.py

示例12: add_reminder

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,代码行数:47,代码来源:views.py

示例13: reminder_handler

 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,代码行数:8,代码来源:views.py

示例14: domain_has_active_reminders

 def domain_has_active_reminders(self, domain):
     for handler in CaseReminderHandler.get_handlers(
         domain.name,
         reminder_type_filter=REMINDER_TYPE_DEFAULT
     ):
         if handler.active:
             return True
     return False
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:8,代码来源:find_unsubscribed_projects_with_reminders.py

示例15: page_context

    def page_context(self):
        page_context = super(ScheduledRemindersCalendarView, self).page_context
        timezone = Domain.get_by_name(self.domain).get_default_timezone()
        reminders = CaseReminderHandler.get_all_reminders(self.domain)
        dates = []
        now = datetime.utcnow()
        timezone_now = datetime.now(timezone)
        today = timezone_now.date()

        def adjust_next_fire_to_timezone(reminder_utc):
            return ServerTime(reminder_utc.next_fire).user_time(timezone).done()

        if reminders:
            start_date = adjust_next_fire_to_timezone(reminders[0]).date()
            if today < start_date:
                start_date = today
            end_date = adjust_next_fire_to_timezone(reminders[-1]).date()
        else:
            start_date = end_date = today
        # make sure start date is a Monday and enddate is a Sunday
        start_date -= timedelta(days=start_date.weekday())
        end_date += timedelta(days=6 - end_date.weekday())
        while start_date <= end_date:
            dates.append(start_date)
            start_date += timedelta(days=1)

        reminder_data = []
        for reminder in reminders:
            handler = reminder.handler
            recipient = reminder.recipient
            recipient_desc = get_recipient_name(recipient)
            case = reminder.case

            reminder_data.append(
                {
                    "handler_name": handler.nickname,
                    "next_fire": adjust_next_fire_to_timezone(reminder),
                    "recipient_desc": recipient_desc,
                    "recipient_type": handler.recipient,
                    "case_id": case.case_id if case is not None else None,
                    "case_name": case.name if case is not None else None,
                }
            )

        page_context.update(
            {
                "domain": self.domain,
                "reminder_data": reminder_data,
                "dates": dates,
                "today": today,
                "now": now,
                "timezone": timezone,
                "timezone_now": timezone_now,
            }
        )
        return page_context
开发者ID:dimagi,项目名称:commcare-hq,代码行数:56,代码来源:views.py


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