def get_form_xml_metadata(meta):
     try:
         couch_form._unsafe_get_xml()
         assert meta is not None, couch_form.form_id
         return meta
     except MissingFormXml:
         pass
     log.warning("Rebuilding missing form XML: %s", couch_form.form_id)
     metas = get_blob_metadata(couch_form.form_id)[(CODES.form_xml,
                                                    "form.xml")]
     if len(metas) == 1:
         couch_meta = couch_form.blobs.get("form.xml")
         if couch_meta is None:
             assert not metas[0].blob_exists(), metas
         else:
             assert metas[0].key == couch_meta.key, (metas, couch_meta)
         blobdb.delete(metas[0].key)
         metas.remove(metas[0])
     else:
         assert not metas, metas  # protect against yet another duplicate
     xml = convert_form_to_xml(couch_form.to_json()["form"])
     att = Attachment("form.xml",
                      xml.encode("utf-8"),
                      content_type="text/xml")
     return att.write(blobdb, sql_form)
Beispiel #2
0
def add_form_xml(sql_form, patch_form):
    xml = patch_form.get_xml()
    att = Attachment("form.xml", xml.encode("utf-8"), content_type="text/xml")
    xml_meta = att.write(get_blob_db(), sql_form)
    sql_form.attachments_list = [xml_meta]