本文整理汇总了Python中corehq.apps.app_manager.xform.XForm.add_case_preloads方法的典型用法代码示例。如果您正苦于以下问题:Python XForm.add_case_preloads方法的具体用法?Python XForm.add_case_preloads怎么用?Python XForm.add_case_preloads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.app_manager.xform.XForm
的用法示例。
在下文中一共展示了XForm.add_case_preloads方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: migrate_preloads
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import add_case_preloads [as 别名]
def migrate_preloads(app, form, preload_items, form_ix, dry):
xform = XForm(form.source)
if form.case_references:
load_refs = form.case_references.load
else:
load_refs = {}
form.case_references = CaseReferences(load=load_refs)
for hashtag, preloads in preload_items:
if hashtag == "#case/":
xform.add_case_preloads(preloads)
elif hashtag == "#user/":
xform.add_casedb()
for nodeset, prop in preloads.items():
assert '/' not in prop, (app.id, form.unique_id, prop)
xform.add_setvalue(ref=nodeset, value=USERPROP_PREFIX + prop)
else:
raise ValueError("unknown hashtag: " + hashtag)
for nodeset, prop in six.iteritems(preloads):
load_refs.setdefault(nodeset, []).append(hashtag + prop)
logger.info("%s/%s %s setvalue %s = %s",
app.domain, app._id, form_ix, nodeset, hashtag + prop)
if dry:
logger.info("setvalue XML: %s", " ".join(line.strip()
for line in ET.tostring(xform.xml).split("\n")
if "setvalue" in line))
else:
save_xform(app, form, ET.tostring(xform.xml))
示例2: migrate_app
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import add_case_preloads [as 别名]
def migrate_app(self, app_id):
app = Application.get(app_id)
modules = [m for m in app.modules if m.module_type == 'basic']
for module in modules:
forms = [f for f in module.forms if f.doc_type == 'Form']
for form in forms:
preload = form.actions.case_preload.preload
if preload:
xform = XForm(form.source)
xform.add_case_preloads(preload)
save_xform(app, form, ET.tostring(xform.xml))
form.actions.load_from_form = form.actions.case_preload
form.actions.case_preload = PreloadAction()
app.vellum_case_management = True
app.save()