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)
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)
def process_cross_query(navigation_root_id, document_id, query, json_content): """ :param document_id: :param query: :param json_content: :return: """ doc_query = {"_id": ObjectId(document_id)} doc_projection = {query.values()[0]: 1} document = XMLdata.executeQueryFullResult(doc_query, doc_projection) document_projection_value = get_projection(document[0]) cross_query = {query.keys()[0]: document_projection_value} cross_projection = {"_id": 1} cross_documents = XMLdata.executeQueryFullResult(cross_query, cross_projection) cross_documents_ids = [ get_projection(cross_doc) for cross_doc in cross_documents ] # FIXME won't work for the case where we need several item from a same document cross_document_data = processviewdocidlist(navigation_root_id, cross_documents_ids, json_content) return [ content for contents in cross_document_data for content in contents ]
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)
def list_identifiers(self): try: #Template name self.template_name = 'oai_pmh/xml/list_identifiers.xml' query = dict() items = [] #Handle FROM and UNTIL query = self.check_dates() try: #Get the metadata format thanks to the prefix myMetadataFormat = OaiMyMetadataFormat.objects.get( metadataPrefix=self.metadataPrefix) #Get all template using it (activated True) templates = OaiTemplMfXslt.objects( myMetadataFormat=myMetadataFormat, activated=True).distinct(field="template") #Ids templatesID = [str(x.id) for x in templates] #If myMetadataFormat is linked to a template, we add the template id if myMetadataFormat.isTemplate: templatesID.append(str(myMetadataFormat.template.id)) except: #The metadata format doesn't exist raise cannotDisseminateFormat(self.metadataPrefix) if self.set: try: setsTemplates = OaiMySet.objects( setSpec=self.set).only('templates').get() templatesID = set(templatesID).intersection( [str(x.id) for x in setsTemplates.templates]) except Exception, e: raise noRecordsMatch for template in templatesID: #Retrieve sets for this template sets = OaiMySet.objects(templates=template).all() query['schema'] = template #The record has to be published query['ispublished'] = True #Get all records for this template data = XMLdata.executeQueryFullResult(query) #IF no records, go to the next template if len(data) == 0: continue for i in data: #Fill the response identifier = '%s:%s:id/%s' % (settings.OAI_SCHEME, settings.OAI_REPO_IDENTIFIER, str(i['_id'])) item_info = { 'identifier': identifier, 'last_modified': self.get_last_modified_date(i), 'sets': sets, 'deleted': i.get('status', '') == Status.DELETED } items.append(item_info) #If there is no records if len(items) == 0: raise noRecordsMatch return self.render_to_response({'items': items})
def execute_query(filters=list(), projection=None): """ :param filters: :param projection: :return: """ # query = { # "$and": [] # } results_id = {xml_data["_id"] for xml_data in XMLdata.objects()} results = [] # Parsing filters if present for _filter in filters: if _is_advanced_filter(_filter): json_filter = json.loads(_filter) # Get matching document # list possible values of the right hand side # match resulted documents documents_field = json_filter["documents"].values()[0] values = get_filter_values(documents_field) matching_documents = get_matching_document( json_filter["documents"].keys()[0], values, json_filter["query"]) # Extract correct documents filter_result = [] for doc in matching_documents: doc_cross_query = { json_filter["documents"].values()[0]: get_projection(doc) } filter_result += XMLdata.executeQueryFullResult( doc_cross_query, json.loads(projection)) else: filter_result = XMLdata.executeQueryFullResult( json.loads(_filter), json.loads(projection)) filter_id = {document["_id"] for document in filter_result} results_id = results_id.intersection(filter_id) results = [doc for doc in filter_result if doc["_id"] in results_id] return results
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)
def test_or_numeric_3(self): criteria1 = build_criteria("content.root.integer", "=", 1, "xs:int", "xs") criteria2 = build_criteria("content.root.integer", "gte", 2, "xs:int", "xs") criteria = ORCriteria(criteria1, criteria2) results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 3)
def test_and_numeric_1(self): criteria1 = build_criteria("content.root.integer", "=", 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) == 1)
def test_decimal_not(self): criteria = build_criteria("content.root.float", "=", 1, "xs:float", "xs", isNot=True) results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 2)
def test_enum_not(self): criteria = build_criteria("content.root.enum", "is", "a", "enum", "xs", isNot=True) results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 2)
def test_str_encoding(self): criteria = build_criteria("content.root.str", "is", "test", "xs:string", "xs", isNot=True) results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 1)
def test_numeric_not(self): criteria = build_criteria("content.root.integer", "=", 1, "xs:int", "xs", isNot=True) results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 2)
def test_regex_not(self): criteria = build_criteria("content.root.str", "like", "test", "xs:string", "xs", isNot=True) manageRegexBeforeExe(criteria) results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 0)
def get_filter_values(field): """ Get matching values in MongoDB for a given field :param field: :return: """ query = {field: {"$exists": True}} projection = {field: 1} documents = XMLdata.executeQueryFullResult(query, projection) return {get_projection(doc) for doc in documents}
def list_identifiers(self): try: #Template name self.template_name = 'oai_pmh/xml/list_identifiers.xml' query = dict() items=[] #Handle FROM and UNTIL query = self.check_dates() try: #Get the metadata format thanks to the prefix myMetadataFormat = OaiMyMetadataFormat.objects.get(metadataPrefix=self.metadataPrefix) #Get all template using it (activated True) templates = OaiTemplMfXslt.objects(myMetadataFormat=myMetadataFormat, activated=True).distinct(field="template") #Ids templatesID = [str(x.id) for x in templates] #If myMetadataFormat is linked to a template, we add the template id if myMetadataFormat.isTemplate: templatesID.append(str(myMetadataFormat.template.id)) except: #The metadata format doesn't exist raise cannotDisseminateFormat(self.metadataPrefix) if self.set: try: setsTemplates = OaiMySet.objects(setSpec=self.set).only('templates').get() templatesID = set(templatesID).intersection([str(x.id) for x in setsTemplates.templates]) except Exception, e: raise noRecordsMatch for template in templatesID: #Retrieve sets for this template sets = OaiMySet.objects(templates=template).all() query['schema'] = template #The record has to be published query['ispublished'] = True #Get all records for this template data = XMLdata.executeQueryFullResult(query) #IF no records, go to the next template if len(data) == 0: continue for i in data: #Fill the response identifier = '%s:%s:id/%s' % (settings.OAI_SCHEME, settings.OAI_REPO_IDENTIFIER, str(i['_id'])) item_info = { 'identifier': identifier, 'last_modified': self.get_last_modified_date(i), 'sets': sets, 'deleted': i.get('status', '') == Status.DELETED } items.append(item_info) #If there is no records if len(items) == 0: raise noRecordsMatch return self.render_to_response({'items': items})
def test_and_numeric_not(self): criteria1 = build_criteria("content.root.integer", "=", 1, "xs:int", "xs", isNot=True) criteria2 = build_criteria("content.root.integer", "lte", 3, "xs:int", "xs") criteria = ANDCriteria(criteria1, criteria2) results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 2)
def test_decimal_false(self): criteria = build_criteria("content.root.float", "=", 4, "xs:float", "xs") results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 0)
def test_enum_false(self): criteria = build_criteria("content.root.enum", "is", "d", "enum", "xs") results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 0)
def test_str_false(self): criteria = build_criteria("content.root.str", "is", "test4", "xs:string", "xs") results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 0)
def test_and_numeric_0(self): criteria1 = build_criteria("content.root.integer", "=", 0, "xs:int", "xs") criteria2 = build_criteria("content.root.integer", "gte", 4, "xs:int", "xs") criteria = ANDCriteria(criteria1, criteria2) results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 0)
def load_leaf_view(request, docid): """ Load view for a leaf Parameters: - request - doc id Returns: """ navigation_name2=request.POST["node_id"] xml_document = XMLdata.get(docid) navigation_node = Navigation.objects.get(pk=request.POST["node_id"]) # Display XML file if "projection_view" annotation is not configured if "projection_view" not in navigation_node.options: # TODO transform the XML into a data table return HttpResponse(json.dumps({}), HTTP_200_OK) projection_views = json.loads(navigation_node.options["projection_view"]) view_data = { "header": xml_document.get("title"), "type": "leaf", "views": [] } #Initialize parameters in order to download later some information my_listof_ordereddicts_cross_docs2 =[] query_and_results2 = [] my_listof_ordereddicts2 = [] resultat2 = [] resultat3 = [] my_list_of_cross_results = [] # Send the annotation to the processor and collect the data for projection_view in projection_views: result_data = { "title": projection_view["title"], "data": None } # FIXME better handling of x- if "query" in projection_view.keys(): my_projections = [] # Get the names of the brakets which need to be displayed for value in projection_view["data"]: my_projections.append(value.get('path')) result_data["data"] = process_cross_query(request.POST["nav_id"], docid, projection_view["query"], projection_view["data"]) # Set the documents which must be queried doc_query_proc = { "_id": ObjectId(docid) } quiered_docs = doc_to_query(1) co_dict = {} for id_doc in quiered_docs: other_doc_query = { "_id" : ObjectId(id_doc) } for projection in my_projections: proj_co = { my_projections[my_projections.index(projection)] : 1 } res_co = XMLdata.executeQueryFullResult(other_doc_query,proj_co) try: doc_projco = get_projection(res_co[0]) s = str(my_projections[my_projections.index(projection)]) y = s.split(".") attribute = y[len(y)-1] result_cross = doc_projco my_list_of_cross_results.append((attribute,result_cross)) global list_of_ordered_dict_cross_docs list_of_ordered_dict_cross_docs = res_co my_listof_ordereddicts_cross_docs2.append(res_co) if "OrderedDict" in str(doc_projco): pass else: querry_doc1 = query_and_results2[len(query_and_results2)-1]#.split(".") querry_doc = (querry_doc1.split(".")) q_doc = querry_doc[len(querry_doc)-1] resultat3.append((q_doc,doc_projco)) except: res_co = '' else: my_projections = [] for value in projection_view["data"]: my_projections.append(value.get('path')) id_doc_to_query = { "_id": ObjectId(docid) } for projection in my_projections: proj_co = { my_projections[my_projections.index(projection)] : 1 } res_co = XMLdata.executeQueryFullResult(id_doc_to_query,proj_co) query_and_results2.append(projection) try: doc_projco = get_projection(res_co[0]) global list_of_ordered_dict list_of_ordered_dict = res_co my_listof_ordereddicts2.append(res_co) results_initial_doc.append(doc_projco) if "OrderedDict" in str(doc_projco): pass else: querry_doc1 = query_and_results2[len(query_and_results2)-1]#.split(".") querry_doc = (querry_doc1.split(".")) q_doc = querry_doc[len(querry_doc)-1] resultat2.append((q_doc,doc_projco)) except: res_co = '' result_data["data"] = processview(request.POST["nav_id"], docid, projection_view["data"]) my_result_to_dwld.append(result_data["data"]) view_data["views"].append(result_data) my_node = str(get_node_name(navigation_name2))+"_"+str(request.POST["doc_id"]) query_and_results_tab.append(query_and_results2) my_listof_ordereddicts_cross_docs_tab.append(my_listof_ordereddicts_cross_docs2) navigation_name_tab.append(navigation_name2) my_listof_ordereddicts_tab.append(my_listof_ordereddicts2) resultat.append(resultat2) my_list_of_cross_results_f.append(my_list_of_cross_results) my_tab.append(my_node) return view_data
def test_numeric_inferior(self): criteria = build_criteria("content.root.integer", "lt", 3, "xs:int", "xs") results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 2)
#if a set was provided, we filter the templates if self.set: try: setsTemplates = OaiMySet.objects(setSpec=self.set).only('templates').get() templatesID = set(templatesID).intersection([str(x.id) for x in setsTemplates.templates]) except Exception, e: raise noRecordsMatch #For each template found for template in templatesID: #Retrieve sets for this template sets = OaiMySet.objects(templates=template).all() query['schema'] = template #The record has to be published query['ispublished'] = True #Get all records for this template data = XMLdata.executeQueryFullResult(query, includeDeleted=True) #IF no records, go to the next template if len(data) == 0: continue if not myMetadataFormat.isTemplate: xslt = objTempMfXslt(template=template).get().xslt #Add each record for elt in data: dataToTransform = [{'title': elt['title'], 'content': self.cleanXML(elt['xml_file'])}] dataXML = dataToTransform if myMetadataFormat.isTemplate \ else self.getXMLTranformXSLT(dataToTransform, xslt) identifier = '%s:%s:id/%s' % (settings.OAI_SCHEME, settings.OAI_REPO_IDENTIFIER,
def test_numeric_superior_equals(self): criteria = build_criteria("content.root.integer", "gte", 1, "xs:int", "xs") results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 3)
def test_numeric_false(self): criteria = build_criteria("content.root.integer", "=", 4, "xs:int", "xs") results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 0)
try: setsTemplates = OaiMySet.objects( setSpec=self.set).only('templates').get() templatesID = set(templatesID).intersection( [str(x.id) for x in setsTemplates.templates]) except Exception, e: raise noRecordsMatch #For each template found for template in templatesID: #Retrieve sets for this template sets = OaiMySet.objects(templates=template).all() query['schema'] = template #The record has to be published query['ispublished'] = True #Get all records for this template data = XMLdata.executeQueryFullResult(query) #IF no records, go to the next template if len(data) == 0: continue dataToTransform = [{ 'title': x['_id'], 'content': self.cleanXML(xmltodict.unparse(x['content'])) } for x in data] if myMetadataFormat.isTemplate: #No transformation needed dataXML = dataToTransform else: #Get the XSLT file xslt = objTempMfXslt(template=template).get().xslt
def test_numeric_inferior_equals(self): criteria = build_criteria("content.root.integer", "lte", 3, "xs:int", "xs") results = XMLdata.executeQueryFullResult(criteria) self.assertTrue(len(results) == 3)
def __load_link_view(request): """ Load link view for a link :param request: :return: """ ref_node_id = request.POST["ref_node_id"] reference_node = get_navigation_node_for_document(ref_node_id, request.POST["doc_id"]) navigation_name2 = request.POST["ref_node_id"]# xml_document = XMLdata.get(request.POST["doc_id"])# try : if "projection_view" in reference_node.options and reference_node.options["projection_view"] is not None: projection_views = json.loads(reference_node.options["projection_view"]) view_data = { "header": xml_document.get("title"), "type": "leaf", "views": [] } my_listof_ordereddicts_cross_docs2 =[]# query_and_results2 = []# my_listof_ordereddicts2 = []# resultat2 = [] resultat3 = [] my_list_of_cross_results = [] # Send the annotation to the processor and collect the data for projection_view in projection_views: result_data = { "title": projection_view["title"], "data": None } # FIXME better handling of x-queries if "query" in projection_view.keys(): my_projections = []# # Get the names of the brakets which need to be displayed for value in projection_view["data"]:# my_projections.append(value.get('path'))# result_data["data"] = process_cross_query(request.POST["nav_id"], request.POST["doc_id"], projection_view["query"], projection_view["data"]) # Set the documents which must be queried doc_query_proc = { "_id": ObjectId(request.POST["doc_id"]) } quiered_docs = doc_to_query(1) co_dict = {} for id_doc in quiered_docs: other_doc_query = { "_id" : ObjectId(id_doc) } for projection in my_projections: proj_co = { my_projections[my_projections.index(projection)] : 1 } res_co = XMLdata.executeQueryFullResult(other_doc_query,proj_co) try: doc_projco = get_projection(res_co[0]) s = str(my_projections[my_projections.index(projection)]) y = s.split(".") attribute = y[len(y)-1] result_cross = doc_projco my_list_of_cross_results.append((attribute,result_cross)) global list_of_ordered_dict_cross_docs list_of_ordered_dict_cross_docs = res_co my_listof_ordereddicts_cross_docs2.append(res_co) if "OrderedDict" in str(doc_projco): pass else: querry_doc1 = query_and_results2[len(query_and_results2)-1]#.split(".") querry_doc = (querry_doc1.split(".")) q_doc = querry_doc[len(querry_doc)-1] resultat3.append((q_doc,doc_projco)) except: res_co = '' else: my_projections = [] for value in projection_view["data"]: my_projections.append(value.get('path')) id_doc_to_query = { "_id": ObjectId(request.POST["doc_id"]) } for projection in my_projections: proj_co = { my_projections[my_projections.index(projection)] : 1 } res_co = XMLdata.executeQueryFullResult(id_doc_to_query,proj_co) query_and_results2.append(projection) try: doc_projco = get_projection(res_co[0]) global list_of_ordered_dict list_of_ordered_dict = res_co my_listof_ordereddicts2.append(res_co) results_initial_doc.append(doc_projco) if "OrderedDict" in str(doc_projco): pass else: querry_doc1 = query_and_results2[len(query_and_results2)-1]#.split(".") querry_doc = (querry_doc1.split(".")) q_doc = querry_doc[len(querry_doc)-1] resultat2.append((q_doc,doc_projco)) except: res_co = '' result_data["data"] = processview(request.POST["nav_id"], request.POST["doc_id"], projection_view["data"]) my_result_to_dwld.append(result_data["data"]) view_data["views"].append(result_data) my_node = str(get_node_name(navigation_name2))+"_"+str(request.POST["doc_id"]) query_and_results_tab.append(query_and_results2) my_listof_ordereddicts_cross_docs_tab.append(my_listof_ordereddicts_cross_docs2) navigation_name_tab.append(navigation_name2) my_listof_ordereddicts_tab.append(my_listof_ordereddicts2) resultat.append(resultat2) my_list_of_cross_results_f.append(my_list_of_cross_results) my_tab.append(my_node) html_data = render(request, "explore_tree/components/view.html", view_data) doc_id = str(reference_node.pk) + "." + str(xml_document["_id"]) return HttpResponse(json.dumps({"html": html_data.content, "doc_id": doc_id}), status=HTTP_200_OK) else: return HttpResponse(json.dumps({}), HTTP_200_OK) except: #"NOT FOUND" #else: return HttpResponse(json.dumps({}), HTTP_200_OK)
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, includeDeleted=True) #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['title'], 'content': self.cleanXML(data['xml_file'])}] if hasToBeTransformed: dataXML = self.getXMLTranformXSLT(dataToTransform, xslt) else: dataXML = dataToTransform #Fill the response record_info = { 'identifier': self.identifier, 'last_modified': self.get_last_modified_date(data), 'sets': sets, 'XML': dataXML[0]['content'], 'deleted': data.get('status', '') == Status.DELETED } return self.render_to_response(record_info) except OAIExceptions, e: return self.errors(e.errors)
#if a set was provided, we filter the templates if self.set: try: setsTemplates = OaiMySet.objects(setSpec=self.set).only('templates').get() templatesID = set(templatesID).intersection([str(x.id) for x in setsTemplates.templates]) except Exception, e: raise noRecordsMatch #For each template found for template in templatesID: #Retrieve sets for this template sets = OaiMySet.objects(templates=template).all() query['schema'] = template #The record has to be published query['ispublished'] = True #Get all records for this template data = XMLdata.executeQueryFullResult(query) #IF no records, go to the next template if len(data) == 0: continue dataToTransform = [{'title': x['_id'], 'content': self.cleanXML(xmltodict.unparse(x['content']))} for x in data] if myMetadataFormat.isTemplate: #No transformation needed dataXML = dataToTransform else: #Get the XSLT file xslt = objTempMfXslt(template=template).get().xslt #Transform all XML data (1 call) dataXML = self.getXMLTranformXSLT(dataToTransform, xslt) #Add each record for elt in data: identifier = '%s:%s:id/%s' % (settings.OAI_SCHEME, settings.OAI_REPO_IDENTIFIER,