本文整理汇总了Python中mgi.models.XMLdata.update_content方法的典型用法代码示例。如果您正苦于以下问题:Python XMLdata.update_content方法的具体用法?Python XMLdata.update_content怎么用?Python XMLdata.update_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mgi.models.XMLdata
的用法示例。
在下文中一共展示了XMLdata.update_content方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_xml_data_to_db
# 需要导入模块: from mgi.models import XMLdata [as 别名]
# 或者: from mgi.models.XMLdata import update_content [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)
示例2: save_xml_data_to_db
# 需要导入模块: from mgi.models import XMLdata [as 别名]
# 或者: from mgi.models.XMLdata import update_content [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)