本文整理汇总了Python中corehq.apps.casegroups.models.CommCareCaseGroup.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python CommCareCaseGroup.wrap方法的具体用法?Python CommCareCaseGroup.wrap怎么用?Python CommCareCaseGroup.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.casegroups.models.CommCareCaseGroup
的用法示例。
在下文中一共展示了CommCareCaseGroup.wrap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from corehq.apps.casegroups.models import CommCareCaseGroup [as 别名]
# 或者: from corehq.apps.casegroups.models.CommCareCaseGroup import wrap [as 别名]
def handle(self, *labels, **options):
existing_samples = CommCareCaseGroup.get_db().view(
'reminders/sample_by_domain',
startkey=[],
endkey=[{}],
include_docs=True
).all()
print "Found %d SurveySamples to migrate..." % len(existing_samples)
print "Migrating"
for sample in existing_samples:
try:
sample_doc = sample["doc"]
sample_doc["timezone"] = sample_doc.get("time_zone")
del sample_doc["time_zone"]
sample_doc["cases"] = sample_doc.get("contacts", [])
del sample_doc["contacts"]
sample_doc["doc_type"] = CommCareCaseGroup.__name__
case_group = CommCareCaseGroup.wrap(sample_doc)
case_group.save()
sys.stdout.write('.')
except Exception:
sys.stdout.write('!')
sys.stdout.flush()
print "\nMigration complete."