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


Python models.CallLog类代码示例

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


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

示例1: get_data

def get_data(ids):
    """
    returns the data in the format:
    {
        '2015-03': {
            'domain1': {
                'KOOKOO': {'calls': 40, 'minutes': 45}
            },
            'domain2': {
                'KOOKOO': {'calls': 20, 'minutes': 25}
                'TELERIVET': {'calls': 5, 'minutes': 0}
            }
        }
    }
    """
    data = {}
    for doc in iter_docs(CallLog.get_db(), ids):
        call = CallLog.wrap(doc)
        month_data = get_month_data(data, call.date)
        domain_data = get_domain_data(month_data, call.domain)
        backend_api = get_backend_api(call)
        backend_data = get_backend_data(domain_data, backend_api)
        backend_data['calls'] += 1
        duration = (call.duration or 0) / 60.0
        duration = int(ceil(duration))
        backend_data['minutes'] += duration
    return data
开发者ID:aristide,项目名称:commcare-hq,代码行数:27,代码来源:ivr_usage.py

示例2: testCallSync

    def testCallSync(self):
        self.deleteAllLogs()
        self.assertEqual(self.getCallLogCount(), 0)
        self.assertEqual(self.getCallCount(), 0)

        # Test Create
        call = Call()
        self.setRandomCallValues(call)
        call.save()

        sleep(1)
        self.assertEqual(self.getCallLogCount(), 1)
        self.assertEqual(self.getCallCount(), 1)

        calllog = CallLog.get(call.couch_id)
        self.checkFieldValues(calllog, call, Call._migration_get_fields())
        self.assertTrue(CallLog.get_db().get_rev(calllog._id).startswith('2-'))

        # Test Update
        self.setRandomCallValues(call)
        call.save()

        sleep(1)
        self.assertEqual(self.getCallLogCount(), 1)
        self.assertEqual(self.getCallCount(), 1)
        callog = CallLog.get(call.couch_id)
        self.checkFieldValues(callog, call, Call._migration_get_fields())
        self.assertTrue(CallLog.get_db().get_rev(callog._id).startswith('3-'))
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:28,代码来源:migration.py

示例3: test_401_response

    def test_401_response(self):
        start_count = CallLog.count_by_domain(self.domain)

        response = Client().post('/twilio/ivr/xxxxx', {
            'From': self.phone_number,
            'CallSid': 'xyz',
        })
        self.assertEqual(response.status_code, 401)

        end_count = CallLog.count_by_domain(self.domain)
        self.assertEqual(start_count, end_count)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:11,代码来源:test_log_call.py

示例4: test_log_call

    def test_log_call(self):
        if self.__class__ == LogCallTestCase:
            # The test runner picks up this base class too, but we only
            # want to run the test on subclasses.
            return

        self.assertEqual(CallLog.count_by_domain(self.domain), 0)
        response = self.simulate_inbound_call(self.phone_number)
        self.check_response(response)
        self.assertEqual(CallLog.count_by_domain(self.domain), 1)

        call = CallLog.by_domain_asc(self.domain).all()[0]
        self.assertEqual(call.couch_recipient_doc_type, 'CommCareCase')
        self.assertEqual(call.couch_recipient, self.case.get_id)
        self.assertEqual(call.direction, INCOMING)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:15,代码来源:util.py

示例5: ivr_finished

def ivr_finished(request):
    # Retrieve all parameters
    status = request.POST.get("status", None)
    start_time = request.POST.get("start_time", None)
    caller_id = request.POST.get("caller_id", None)
    phone_no = request.POST.get("phone_no", None)
    sid = request.POST.get("sid", "")
    duration = request.POST.get("duration", None)
    ringing_time = request.POST.get("ringing_time", None)
    status_details = request.POST.get("status_details", None)
    
    gateway_session_id = "KOOKOO-" + sid

    with CriticalSection([gateway_session_id]):
        call_log_entry = CallLog.view("sms/call_by_session",
                                      startkey=[gateway_session_id, {}],
                                      endkey=[gateway_session_id],
                                      descending=True,
                                      include_docs=True,
                                      limit=1).one()
        if call_log_entry is not None:
            try:
                duration = int(duration)
            except Exception:
                duration = None
            call_log_entry.answered = (status == "answered")
            call_log_entry.duration = duration
            call_log_entry.save()
    
    return HttpResponse("")
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:30,代码来源:views.py

示例6: incoming

