本文整理汇总了Python中corehq.apps.app_manager.xform.XForm.resolve_path方法的典型用法代码示例。如果您正苦于以下问题:Python XForm.resolve_path方法的具体用法?Python XForm.resolve_path怎么用?Python XForm.resolve_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.app_manager.xform.XForm
的用法示例。
在下文中一共展示了XForm.resolve_path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fix_user_props_copy
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import resolve_path [as 别名]
def fix_user_props_copy(app, module, form, form_ix, preloads, dry):
updated = False
xform = XForm(form.source)
refs = {xform.resolve_path(ref): prop for ref, prop in six.iteritems(preloads)}
for node in xform.model_node.findall("{f}setvalue"):
if (node.attrib.get('ref') in refs
and node.attrib.get('event') == "xforms-ready"):
ref = node.attrib.get('ref')
value = (node.attrib.get('value') or "").replace(" ", "")
prop = refs[ref]
userprop = "#user/" + prop
if value == get_bad_usercase_path(module, form, prop):
logger.info("%s setvalue %s -> %s", form_ix, userprop, ref)
node.attrib["value"] = USERPROP_PREFIX + prop
updated = True
elif value != USERPROP_PREFIX + prop:
logger.warn("%s %s has unexpected value: %r (not %s)",
form_ix, ref, value, userprop)
if updated:
if dry:
logger.info("updated setvalues in XML:\n%s", "\n".join(line
for line in ET.tostring(xform.xml).split("\n")
if "setvalue" in line))
else:
save_xform(app, form, ET.tostring(xform.xml))
return updated
示例2: fix_user_props_caseref
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import resolve_path [as 别名]
def fix_user_props_caseref(app, module, form, form_ix, dry):
updated = False
xform = XForm(form.source)
refs = {xform.resolve_path(ref): vals
for ref, vals in six.iteritems(form.case_references.load)
if any(v.startswith("#user/") for v in vals)}
ref_warnings = []
for node in xform.model_node.findall("{f}setvalue"):
if (node.attrib.get('ref') in refs
and node.attrib.get('event') == "xforms-ready"):
ref = node.attrib.get('ref')
ref_values = refs[ref]
if len(ref_values) != 1:
ref_warnings.append((ref, " ".join(ref_values)))
continue
value = (node.attrib.get('value') or "").replace(" ", "")
userprop = ref_values[0]
assert userprop.startswith("#user/"), (ref, userprop)
prop = userprop[len("#user/"):]
if value == get_bad_usercase_path(module, form, prop):
logger.info("%s setvalue %s -> %s", form_ix, userprop, ref)
node.attrib["value"] = USERPROP_PREFIX + prop
updated = True
elif value != (USERPROP_PREFIX + prop).replace(" ", ""):
ref_warnings.append((ref, "%r (%s)" % (value, userprop)))
if updated:
if dry:
logger.info("updated setvalues in XML:\n%s", "\n".join(line
for line in ET.tostring(xform.xml).split("\n")
if "setvalue" in line))
else:
save_xform(app, form, ET.tostring(xform.xml))
if ref_warnings:
for ref, ref_values in ref_warnings:
logger.warning("%s %s has unexpected #user refs: %s",
form_ix, ref, ref_values)
return updated