本文整理汇总了Python中corehq.apps.app_manager.xform.XForm.render方法的典型用法代码示例。如果您正苦于以下问题:Python XForm.render方法的具体用法?Python XForm.render怎么用?Python XForm.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.app_manager.xform.XForm
的用法示例。
在下文中一共展示了XForm.render方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_xmlns_on_form
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import render [as 别名]
def set_xmlns_on_form(form_id, xmlns, app_build, log_file, dry_run):
"""
Set the xmlns on a form and all the corresponding forms in the saved builds
that are copies of app.
(form is an app_manager.models.Form)
"""
try:
form_in_build = app_build.get_form(form_id)
except FormNotFoundException:
return
if form_in_build.xmlns == "undefined" or form_in_build.source.count('xmlns="undefined"') > 0:
if form_in_build.xmlns != "undefined":
assert form_in_build.xmlns == xmlns
xml = form_in_build.source
wrapped_xml = XForm(xml)
data = wrapped_xml.data_node.render().decode('utf-8')
data = data.replace("undefined", xmlns, 1)
wrapped_xml.instance_node.remove(wrapped_xml.data_node.xml)
wrapped_xml.instance_node.append(parse_xml(data))
new_xml = wrapped_xml.render().decode('utf-8')
form_in_build.source = new_xml
form_in_build.form_migrated_from_undefined_xmlns = datetime.utcnow()
log_file.write(
"New xmlns for form {form_id} in app {app_build._id} is {new_xmlns}\n".format(
form_id=form_id,
app_build=app_build,
new_xmlns=xmlns
))
if not dry_run:
app_build.save() # Magic happens on save
示例2: save_xform
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import render [as 别名]
def save_xform(app, form, xml):
try:
xform = XForm(xml)
except XFormError:
pass
else:
duplicates = app.get_xmlns_map()[xform.data_node.tag_xmlns]
for duplicate in duplicates:
if form == duplicate:
continue
else:
data = xform.data_node.render()
xmlns = "http://openrosa.org/formdesigner/%s" % form.get_unique_id()
data = data.replace(xform.data_node.tag_xmlns, xmlns, 1)
xform.instance_node.remove(xform.data_node.xml)
xform.instance_node.append(parse_xml(data))
xml = xform.render()
break
form.source = xml
示例3: test_strip_ignore_retain
# 需要导入模块: from corehq.apps.app_manager.xform import XForm [as 别名]
# 或者: from corehq.apps.app_manager.xform.XForm import render [as 别名]
def test_strip_ignore_retain(self):
before = self.get_xml("ignore_retain")
after = self.get_xml("ignore_retain_stripped")
xform = XForm(before)
xform.strip_vellum_ns_attributes()
self.assertXmlEqual(xform.render(), after)