当前位置: 首页>>代码示例>>Python>>正文


Python FormProcessorInterface.store_attachments方法代码示例

本文整理汇总了Python中corehq.form_processor.interfaces.processor.FormProcessorInterface.store_attachments方法的典型用法代码示例。如果您正苦于以下问题:Python FormProcessorInterface.store_attachments方法的具体用法?Python FormProcessorInterface.store_attachments怎么用?Python FormProcessorInterface.store_attachments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在corehq.form_processor.interfaces.processor.FormProcessorInterface的用法示例。


在下文中一共展示了FormProcessorInterface.store_attachments方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_simple_wrapped_form

# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import store_attachments [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
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:15,代码来源:xform.py

示例2: get_simple_wrapped_form

# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import store_attachments [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
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:17,代码来源:xform.py

示例3: _create_new_xform

# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import store_attachments [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
开发者ID:,项目名称:,代码行数:43,代码来源:

示例4: get_form_ready_to_save

# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import store_attachments [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
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:26,代码来源:test_utils.py


注:本文中的corehq.form_processor.interfaces.processor.FormProcessorInterface.store_attachments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。