本文整理汇总了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)
示例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()
示例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()
示例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)
示例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)
示例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))
示例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)