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


Python XMLdata.getByIDsAndDistinctBy方法代码示例

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


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

示例1: list_metadata_formats

# 需要导入模块: from mgi.models import XMLdata [as 别名]
# 或者: from mgi.models.XMLdata import getByIDsAndDistinctBy [as 别名]
    def list_metadata_formats(self):
        try:
            #Template name
            self.template_name = 'oai_pmh/xml/list_metadata_formats.xml'
            items = []
            # If an identifier is provided, with look for its metadataformats
            if self.identifier != None:
                id = self.check_identifier()
                #We retrieve the template id for this record
                listId = []
                listId.append(id)
                listSchemaIds = XMLdata.getByIDsAndDistinctBy(listId, 'schema')
                if len(listSchemaIds) == 0:
                    raise idDoesNotExist(self.identifier)
                #Get metadata formats information for this template. The metadata formats must be activated
                metadataFormats = OaiTemplMfXslt.objects(template__in=listSchemaIds, activated=True).distinct(field='myMetadataFormat')
                #Get the template metadata format if existing
                metadataFormatsTemplate = OaiMyMetadataFormat.objects(template__in=listSchemaIds, isTemplate=True).all()
                if len(metadataFormatsTemplate) != 0:
                    metadataFormats.extend(metadataFormatsTemplate)
            else:
                #No identifier provided. We return all metadata formats available
                metadataFormats = OaiMyMetadataFormat.objects().all()
            #If there is no metadata formats, we raise noMetadataFormat
            if len(metadataFormats) == 0:
                raise noMetadataFormat
            else:
                #Fill the response
                for metadataFormat in metadataFormats:
                    item_info = {
                        'metadataNamespace': metadataFormat.metadataNamespace,
                        'metadataPrefix':  metadataFormat.metadataPrefix,
                        'schema':  metadataFormat.schema
                    }
                    items.append(item_info)

            return self.render_to_response({'items': items})
        except OAIExceptions, e:
            return self.errors(e.errors)
开发者ID:pdessauw,项目名称:MaterialsResourceRegistry,代码行数:41,代码来源:views.py

示例2: start_export

# 需要导入模块: from mgi.models import XMLdata [as 别名]
# 或者: from mgi.models.XMLdata import getByIDsAndDistinctBy [as 别名]
def start_export(request):
    if request.method == 'POST':
        #We retrieve all selected exporters
        listExporter = request.POST.getlist('my_exporters')
        instances = request.session['instancesExplore']
        listId = request.session['listIdToExport']
        xmlResults = []
        #Creation of ZIP file
        in_memory = StringIO()
        zip = zipfile.ZipFile(in_memory, "a")
        is_many_inst = len(instances) > 1
        for instance in instances:
            #Retrieve data
            sessionName = "resultsExplore" + eval(instance)['name']
            results = request.session[sessionName]
            if (len(results) > 0):
                for result in results:
                    if result['id'] in listId:
                        xmlResults.append(result)

            #For each data, we convert
            if len(xmlResults) > 0:
                #Init the folder name
                folder_name = None
                if is_many_inst:
                    folder_name = eval(instance)['name']
                #Check if the XSLT converter is asked. If yes, we start with this one because there is a specific treatment
                listXslt = request.POST.getlist('my_xslts')
                #Get the content of the file
                if len(listXslt) > 0:
                    exporter = XSLTExporter()
                    for xslt in listXslt:
                        xslt = ExporterXslt.objects.get(pk=xslt)
                        exporter._setXslt(xslt.content)
                        if folder_name == None:
                            exporter._transformAndZip(xslt.name, xmlResults, zip)
                        else:
                            exporter._transformAndZip(folder_name+"/"+xslt.name, xmlResults, zip)

                #We export for others exporters
                for exporter in listExporter:
                    exporter = get_exporter(exporter)
                    exporter._transformAndZip(folder_name, xmlResults, zip)

        zip.close()

        #ZIP file to be downloaded
        in_memory.seek(0)
        response = HttpResponse(in_memory.read())
        response["Content-Disposition"] = "attachment; filename=Results.zip"
        response['Content-Type'] = 'application/x-zip'
        request.session['listIdToExport'] = ''

        return response
    else:
        # We retrieve the result_id for each file the user wants to export
        listId = request.GET.getlist('listId[]')
        request.session['listIdToExport'] = listId

        # Get all schemaId from the listId
        listSchemas = XMLdata.getByIDsAndDistinctBy(listId, "schema")
            # XMLdata.objects(pk__in=listId).distinct(field="schema")

        export_form = ExportForm(listSchemas)

        upload_xslt_Form = UploadXSLTForm(listSchemas)
        template = loader.get_template('explore/export_start.html')
        context = Context({'export_form':export_form, 'upload_xslt_Form':upload_xslt_Form, 'nb_elts_exp': len(export_form.EXPORT_OPTIONS), 'nb_elts_xslt' : len(upload_xslt_Form.EXPORT_OPTIONS)})

        return HttpResponse(json.dumps({'template': template.render(context)}), content_type='application/javascript')
开发者ID:hzhao1230,项目名称:nanomine,代码行数:72,代码来源:views.py


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