def incoming(phone_number, backend_module, gateway_session_id, ivr_event, input_data=None,
        duration=None):
    """
    The main entry point for all incoming IVR requests.
    """
    call_log_entry = CallLog.get_call_by_gateway_session_id(gateway_session_id)
    logged_subevent = None
    if call_log_entry and call_log_entry.messaging_subevent_id:
        logged_subevent = MessagingSubEvent.objects.get(
            pk=call_log_entry.messaging_subevent_id)

    if call_log_entry:
        add_metadata(call_log_entry, duration)

    if call_log_entry and call_log_entry.form_unique_id is None:
        # If this request is for a call with no form,
        # then just short circuit everything and hang up
        return hang_up_response(gateway_session_id, backend_module=backend_module)

    if call_log_entry and backend_module:
        return handle_known_call_session(call_log_entry, backend_module, ivr_event,
            input_data=input_data, logged_subevent=logged_subevent)
    else:
        if not call_log_entry:
            log_call(phone_number, gateway_session_id, backend_module=backend_module)
        return hang_up_response(gateway_session_id, backend_module=backend_module)
开发者ID:sheelio,项目名称:commcare-hq,代码行数:26,代码来源:api.py

示例7: fire_ivr_survey_event

def fire_ivr_survey_event(reminder, handler, recipients, verified_numbers):
    if handler.recipient == RECIPIENT_CASE:
        # If there are no recipients, just move to the next reminder event
        if len(recipients) == 0:
            return True
        
        # If last_fired is None, it means that the reminder fired for the first time on a timeout interval. So we can
        # skip the lookup for the answered call since no call went out yet.
        if reminder.last_fired is not None and reminder.callback_try_count > 0 and CallLog.answered_call_exists(recipients[0].doc_type, recipients[0].get_id, reminder.last_fired):
            reminder.skip_remaining_timeouts = True
            return True
        verified_number = verified_numbers[recipients[0].get_id]
        if verified_number is not None:
            if initiate_outbound_call(verified_number, reminder.current_event.form_unique_id, handler.submit_partial_forms, handler.include_case_side_effects, handler.max_question_retries):
                return True
            else:
                reminder = CaseReminder.get(reminder._id)
                reminder.error_retry_count += 1
                if reminder.error_retry_count > getattr(settings, "IVR_OUTBOUND_RETRIES", DEFAULT_OUTBOUND_RETRIES):
                    return True
                else:
                    reminder.next_fire += timedelta(minutes=getattr(settings, "IVR_OUTBOUND_RETRY_INTERVAL", DEFAULT_OUTBOUND_RETRY_INTERVAL))
                    reminder.save()
                    return False
        else:
            raise_error(reminder, ERROR_NO_VERIFIED_NUMBER)
            return False
    else:
        # TODO: Implement ivr survey for RECIPIENT_USER, RECIPIENT_OWNER, and RECIPIENT_SURVEY_SAMPLE
        return False
开发者ID:pawelreise,项目名称:commcare-hq,代码行数:30,代码来源:event_handlers.py

示例8: ivr_finished

def ivr_finished(request):
    """
    Kookoo invokes this view after a call is finished (whether answered or not)
    with status and some statistics.
    Point Kookoo's 'callback_url' parameter here.
    """
    # Retrieve all parameters
    status = request.POST.get("status", None)
    start_time = request.POST.get("start_time", None)
    caller_id = request.POST.get("caller_id", None)
    phone_no = request.POST.get("phone_no", None)
    sid = request.POST.get("sid", "")
    duration = request.POST.get("duration", None)
    ringing_time = request.POST.get("ringing_time", None)
    status_details = request.POST.get("status_details", None)
    
    gateway_session_id = "KOOKOO-" + sid

    with CriticalSection([gateway_session_id], timeout=300):
        call_log_entry = CallLog.view("sms/call_by_session",
                                      startkey=[gateway_session_id, {}],
                                      endkey=[gateway_session_id],
                                      descending=True,
                                      include_docs=True,
                                      limit=1).one()
        if call_log_entry is not None:
            try:
                duration = int(duration)
            except Exception:
                duration = None
            call_log_entry.answered = (status == "answered")
            call_log_entry.duration = duration
            call_log_entry.save()
    
    return HttpResponse("")
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:35,代码来源:views.py

示例9: get_call_couch_ids

 def get_call_couch_ids(self):
     result = CallLog.view(
         'sms/by_domain',
         include_docs=False,
         reduce=False,
     ).all()
     return [row['id'] for row in result if row['key'][1] == 'CallLog']
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:7,代码来源:migrate_logs_to_sql.py

示例10: initiate_outbound_call

def initiate_outbound_call(verified_number, form_unique_id, submit_partial_form, include_case_side_effects, max_question_retries):
    call_log_entry = CallLog(
        couch_recipient_doc_type = verified_number.owner_doc_type,
        couch_recipient          = verified_number.owner_id,
        phone_number             = "+" + str(verified_number.phone_number),
        direction                = OUTGOING,
        date                     = datetime.utcnow(),
        domain                   = verified_number.domain,
        form_unique_id           = form_unique_id,
        submit_partial_form      = submit_partial_form,
        include_case_side_effects = include_case_side_effects,
        max_question_retries     = max_question_retries,
        current_question_retry_count = 0,
    )
    backend = verified_number.ivr_backend
    kwargs = backend.get_cleaned_outbound_params()
    module = __import__(backend.outbound_module, fromlist=["initiate_outbound_call"])
    call_log_entry.backend_api = module.API_ID
    call_log_entry.save()
    return module.initiate_outbound_call(call_log_entry, **kwargs)
