本文整理汇总了Python中mgi.models.XMLdata类的典型用法代码示例。如果您正苦于以下问题:Python XMLdata类的具体用法?Python XMLdata怎么用?Python XMLdata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLdata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_publish_draft
def test_update_publish_draft(self):
status = Status.ACTIVE
new_xml = "<Resource localid='' status='"+status+"'><identity>" \
"<title>My new software</title></identity><curation><publisher>PF</publisher><contact><name></name>" \
"</contact></curation><content><description>This is a new record</description><subject></subject>" \
"<referenceURL></referenceURL></content></Resource>"
id = self.createXMLData(ispublished=True)
xmlData = XMLdata.get(id)
self.assertNotEquals(new_xml, XMLdata.unparse(xmlData['content']))
adminId = self.getAdmin().id
template = self.createTemplate()
elements = SchemaElement.objects().all()
self.assertEqual(len(elements), 0)
elementsForm = FormData.objects().all()
self.assertEqual(len(elementsForm), 0)
formData = self.createFormData(user=adminId, name='name', template=str(template.id), xml_data=new_xml,
xml_data_id=str(id))
url = '/dashboard/update_publish_draft'
data = {'draft_id': str(formData.id)}
r = self.doRequestGetAdminClientLogged(url=url, data=data)
xmlDataInDatabase = XMLdata.get(id)
elements = SchemaElement.objects().all()
self.assertEqual(len(elements), 0)
elementsForm = FormData.objects().all()
self.assertEqual(len(elementsForm), 0)
self.assertEquals(etree.XML(new_xml).text, etree.XML(str(XMLdata.unparse(xmlDataInDatabase['content']))).text)
self.assertEquals(True, xmlDataInDatabase.get('ispublished'))
self.assertEquals(str(adminId), xmlDataInDatabase.get('iduser'))
self.assertNotEquals(xmlData.get('lastmodificationdate'), xmlDataInDatabase.get('lastmodificationdate'))
self.assertNotEquals(xmlData.get('publicationdate'), xmlDataInDatabase.get('publicationdate'))
self.assertEquals(status, xmlDataInDatabase.get('status'))
示例2: test_invert_str
def test_invert_str(self):
criteria = build_criteria("content.root.str", "is", "test1", "xs:string", "xs")
results = XMLdata.executeQueryFullResult(criteria)
self.assertTrue(len(results) == 1)
inverted = invertQuery(criteria)
inverted_results = XMLdata.executeQueryFullResult(inverted)
self.assertTrue(len(inverted_results) == 2)
示例3: test_delete_result
def test_delete_result(self):
id = self.createXMLData()
self.assertIsNotNone(XMLdata.get(id))
url = '/dashboard/delete_result'
data = {'result_id': str(id)}
r = self.doRequestGetAdminClientLogged(url=url, data=data)
self.assertIsNone(XMLdata.get(id))
示例4: test_update_unpublish
def test_update_unpublish(self):
id = self.createXMLData(ispublished=True)
self.assertEquals(True, XMLdata.get(id)['ispublished'])
url = '/dashboard/update_unpublish'
data = {'result_id': str(id)}
r = self.doRequestGetAdminClientLogged(url=url, data=data)
self.assertEquals(False, XMLdata.get(id)['ispublished'])
示例5: explore_detail_result_process
def explore_detail_result_process(request):
result_id = request.GET['id']
xmlString = XMLdata.get(result_id)
schemaId = xmlString['schema']
if 'title' in request.GET:
title = request.GET['title']
else:
title = xmlString['title']
xmlString = XMLdata.unparse(xmlString['content']).encode('utf-8')
xsltPath = os.path.join(settings.SITE_ROOT, 'static', 'resources', 'xsl', 'xml2html.xsl')
xslt = etree.parse(xsltPath)
transform = etree.XSLT(xslt)
#Check if a custom detailed result XSLT has to be used
schema = Template.objects.get(pk=schemaId)
try:
if (xmlString != ""):
dom = etree.fromstring(str(xmlString))
if schema.ResultXsltDetailed:
shortXslt = etree.parse(BytesIO(schema.ResultXsltDetailed.content.encode('utf-8')))
shortTransform = etree.XSLT(shortXslt)
newdom = shortTransform(dom)
else:
newdom = transform(dom)
except Exception, e:
#We use the default one
newdom = transform(dom)
示例6: my_profile_resources
def my_profile_resources(request):
template = loader.get_template('profile/my_profile_resources.html')
if 'template' in request.GET:
template_name = request.GET['template']
if template_name == 'all':
context = RequestContext(request, {
'XMLdatas': XMLdata.find({'iduser' : str(request.user.id)}),
})
else :
if template_name == 'datacollection':
templateNamesQuery = list(chain(Template.objects.filter(title=template_name).values_list('id'), Template.objects.filter(title='repository').values_list('id'), Template.objects.filter(title='database').values_list('id'), Template.objects.filter(title='projectarchive').values_list('id')))
else :
templateNamesQuery = Template.objects.filter(title=template_name).values_list('id')
templateNames = []
for templateQuery in templateNamesQuery:
templateNames.append(str(templateQuery))
context = RequestContext(request, {
'XMLdatas': XMLdata.find({'iduser' : str(request.user.id), 'schema':{"$in" : templateNames}}), 'template': template_name
})
else :
context = RequestContext(request, {
'XMLdatas': XMLdata.find({'iduser' : str(request.user.id)}),
})
return HttpResponse(template.render(context))
示例7: test_invert_numeric
def test_invert_numeric(self):
criteria = build_criteria("content.root.integer", "=", 1, "xs:int", "xs")
results = XMLdata.executeQueryFullResult(criteria)
self.assertTrue(len(results) == 1)
inverted = invertQuery(criteria)
inverted_results = XMLdata.executeQueryFullResult(inverted)
self.assertTrue(len(inverted_results) == 2)
示例8: change_owner_record
def change_owner_record(request):
if 'recordID' in request.POST and 'userID' in request.POST:
xml_data_id = request.POST['recordID']
user_id = request.POST['userID']
try:
XMLdata.update_user(xml_data_id, user=user_id)
messages.add_message(request, messages.INFO, 'Record Owner changed with success.')
except Exception, e:
return HttpResponseServerError({"Something wrong occurred during the change of owner."}, status=500)
示例9: test_invert_and_numeric
def test_invert_and_numeric(self):
criteria1 = build_criteria("content.root.integer", "gt", 1, "xs:int", "xs")
criteria2 = build_criteria("content.root.integer", "lte", 3, "xs:int", "xs")
criteria = ANDCriteria(criteria1, criteria2)
results = XMLdata.executeQueryFullResult(criteria)
self.assertTrue(len(results) == 2)
inverted = invertQuery(criteria)
inverted_results = XMLdata.executeQueryFullResult(inverted)
self.assertTrue(len(inverted_results) == 3)
示例10: change_status_case_inactive
def change_status_case_inactive(self, ispublished):
id = self.createXMLData(ispublished=ispublished)
XMLdata.change_status(id, Status.INACTIVE, ispublished)
list_xmldata = XMLdata.find({'_id': ObjectId(id)})
self.assertEquals(Status.INACTIVE, list_xmldata[0]['status'])
self.assertEquals(Status.INACTIVE, list_xmldata[0]['content']['Resource']['@status'])
if ispublished:
self.assertNotEquals(None, list_xmldata[0].get('oai_datestamp', None))
else:
self.assertEquals(None, list_xmldata[0].get('oai_datestamp', None))
示例11: delete_result
def delete_result(request):
result_id = request.GET['result_id']
try:
XMLdata.delete(result_id)
except:
# XML can't be found
pass
return HttpResponse(json.dumps({}), content_type='application/javascript')
示例12: dashboard_resources
def dashboard_resources(request):
template = loader.get_template('dashboard/my_dashboard_my_records.html')
query = {}
context = RequestContext(request, {})
ispublished = request.GET.get('ispublished', None)
template_name = request.GET.get('template', None)
query['iduser'] = str(request.user.id)
#If ispublished not None, check if we want publish or unpublish records
if ispublished:
ispublished = ispublished == 'true'
query['ispublished'] = ispublished
if template_name:
context.update({'template': template_name})
if template_name == 'datacollection':
templateNamesQuery = list(chain(Template.objects.filter(title=template_name).values_list('id'),
Template.objects.filter(title='repository').values_list('id'),
Template.objects.filter(title='database').values_list('id'),
Template.objects.filter(title='projectarchive').values_list('id')))
else :
templateNamesQuery = Template.objects.filter(title=template_name).values_list('id')
templateNames = []
for templateQuery in templateNamesQuery:
templateNames.append(str(templateQuery))
query['schema'] = {"$in" : templateNames}
userXmlData = sorted(XMLdata.find(query), key=lambda data: data['lastmodificationdate'], reverse=True)
#Add user_form for change owner
user_form = UserForm(request.user)
context.update({'XMLdatas': userXmlData, 'ispublished': ispublished, 'user_form': user_form})
#If the user is an admin, we get records for other users
if request.user.is_staff:
#Get user name for admin
usernames = dict((str(x.id), x.username) for x in User.objects.all())
query['iduser'] = {"$ne": str(request.user.id)}
otherUsersXmlData = sorted(XMLdata.find(query), key=lambda data: data['lastmodificationdate'], reverse=True)
context.update({'OtherUsersXMLdatas': otherUsersXmlData, 'usernames': usernames})
#Get new version of records
listIds = [str(x['_id']) for x in userXmlData]
if request.user.is_staff:
listIdsOtherUsers = [str(x['_id']) for x in otherUsersXmlData]
listIds = list(set(listIds).union(set(listIdsOtherUsers)))
drafts = FormData.objects(xml_data_id__in=listIds, isNewVersionOfRecord=True).all()
XMLdatasDrafts = dict()
for draft in drafts:
XMLdatasDrafts[draft.xml_data_id] = draft.id
context.update({'XMLdatasDrafts': XMLdatasDrafts})
#Add Status enum
context.update({'Status': Status})
return HttpResponse(template.render(context))
示例13: test_change_owner_record
def test_change_owner_record(self):
userId = self.getUser().id
adminId = self.getAdmin().id
template = self.createTemplate()
xmldataid = self.createXMLData(iduser=userId, schemaID=template.id)
self.assertEquals(str(userId), str(XMLdata.get(xmldataid)['iduser']))
url = '/dashboard/change-owner-record'
data = {'recordID': str(xmldataid), 'userID': str(adminId)}
r = self.doRequestPostUserClientLogged(url=url, data=data)
self.assertEquals(str(adminId), str(XMLdata.get(xmldataid)['iduser']))
self.isStatusOK(r.status_code)
示例14: update_publish
def update_publish(request):
XMLdata.update_publish(request.GET['result_id'])
resource = XMLdata.get(request.GET['result_id'])
# Send mail to the user and the admin
context = {'URI': MDCS_URI,
'title': resource['title'],
'publicationdate': resource['publicationdate'],
'user': request.user.username}
send_mail_to_managers(subject='Resource Published',
pathToTemplate='dashboard/email/resource_published.html',
context=context)
return HttpResponse(json.dumps({}), content_type='application/javascript')
示例15: save_xml_data_to_db
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)