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


Python XMLdata.save方法代码示例

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


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

示例1: save_xml_data_to_db

# 需要导入模块: from mgi.models import XMLdata [as 别名]
# 或者: from mgi.models.XMLdata import save [as 别名]
def save_xml_data_to_db(request):
    form_data_id = request.session['curateFormData']
    form_data = FormData.objects.get(pk=form_data_id)

    form_id = request.session['form_id']
    root_element = SchemaElement.objects.get(pk=form_id)

    xml_renderer = XmlRenderer(root_element)
    xml_string = xml_renderer.render()

    # xmlString = request.session['xmlString']
    # template_id = request.session['currentTemplateID']
    template_id = form_data.template

    # Parse data from form
    form = SaveDataForm(request.POST)
    if not form.data['title'].lower().endswith('.xml'):
        form.data['title'] += ".xml"

    if not form.is_valid():
        return HttpResponseBadRequest('Invalid form name')

    if xml_string == "" or xml_string is None:
        return HttpResponseBadRequest('No XML data found')

    try:
        # update data if id is present
        if form_data.xml_data_id is not None:
            XMLdata.update_content(
                form_data.xml_data_id,
                xml_string,
                title=form.data['title']
            )
        else:
            # create new data otherwise
            xml_data = XMLdata(
                schemaID=template_id,
                xml=xml_string,
                title=form.data['title'],
                iduser=str(request.user.id)
            )
            xml_data.save()

        form_data.delete()

        return HttpResponse('ok')
    except Exception, e:
        message = e.message.replace('"', '\'')
        return HttpResponseBadRequest(message)
开发者ID:pdessauw,项目名称:MaterialsResourceRegistry,代码行数:51,代码来源:views.py

示例2: save_xml_data_to_db

# 需要导入模块: from mgi.models import XMLdata [as 别名]
# 或者: from mgi.models.XMLdata import save [as 别名]
def save_xml_data_to_db(request):
    xmlString = request.session['xmlString']
    templateID = request.session['currentTemplateID']

    form = SaveDataForm(request.POST)

    if form.is_valid():
        if xmlString != "":
            try:
                # get form data from the database
                form_data_id = request.session['curateFormData']
                form_data = FormData.objects.get(pk=ObjectId(form_data_id))
                if not form.data['title'].lower().endswith('.xml'):
                    form.data['title'] += ".xml"
                # update data if id is present
                if form_data.xml_data_id is not None:
                    XMLdata.update_content(form_data.xml_data_id, xmlString, title=form.data['title'])
                else:
                    #create new data otherwise
                    newJSONData = XMLdata(schemaID=templateID, xml=xmlString, title=form.data['title'], iduser=str(request.user.id))
                    newJSONData.save()
                # delete form data
                try:
                    form_data = FormData.objects().get(pk=form_data_id)
                    # cascade delete references
                    for form_element_id in form_data.elements.values():
                        try:
                            form_element = FormElement.objects().get(pk=form_element_id)
                            if form_element.xml_element is not None:
                                try:
                                    xml_element = XMLElement.objects().get(pk=str(form_element.xml_element.id))
                                    xml_element.delete()
                                except:
                                    # raise an exception when element not found
                                    pass
                            form_element.delete()
                        except:
                            # raise an exception when element not found
                            pass
                    form_data.delete()
                except Exception, e:
                    return HttpResponseBadRequest('Unable to save data.')
                return HttpResponse('ok')
            except Exception, e:
                message = e.message.replace('"', '\'')
                return HttpResponseBadRequest(message)
开发者ID:hzhao1230,项目名称:nanomine,代码行数:48,代码来源:views.py


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