本文整理汇总了Python中corehq.apps.smsforms.models.SQLXFormsSession.create_session_object方法的典型用法代码示例。如果您正苦于以下问题:Python SQLXFormsSession.create_session_object方法的具体用法?Python SQLXFormsSession.create_session_object怎么用?Python SQLXFormsSession.create_session_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.smsforms.models.SQLXFormsSession
的用法示例。
在下文中一共展示了SQLXFormsSession.create_session_object方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_smsforms_session
# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import create_session_object [as 别名]
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
示例2: test_move_to_next_action_with_reminders
# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import create_session_object [as 别名]
def test_move_to_next_action_with_reminders(self, utcnow_mock):
utcnow_mock.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]
)
self.assertTrue(session.session_is_open)
self.assertEqual(session.start_time, datetime(2018, 1, 1, 0, 0))
self.assertIsNone(session.end_time)
self.assertEqual(session.current_action_due, datetime(2018, 1, 1, 0, 30))
self.assertTrue(session.current_action_is_a_reminder)
utcnow_mock.return_value = datetime(2018, 1, 1, 0, 31)
session.move_to_next_action()
self.assertTrue(session.session_is_open)
self.assertEqual(session.start_time, datetime(2018, 1, 1, 0, 0))
self.assertIsNone(session.end_time)
self.assertEqual(session.current_action_due, datetime(2018, 1, 1, 1, 30))
self.assertTrue(session.current_action_is_a_reminder)
utcnow_mock.return_value = datetime(2018, 1, 1, 1, 31)
session.move_to_next_action()
self.assertTrue(session.session_is_open)
self.assertEqual(session.start_time, datetime(2018, 1, 1, 0, 0))
self.assertIsNone(session.end_time)
self.assertEqual(session.current_action_due, datetime(2018, 1, 2, 0, 0))
self.assertFalse(session.current_action_is_a_reminder)
utcnow_mock.return_value = datetime(2018, 1, 2, 0, 1)
session.move_to_next_action()
self.assertTrue(session.session_is_open)
self.assertEqual(session.start_time, datetime(2018, 1, 1, 0, 0))
self.assertIsNone(session.end_time)
self.assertEqual(session.current_action_due, datetime(2018, 1, 2, 0, 0))
self.assertFalse(session.current_action_is_a_reminder)
示例3: start_session_for_structured_sms
# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import create_session_object [as 别名]
def start_session_for_structured_sms(domain, contact, phone_number, app, module, form,
case_id, keyword, logged_subevent=None):
"""
Returns (session, responses, error, error_code)
"""
try:
session, responses = start_session(
SQLXFormsSession.create_session_object(
domain,
contact,
phone_number.phone_number,
app,
form,
expire_after=0,
),
domain,
contact,
app,
module,
form,
case_id=case_id,
yield_responses=True
)
if logged_subevent:
logged_subevent.xforms_session_id = session.pk
logged_subevent.save()
return (session, responses, False, None)
except TouchformsError as e:
human_readable_message = get_formplayer_exception(domain, e)
logged_subevent.error(MessagingEvent.ERROR_TOUCHFORMS_ERROR,
additional_error_text=human_readable_message)
if touchforms_error_is_config_error(domain, e):
error_code = MSG_FORM_ERROR
else:
notify_exception(None, message=('Could not process structured sms for'
'contact %s, domain %s, keyword %s' % (contact.get_id, domain, keyword)))
error_code = MSG_TOUCHFORMS_ERROR
return (None, None, True, error_code)
示例4: test_session_is_stale
# 需要导入模块: from corehq.apps.smsforms.models import SQLXFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.SQLXFormsSession import create_session_object [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)