• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.XMLdata类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了XMLdata类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'))
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:31,代码来源:tests_ajax.py


示例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)
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:7,代码来源:tests.py


示例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))
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:7,代码来源:tests_ajax.py


示例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'])
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:7,代码来源:tests_ajax.py


示例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)
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:27,代码来源:views.py


示例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))
开发者ID:hzhao1230,项目名称:nanomine,代码行数:25,代码来源:views.py


示例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)
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:7,代码来源:tests.py


示例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)
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:9,代码来源:views.py


示例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)
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:9,代码来源:tests.py


示例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))
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:10,代码来源:tests_model.py


示例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')
开发者ID:pdessauw,项目名称:MaterialsResourceRegistry,代码行数:10,代码来源:ajax.py


示例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))
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:55,代码来源:views.py


示例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)
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:11,代码来源:tests_views.py


示例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')
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:14,代码来源:ajax.py


示例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)
开发者ID:pdessauw,项目名称:MaterialsResourceRegistry,代码行数:49,代码来源:views.py


示例16: curate_enter_data

def curate_enter_data(request):
    print "BEGIN curate_enter_data(request)"

    try:
        context = RequestContext(request, {})
        if 'id' in request.GET:
            xml_data_id = request.GET['id']
            xml_data = XMLdata.get(xml_data_id)
            template = Template.objects().get(pk=ObjectId(xml_data['schema']))
            context = RequestContext(request, {'edit': True, 'template_name': template.title})
            curate_edit_data(request)
        elif 'template' in request.GET:
            context = RequestContext(request, {'template_name': request.GET['template']})
            curate_from_schema(request)
        elif 'templateid' in request.GET:
            pass

        template = loader.get_template('curate/curate_enter_data.html')

        return HttpResponse(template.render(context))
    except MDCSError, e:
        template = loader.get_template('curate/errors.html')
        context = RequestContext(request, {
            'errors': e.message,
        })
        return HttpResponse(template.render(context))
开发者ID:pdessauw,项目名称:MaterialsResourceRegistry,代码行数:26,代码来源:views.py


示例17: update_publish_draft

def update_publish_draft(request):
    form_id = request.GET['draft_id']
    form_data = FormData.objects.get(pk=form_id)
    xml_string = form_data.xml_data
    title = form_data.name
    if xml_string == "" or xml_string is None:
        return HttpResponseBadRequest('No XML data found')
    try:
        # update form data if id is present
        if form_data.xml_data_id is not None:
            publicationdate = XMLdata.update_publish_draft(form_data.xml_data_id, xml_string, str(request.user.id))
            #Delete the form
            if form_data.schema_element_root is not None:
                delete_branch_from_db(form_data.schema_element_root.pk)
            form_data.delete()

            # Send mail to the managers
            context = {'URI': MDCS_URI,
                       'title': title,
                       'publicationdate': publicationdate,
                       'user': request.user.username}

            send_mail_to_managers(subject='Resource Published',
                                    pathToTemplate='dashboard/email/resource_published.html',
                                    context=context)

            messages.add_message(request, messages.INFO, 'New version published with success.')
            return HttpResponse(json.dumps({}), content_type='application/javascript')
        else:
            return HttpResponseBadRequest('Related record not found. Impossible to publish the draft')

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


示例18: explore_detail_result_keyword

def explore_detail_result_keyword(request):
    template = loader.get_template("oai_pmh/explore/explore_detail_results_keyword.html")
    result_id = request.GET["id"]
    record = OaiRecord.objects.get(pk=result_id)
    # schemaId = xmlString['schema']
    if "title" in request.GET:
        title = request.GET["title"]
    else:
        title = record.identifier
    xmlString = XMLdata.unparse(record.getMetadataOrdered()).encode("utf-8")
    xsltPath = os.path.join(settings.SITE_ROOT, "static", "resources", "xsl", "xml2html.xsl")
    xslt = etree.parse(xsltPath)
    transform = etree.XSLT(xslt)
    dom = etree.fromstring(str(xmlString))

    # Check if a custom list result XSLT has to be used
    try:
        metadataFormat = record.metadataformat
        if metadataFormat.template.ResultXsltDetailed:
            listXslt = etree.parse(BytesIO(metadataFormat.template.ResultXsltDetailed.content.encode("utf-8")))
            transform = etree.XSLT(listXslt)
            newdom = transform(dom)
        else:
            newdom = transform(dom)
    except Exception, e:
        # We use the default one
        newdom = transform(dom)
