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


Python models.SQLXFormsSession类代码示例

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


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

示例1: test_get_open_sms_session_multiple_results

    def test_get_open_sms_session_multiple_results(self):
        domain = uuid.uuid4().hex
        contact = uuid.uuid4().hex
        for i in range(3):
            _make_session(
                domain=domain,
                connection_id=contact,
                end_time=None,
                session_type=XFORMS_SESSION_SMS,
            )

        with self.assertRaises(MultipleResultsFound):
            SQLXFormsSession.get_open_sms_session(domain, contact)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:13,代码来源:test_sql_session.py

示例2: start_smsforms_session

    def start_smsforms_session(self, domain, recipient, case_id, phone_entry_or_number, logged_subevent, workflow,
            app, module, form):
        # Close all currently open sessions
        SQLXFormsSession.close_all_open_sms_sessions(domain, recipient.get_id)

        # Start the new session
        try:
            session, responses = start_session(
                SQLXFormsSession.create_session_object(
                    domain,
                    recipient,
                    (phone_entry_or_number.phone_number
                     if isinstance(phone_entry_or_number, PhoneNumber)
                     else phone_entry_or_number),
                    app,
                    form,
                    expire_after=self.expire_after,
                    reminder_intervals=self.reminder_intervals,
                    submit_partially_completed_forms=self.submit_partially_completed_forms,
                    include_case_updates_in_partial_submissions=self.include_case_updates_in_partial_submissions
                ),
                domain,
                recipient,
                app,
                module,
                form,
                case_id,
            )
        except TouchformsError as e:
            logged_subevent.error(
                MessagingEvent.ERROR_TOUCHFORMS_ERROR,
                additional_error_text=get_formplayer_exception(domain, e)
            )

            if touchforms_error_is_config_error(domain, e):
                # Don't reraise the exception because this means there are configuration
                # issues with the form that need to be fixed. The error is logged in the
                # above lines.
                return None, None

            # Reraise the exception so that the framework retries it again later
            raise
        except:
            logged_subevent.error(MessagingEvent.ERROR_TOUCHFORMS_ERROR)
            # Reraise the exception so that the framework retries it again later
            raise

        session.workflow = workflow
        session.save()

        return session, responses
开发者ID:dimagi,项目名称:commcare-hq,代码行数:51,代码来源:content.py

示例3: test_get_and_close_all_open_sessions

    def test_get_and_close_all_open_sessions(self):
        domain = uuid.uuid4().hex
        contact = uuid.uuid4().hex
        for i in range(3):
            _make_session(
                domain=domain,
                connection_id=contact,
                end_time=None,
                session_type=XFORMS_SESSION_SMS,
            )

        sql_sessions = SQLXFormsSession.get_all_open_sms_sessions(domain, contact)
        self.assertEqual(3, len(sql_sessions))
        SQLXFormsSession.close_all_open_sms_sessions(domain, contact)
        self.assertEqual(0, len(SQLXFormsSession.get_all_open_sms_sessions(domain, contact)))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:15,代码来源:test_sql_session.py

示例4: test_get_single_open_session

 def test_get_single_open_session(self):
     properties = _arbitrary_session_properties(
         end_time=None,
         session_type=XFORMS_SESSION_SMS,
     )
     session = SQLXFormsSession(**properties)
     session.save()
     (mult, session) = get_single_open_session_or_close_multiple(
         session.domain, session.connection_id
     )
     self.assertEqual(False, mult)
     [session_back] = SQLXFormsSession.get_all_open_sms_sessions(
         session.domain, session.connection_id
     )
     self.assertEqual(session._id, session_back.couch_id)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:15,代码来源:test_sql_session.py

示例5: test_get_by_session_id

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

示例6: test_get_all_open_sessions_wrong_type

 def test_get_all_open_sessions_wrong_type(self):
     domain = uuid.uuid4().hex
     contact = uuid.uuid4().hex
     _make_session(
         domain=domain,
         connection_id=contact,
         end_time=None,
         session_type=XFORMS_SESSION_IVR,
     )
     self.assertEqual(0, len(SQLXFormsSession.get_all_open_sms_sessions(domain, contact)))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:10,代码来源:test_sql_session.py

示例7: test_get_all_open_sessions_already_ended

 def test_get_all_open_sessions_already_ended(self):
     domain = uuid.uuid4().hex
     contact = uuid.uuid4().hex
     _make_session(
         domain=domain,
         connection_id=contact,
         end_time=datetime.utcnow(),
         session_type=XFORMS_SESSION_SMS,
     )
     self.assertEqual(0, len(SQLXFormsSession.get_all_open_sms_sessions(domain, contact)))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:10,代码来源:test_sql_session.py

示例8: test_get_all_open_sessions_contact_mismatch

 def test_get_all_open_sessions_contact_mismatch(self):
     domain = uuid.uuid4().hex
     contact = uuid.uuid4().hex
     _make_session(
         domain=domain,
         connection_id='wrong',
         end_time=None,
         session_is_open=True,
         session_type=XFORMS_SESSION_SMS,
     )
     self.assertEqual(0, len(SQLXFormsSession.get_all_open_sms_sessions(domain, contact)))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:11,代码来源:test_sql_session.py

示例9: sms_keyword_handler

def sms_keyword_handler(v, text, msg):
    text = text.strip()
    if text == "":
        return False

    sessions = SQLXFormsSession.get_all_open_sms_sessions(v.domain, v.owner_id)
    text_words = text.upper().split()

    if text.startswith("#"):
        return handle_global_keywords(v, text, msg, text_words, sessions)
    else:
        return handle_domain_keywords(v, text, msg, text_words, sessions)
开发者ID:johan--,项目名称:commcare-hq,代码行数:12,代码来源:keyword.py

示例10: test_get_open_sms_session_one_result

    def test_get_open_sms_session_one_result(self):
        domain = uuid.uuid4().hex
        contact = uuid.uuid4().hex
        new_session = _make_session(
            domain=domain,
            connection_id=contact,
            end_time=None,
            session_type=XFORMS_SESSION_SMS,
        )

        session = SQLXFormsSession.get_open_sms_session(domain, contact)
        self.assertEqual(new_session.session_id, session.session_id)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:12,代码来源:test_sql_session.py

示例11: handle_sms_form_complete

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

示例12: test_get_single_open_session_close_multiple

    def test_get_single_open_session_close_multiple(self):
        domain = uuid.uuid4().hex
        contact = uuid.uuid4().hex
        for i in range(3):
            _make_session(
                domain=domain,
                connection_id=contact,
                end_time=None,
                session_type=XFORMS_SESSION_SMS,
            )

        (mult, session) = get_single_open_session_or_close_multiple(domain, contact)
        self.assertEqual(True, mult)
        self.assertEqual(None, session)
        self.assertEqual(0, len(SQLXFormsSession.get_all_open_sms_sessions(domain, contact)))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:15,代码来源:test_sql_session.py

示例13: test_session_is_stale

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

示例14: get_single_open_session_or_close_multiple

def get_single_open_session_or_close_multiple(domain, contact_id):
    """
    Retrieves the current open SQLXFormsSession for the given contact.
    If multiple sessions are open, it closes all of them and returns
    None for the session.

    The return value is a tuple of (multiple, session), where multiple
    is True if there were multiple sessions, and session is the session if
    there was a single open session available.
    """
    sessions = SQLXFormsSession.get_all_open_sms_sessions(domain, contact_id)
    count = sessions.count()
    if count > 1:
        for session in sessions:
            session.end(False)
            session.save()
        return (True, None)

    session = sessions[0] if count == 1 else None
    return (False, session)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:20,代码来源:form_session.py

示例15: handle_due_survey_action

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


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