Exemplo n.º 1
0
def _simulate_form_edit():
    existing_form = create_form_for_test(DOMAIN, save=False)
    FormAccessorSQL.save_new_form(existing_form)
    existing_form = FormAccessorSQL.get_form(existing_form.form_id)

    new_form = create_form_for_test(DOMAIN, save=False)
    new_form.form_id = existing_form.form_id

    existing_form, new_form = apply_deprecation(existing_form, new_form)
    assert existing_form.form_id != new_form.form_id
    return existing_form, new_form
Exemplo n.º 2
0
def _simulate_form_edit():
    existing_form = create_form_for_test(DOMAIN, save=False)
    FormAccessorSQL.save_new_form(existing_form)
    existing_form = FormAccessorSQL.get_form(existing_form.form_id)

    new_form = create_form_for_test(DOMAIN, save=False)
    new_form.form_id = existing_form.form_id

    existing_form, new_form = apply_deprecation(existing_form, new_form)
    assert existing_form.form_id != new_form.form_id
    return existing_form, new_form
Exemplo n.º 3
0
    def new_form_from_old(cls, existing_form, xml, value_responses_map, user_id):
        from corehq.form_processor.parsers.form import apply_deprecation

        new_xml = etree.tostring(xml)
        form_json = convert_xform_to_json(new_xml)
        new_form = cls.new_xform(form_json)
        new_form.user_id = user_id
        new_form.domain = existing_form.domain
        new_form.app_id = existing_form.app_id

        existing_form, new_form = apply_deprecation(existing_form, new_form)
        return (existing_form, new_form)
Exemplo n.º 4
0
    def new_form_from_old(cls, existing_form, xml, value_responses_map, user_id):
        from corehq.form_processor.parsers.form import apply_deprecation

        new_xml = etree.tostring(xml)
        form_json = convert_xform_to_json(new_xml)
        new_form = cls.new_xform(form_json)
        new_form.user_id = user_id
        new_form.domain = existing_form.domain
        new_form.app_id = existing_form.app_id
        cls.store_attachments(new_form, [Attachment(
            name=ATTACHMENT_NAME,
            raw_content=new_xml,
            content_type='text/xml',
        )])

        existing_form, new_form = apply_deprecation(existing_form, new_form)
        return (existing_form, new_form)
Exemplo n.º 5
0
    def new_form_from_old(cls, existing_form, xml, value_responses_map, user_id):
        from corehq.form_processor.parsers.form import apply_deprecation

        new_xml = etree.tostring(xml)
        form_json = convert_xform_to_json(new_xml)
        new_form = cls.new_xform(form_json)
        new_form.user_id = user_id
        new_form.domain = existing_form.domain
        new_form.app_id = existing_form.app_id
        cls.store_attachments(new_form, [Attachment(
            name=ATTACHMENT_NAME,
            raw_content=new_xml,
            content_type='text/xml',
        )])

        existing_form, new_form = apply_deprecation(existing_form, new_form)
        return (existing_form, new_form)
Exemplo n.º 6
0
    def new_form_from_old(cls, existing_form, xml, value_responses_map,
                          user_id):
        from corehq.form_processor.parsers.form import apply_deprecation
        new_form = XFormInstance.wrap(existing_form.to_json())

        for question, response in six.iteritems(value_responses_map):
            data = new_form.form_data
            i = XFormQuestionValueIterator(question)
            for (qid, repeat_index) in i:
                data = data[qid]
                if repeat_index is not None:
                    data = data[repeat_index]
            data[i.last()] = response

        new_form._deferred_blobs = None  # will be re-populated by apply_deprecation
        new_form.external_blobs.clear(
        )  # will be re-populated by apply_deprecation
        existing_form, new_form = apply_deprecation(existing_form, new_form)
        return (existing_form, new_form)
Exemplo n.º 7
0
    def new_form_from_old(cls, existing_form, xml, value_responses_map, user_id):
        from corehq.form_processor.parsers.form import apply_deprecation
        new_form = XFormInstance.wrap(existing_form.to_json())

        for question, response in six.iteritems(value_responses_map):
            data = new_form.form_data
            i = XFormQuestionValueIterator(question)
            for (qid, repeat_index) in i:
                data = data[qid]
                if repeat_index is not None:
                    data = data[repeat_index]
            data[i.last()] = response

        new_xml = etree.tostring(xml)
        new_form._deferred_blobs = None     # will be re-populated by apply_deprecation
        new_form.external_blobs.clear()     # will be re-populated by apply_deprecation
        new_form.deferred_put_attachment(new_xml, "form.xml", content_type="text/xml")
        existing_form, new_form = apply_deprecation(existing_form, new_form)
        return (existing_form, new_form)
Exemplo n.º 8
0
    def new_form_from_old(cls, existing_form, xml, value_responses_map,
                          user_id):
        from corehq.form_processor.parsers.form import apply_deprecation
        new_form = XFormInstance.wrap(existing_form.to_json())

        for question, response in value_responses_map.items():
            data = new_form.form_data
            i = XFormQuestionValueIterator(question)
            for (qid, repeat_index) in i:
                data = data[qid]
                # Repeat groups with multiple responses store them in a list
                if repeat_index is not None and isinstance(data, list):
                    data = data[repeat_index]
            data[i.last()] = response

        new_xml = etree.tostring(xml)
        new_form._deferred_blobs = None  # will be re-populated by apply_deprecation
        new_form.external_blobs.clear(
        )  # will be re-populated by apply_deprecation
        new_form.deferred_put_attachment(new_xml,
                                         "form.xml",
                                         content_type="text/xml")
        existing_form, new_form = apply_deprecation(existing_form, new_form)
        return (existing_form, new_form)