本文整理汇总了Python中corehq.apps.smsforms.models.XFormsSession.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python XFormsSession.wrap方法的具体用法?Python XFormsSession.wrap怎么用?Python XFormsSession.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.smsforms.models.XFormsSession
的用法示例。
在下文中一共展示了XFormsSession.wrap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from corehq.apps.smsforms.models import XFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.XFormsSession import wrap [as 别名]
def handle(self, *args, **options):
db = XFormsSession.get_db()
session_ids = [row['id'] for row in db.view("smsforms/sessions_by_touchforms_id")]
errors = []
for session_doc in iter_docs(db, session_ids):
try:
# Handle the old touchforms session id convention where it was
# always an int
session_id = session_doc.get("session_id", None)
if isinstance(session_id, int):
session_doc["session_id"] = str(session_id)
couch_session = XFormsSession.wrap(session_doc)
sync_sql_session_from_couch_session(couch_session)
except Exception as e:
logging.exception('problem migrating session {}: {}'.format(session_doc['_id'], e))
errors.append(session_doc['_id'])
print 'migrated {} couch sessions. there are now {} in sql'.format(
len(session_ids) - len(errors), SQLXFormsSession.objects.count()
)
if errors:
print 'errors: {}'.format(', '.join(errors))