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


Python SQLXFormsSession.by_session_id方法代码示例

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


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

示例1: test_get_by_session_id

# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import by_session_id [as 别名]
 def test_get_by_session_id(self):
     session_id = uuid.uuid4().hex
     sql_session = SQLXFormsSession.objects.create(
         session_id=session_id,
         start_time=datetime.utcnow(),
         modified_time=datetime.utcnow(),
     )
     self.assertEqual(sql_session.pk, SQLXFormsSession.by_session_id(session_id).pk)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:10,代码来源:test_sql_session.py

示例2: handle_sms_form_complete

# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import by_session_id [as 别名]
def handle_sms_form_complete(sender, session_id, form, **kwargs):
    from corehq.apps.smsforms.models import SQLXFormsSession
    session = SQLXFormsSession.by_session_id(session_id)
    if session:
        resp = submit_form_locally(form, session.domain, app_id=session.app_id)
        xform_id = resp['X-CommCareHQ-FormID']
        session.end(completed=True)
        session.submission_id = xform_id
        session.save()
        
        xform = XFormInstance.get(xform_id)
        xform.survey_incentive = session.survey_incentive
        xform.save()
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:15,代码来源:signals.py

示例3: handle_due_survey_action

# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import by_session_id [as 别名]
def handle_due_survey_action(domain, contact_id, session_id):
    with critical_section_for_smsforms_sessions(contact_id):
        session = SQLXFormsSession.by_session_id(session_id)
        if (
            not session
            or not session.session_is_open
            or session.current_action_due > utcnow()
        ):
            return

        if session_is_stale(session):
            # If a session is having some unrecoverable errors that aren't benefitting from
            # being retried, those errors should show up in sentry log and the fix should
            # be dealt with. In terms of the current session itself, we just close it out
            # to allow new sessions to start.
            session.mark_completed(False)
            session.save()
            return

        if session.current_action_is_a_reminder:
            # Resend the current question in the open survey to the contact
            p = PhoneNumber.get_phone_number_for_owner(session.connection_id, session.phone_number)
            if p:
                metadata = MessageMetadata(
                    workflow=session.workflow,
                    xforms_session_couch_id=session._id,
                )
                resp = current_question(session.session_id, domain)
                send_sms_to_verified_number(
                    p,
                    resp.event.text_prompt,
                    metadata,
                    logged_subevent=session.related_subevent
                )

            session.move_to_next_action()
            session.save()
        else:
            # Close the session
            session.close()
            session.save()
开发者ID:dimagi,项目名称:commcare-hq,代码行数:43,代码来源:tasks.py

示例4: test_session_is_stale

# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import by_session_id [as 别名]
    def test_session_is_stale(self, utcnow_mock_1, utcnow_mock_2):
        utcnow_mock_2.return_value = datetime(2018, 1, 1, 0, 0)
        session = SQLXFormsSession.create_session_object(
            'test',
            Mock(get_id='contact_id'),
            '+9990001',
            Mock(get_id='app_id'),
            Mock(xmlns='xmlns'),
            expire_after=24 * 60,
            reminder_intervals=[30, 60],
            submit_partially_completed_forms=True,
        )
        session.save()
        self.addCleanup(session.delete)

        utcnow_mock_1.return_value = datetime(2018, 1, 14, 0, 0)
        self.assertFalse(session_is_stale(session))

        utcnow_mock_1.return_value = datetime(2018, 1, 16, 0, 0)
        self.assertTrue(session_is_stale(session))

        handle_due_survey_action('test', 'contact_id', session.session_id)
        session = SQLXFormsSession.by_session_id(session.session_id)
        self.assertFalse(session.session_is_open)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:26,代码来源:test_sql_session.py

示例5: handle_sms_form_complete

# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import by_session_id [as 别名]
def handle_sms_form_complete(sender, session_id, form, **kwargs):
    from corehq.apps.smsforms.models import SQLXFormsSession
    session = SQLXFormsSession.by_session_id(session_id)
    if session:
        process_sms_form_complete(session, form)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:7,代码来源:signals.py

示例6: test_get_by_session_id_not_found

# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import by_session_id [as 别名]
 def test_get_by_session_id_not_found(self):
     self.assertEqual(None, SQLXFormsSession.by_session_id(uuid.uuid4().hex))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:4,代码来源:test_sql_session.py

示例7: test_get_by_session_id

# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import by_session_id [as 别名]
 def test_get_by_session_id(self):
     sql_session = _make_session()
     self.assertEqual(sql_session.pk, SQLXFormsSession.by_session_id(sql_session.session_id).pk)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:5,代码来源:test_sql_session.py


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