本文整理汇总了Python中corehq.form_processor.interfaces.processor.FormProcessorInterface.new_xform方法的典型用法代码示例。如果您正苦于以下问题:Python FormProcessorInterface.new_xform方法的具体用法?Python FormProcessorInterface.new_xform怎么用?Python FormProcessorInterface.new_xform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.form_processor.interfaces.processor.FormProcessorInterface
的用法示例。
在下文中一共展示了FormProcessorInterface.new_xform方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_simple_wrapped_form
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import new_xform [as 别名]
def get_simple_wrapped_form(form_id, case_id=None, metadata=None, save=True):
from corehq.form_processor.interfaces.processor import FormProcessorInterface
xml = get_simple_form_xml(form_id=form_id, metadata=metadata)
form_json = convert_xform_to_json(xml)
interface = FormProcessorInterface(domain=metadata.domain)
wrapped_form = interface.new_xform(form_json)
wrapped_form.domain = metadata.domain
interface.store_attachments(wrapped_form, [Attachment('form.xml', xml, 'text/xml')])
if save:
interface.save_processed_models([wrapped_form])
return wrapped_form
示例2: get_simple_wrapped_form
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import new_xform [as 别名]
def get_simple_wrapped_form(form_id, metadata=None, save=True, simple_form=SIMPLE_FORM):
from corehq.form_processor.interfaces.processor import FormProcessorInterface
metadata = metadata or TestFormMetadata()
xml = get_simple_form_xml(form_id=form_id, metadata=metadata, simple_form=simple_form)
form_json = convert_xform_to_json(xml)
interface = FormProcessorInterface(domain=metadata.domain)
wrapped_form = interface.new_xform(form_json)
wrapped_form.domain = metadata.domain
wrapped_form.received_on = metadata.received_on
interface.store_attachments(wrapped_form, [Attachment('form.xml', xml, 'text/xml')])
if save:
interface.save_processed_models([wrapped_form])
return wrapped_form
示例3: _migrate_form
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import new_xform [as 别名]
def _migrate_form(domain, couch_form):
"""
This copies the couch form into a new sql form but does not save it.
See form_processor.parsers.form._create_new_xform
and SubmissionPost._set_submission_properties for what this should do.
"""
interface = FormProcessorInterface(domain)
form_data = couch_form.form
with force_phone_timezones_should_be_processed():
adjust_datetimes(form_data)
sql_form = interface.new_xform(form_data)
sql_form.form_id = couch_form.form_id # some legacy forms don't have ID's so are assigned random ones
if sql_form.xmlns is None:
sql_form.xmlns = ''
return _copy_form_properties(domain, sql_form, couch_form)
示例4: _create_new_xform
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import new_xform [as 别名]
def _create_new_xform(domain, instance_xml, attachments=None):
"""
create but do not save an XFormInstance from an xform payload (xml_string)
optionally set the doc _id to a predefined value (_id)
return doc _id of the created doc
`process` is transformation to apply to the form right before saving
This is to avoid having to save multiple times
If xml_string is bad xml
- raise couchforms.XMLSyntaxError
:param domain:
"""
from corehq.form_processor.interfaces.processor import FormProcessorInterface
interface = FormProcessorInterface(domain)
assert attachments is not None
form_data = convert_xform_to_json(instance_xml)
if not form_data.get('@xmlns'):
raise MissingXMLNSError("Form is missing a required field: XMLNS")
adjust_datetimes(form_data)
xform = interface.new_xform(form_data)
xform.domain = domain
# Maps all attachments to uniform format and adds form.xml to list before storing
attachments = map(
lambda a: Attachment(name=a[0], raw_content=a[1], content_type=a[1].content_type),
attachments.items()
)
attachments.append(Attachment(name='form.xml', raw_content=instance_xml, content_type='text/xml'))
interface.store_attachments(xform, attachments)
result = LockedFormProcessingResult(xform)
with ReleaseOnError(result.lock):
if interface.is_duplicate(xform.form_id):
raise DuplicateError(xform)
return result
示例5: get_form_ready_to_save
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import new_xform [as 别名]
def get_form_ready_to_save(metadata, is_db_test=False):
from corehq.form_processor.parsers.form import process_xform_xml
from corehq.form_processor.utils import get_simple_form_xml, convert_xform_to_json
from corehq.form_processor.interfaces.processor import FormProcessorInterface
from corehq.form_processor.models import Attachment
assert metadata is not None
metadata.domain = metadata.domain or uuid.uuid4().hex
form_id = uuid.uuid4().hex
form_xml = get_simple_form_xml(form_id=form_id, metadata=metadata)
if is_db_test:
wrapped_form = process_xform_xml(metadata.domain, form_xml).submitted_form
else:
interface = FormProcessorInterface(domain=metadata.domain)
form_json = convert_xform_to_json(form_xml)
wrapped_form = interface.new_xform(form_json)
wrapped_form.domain = metadata.domain
interface.store_attachments(wrapped_form, [
Attachment(name='form.xml', raw_content=form_xml, content_type='text/xml')
])
wrapped_form.received_on = metadata.received_on
wrapped_form.app_id = metadata.app_id
return wrapped_form