开发者ID:NoahCarnahan,项目名称:commcare-hq,代码行数:20,代码来源:api.py

示例11: getCallLogCount

 def getCallLogCount(self):
     result = CallLog.view(
         'sms/by_domain',
         startkey=[self.domain, 'CallLog'],
         endkey=[self.domain, 'CallLog', {}],
         include_docs=False,
         reduce=True,
     ).all()
     if result:
         return result[0]['value']
     return 0
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:11,代码来源:migration.py

示例12: get_data

def get_data(ids, timezone=None):
    """
    returns the data in the format:
    {
        '2015-03': {
            'domain1': {
                'KOOKOO': {
                    'I': {'calls': 2, 'minutes': 3},
                    'O': {'calls': 40, 'minutes': 45},
                    '?': {'calls': 0, 'minutes': 0},
                 },
            },
            'domain2': {
                'KOOKOO': {
                    'I': {'calls': 1, 'minutes': 1},
                    'O': {'calls': 20, 'minutes': 25},
                    '?': {'calls': 0, 'minutes': 0},
                 },
                'TELERIVET': {
                    'I': {'calls': 10, 'minutes': 0},
                    'O': {'calls': 0, 'minutes': 0},
                    '?': {'calls': 0, 'minutes': 0},
                 },
            }
        }
    }
    """
    data = {}
    for doc in iter_docs(CallLog.get_db(), ids):
        call = CallLog.wrap(doc)
        date = get_naive_user_datetime(call.date, timezone=timezone)
        month_data = get_month_data(data, date)
        domain_data = get_domain_data(month_data, call.domain)
        backend_api = get_backend_api(call)
        backend_data = get_backend_data(domain_data, backend_api)
        direction = get_direction(call)
        backend_data[direction]['calls'] += 1
        duration = (call.duration or 0) / 60.0
        duration = int(ceil(duration))
        backend_data[direction]['minutes'] += duration
    return data
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:41,代码来源:ivr_usage.py

示例13: get_last_outbound_call

 def get_last_outbound_call(self, contact):
     # Not clear why this should be necessary, but without it the latest
     # call may not be returned
     sleep(0.25)
     call = CallLog.view("sms/by_recipient",
         startkey=[contact.doc_type, contact._id, "CallLog", "O", {}],
         endkey=[contact.doc_type, contact._id, "CallLog", "O"],
         descending=True,
         include_docs=True,
         reduce=False,
     ).first()
     return call
开发者ID:sheelio,项目名称:commcare-hq,代码行数:12,代码来源:util.py

示例14: incoming

def incoming(phone_number, backend_api):
    cleaned_number = phone_number
    if len(cleaned_number) > 0 and cleaned_number[0] == "+":
        cleaned_number = cleaned_number[1:]
    
    # Try to look up the verified number entry
    v = VerifiedNumber.view("sms/verified_number_by_number",
        key=cleaned_number,
        include_docs=True
    ).one()
    
    # If none was found, try to match only the last digits of numbers in the database
    if v is None:
        v = VerifiedNumber.view("sms/verified_number_by_suffix",
            key=cleaned_number,
            include_docs=True
        ).one()
    
    # Save the call entry
    msg = CallLog(
        phone_number    = cleaned_number,
        direction       = INCOMING,
        date            = datetime.utcnow(),
        backend_api     = backend_api
    )
    if v is not None:
        msg.domain = v.domain
        msg.couch_recipient_doc_type = v.owner_doc_type
        msg.couch_recipient = v.owner_id
    msg.save()
开发者ID:mchampanis,项目名称:core-hq,代码行数:30,代码来源:api.py

示例15: ivr_in

def ivr_in(request):
    """
    Handles tropo call requests
    """
    if request.method == "POST":
        data = json.loads(request.body)
        phone_number = data["session"]["from"]["id"]
        # TODO: Implement tropo as an ivr backend. In the meantime, just log the call.

        if phone_number:
            cleaned_number = strip_plus(phone_number)
            v = VerifiedNumber.by_extensive_search(cleaned_number)
        else:
            v = None

        # Save the call entry
        msg = CallLog(
            phone_number=cleaned_number,
            direction=INCOMING,
            date=datetime.utcnow(),
            backend_api=SQLTropoBackend.get_api_id(),
        )
        if v is not None:
            msg.domain = v.domain
            msg.couch_recipient_doc_type = v.owner_doc_type
            msg.couch_recipient = v.owner_id
        msg.save()

        t = Tropo()
        t.reject()
        return HttpResponse(t.RenderJson())
    else:
        return HttpResponseBadRequest("Bad Request")
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:33,代码来源:views.py


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