开发者ID:usnistgov,项目名称:MaterialsResourceRegistry,代码行数:27,代码来源:views.py


示例19: curate_edit_data

def curate_edit_data(request):
    try:
        if 'useForm' in request.GET and request.GET['useForm'] == 'true':
            pass
        else:
            xml_data_id = request.GET['id']
            xml_data = XMLdata.get(xml_data_id)
            json_content = xml_data['content']
            xml_content = xmltodict.unparse(json_content)
            request.session['curate_edit_data'] = xml_content
            request.session['curate_edit'] = True
            request.session['currentTemplateID'] = xml_data['schema']
            # remove previously created forms when editing a new one
            previous_forms = FormData.objects(user=str(request.user.id), xml_data_id__exists=True)
            for previous_form in previous_forms:
                # TODO: check if need to delete all SchemaElements
                previous_form.delete()
            form_data = FormData(
                user=str(request.user.id),
                template=xml_data['schema'],
                name=xml_data['title'],
                xml_data=xml_content,
                xml_data_id=xml_data_id
            )
            form_data.save()
            request.session['curateFormData'] = str(form_data.id)

            if 'form_id' in request.session:
                del request.session['form_id']
            if 'formString' in request.session:
                del request.session['formString']
            if 'xmlDocTree' in request.session:
                del request.session['xmlDocTree']
    except:
        raise MDCSError("The document you are looking for doesn't exist.")
开发者ID:pdessauw,项目名称:MaterialsResourceRegistry,代码行数:35,代码来源:views.py


示例20: get_record

    def get_record(self):
        try:
            #Bool if we need to transform the XML via XSLT
            hasToBeTransformed = False
            #Check if the identifier pattern is OK
            id = self.check_identifier()
            #Template name
            self.template_name = 'oai_pmh/xml/get_record.xml'
            query = dict()
            #Convert id to ObjectId
            try:
                query['_id'] = ObjectId(id)
                #The record has to be published
                query['ispublished'] = True
            except Exception:
                raise idDoesNotExist(self.identifier)
            data = XMLdata.executeQueryFullResult(query)
            #This id doesn't exist
            if len(data) == 0:
                raise idDoesNotExist(self.identifier)
            data = data[0]
            #Get the template for the identifier
            template = data['schema']
            #Retrieve sets for this template
            sets = OaiMySet.objects(templates=template).all()
            #Retrieve the XSLT for the transformation
            try:
                #Get the metadataformat for the provided prefix
                myMetadataFormat = OaiMyMetadataFormat.objects.get(metadataPrefix=self.metadataPrefix)
                #If this metadata prefix is not associated to a template, we need to retrieve the XSLT to do the transformation
                if not myMetadataFormat.isTemplate:
                    hasToBeTransformed = True
                    #Get information about the XSLT for the MF and the template
                    objTempMfXslt = OaiTemplMfXslt.objects(myMetadataFormat=myMetadataFormat, template=template, activated=True).get()
                    #If no information or desactivated
                    if not objTempMfXslt.xslt:
                        raise cannotDisseminateFormat(self.metadataPrefix)
                    else:
                        #Get the XSLT for the transformation
                        xslt = objTempMfXslt.xslt
            except:
                raise cannotDisseminateFormat(self.metadataPrefix)

            #Transform XML data
            dataToTransform = [{'title': data['_id'], 'content': self.cleanXML(xmltodict.unparse(data['content']))}]
            if hasToBeTransformed:
                dataXML = self.getXMLTranformXSLT(dataToTransform, xslt)
            else:
                dataXML = dataToTransform
            #Fill the response
            record_info = {
                'identifier': self.identifier,
                'last_modified': datestamp.datetime_to_datestamp(data['publicationdate']) if 'publicationdate' in data else datestamp.datetime_to_datestamp(datetime.datetime.min),
                'sets': sets,
                'XML': dataXML[0]['content']
            }
            return self.render_to_response(record_info)
        except OAIExceptions, e:
            return self.errors(e.errors)
开发者ID:pdessauw,项目名称:MaterialsResourceRegistry,代码行数:59,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tests.DataHandler类代码示例发布时间:2022-05-27
下一篇:
Python log.debug函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap