From 443971b274ed0172462eeb350aec33a7c13b19a5 Mon Sep 17 00:00:00 2001 From: kthoden Date: Mon, 27 Jan 2020 16:15:45 +0100 Subject: [PATCH] Index entries: link in current popup is deactivated --- .../management/commands/publicationimport.py | 96 +++++++------------ 1 file changed, 32 insertions(+), 64 deletions(-) diff --git a/eoapublications/management/commands/publicationimport.py b/eoapublications/management/commands/publicationimport.py index 87845d6..89a3308 100644 --- a/eoapublications/management/commands/publicationimport.py +++ b/eoapublications/management/commands/publicationimport.py @@ -23,53 +23,23 @@ def process_as_string(self,xmlElement): for xmlChild in xmlElement.iterchildren(): strResult = strResult + etree.tostring(xmlChild).decode() return strResult - def process_index_entries(self,xmlIndex,xmlElement,Newelement,Newpublication): - for xmlEntry in xmlElement.findall('EOAindex'): - if xmlEntry.get("secondary") is not None: - continue - Newindexelement = Indexelement(Element=Newelement) - strMainEntry = xmlEntry.get("main") - strHtml = strMainEntry + ": " - # Find corresponding Entry in EOAprintindex - for xmlIndexEntry in xmlIndex.findall(".//EOAindexentry"): - if xmlIndexEntry.get("main") == strMainEntry: - intLinkNumber = 1 - for xmlIndexLink in xmlIndexEntry.findall("./EOAindexlink"): - strHtml = strHtml + "" - strHtml = strHtml + str(intLinkNumber) - strHtml = strHtml + " " - intLinkNumber += 1 - strHtml = strHtml + "
" - Newindexelement.Html = strHtml - Newindexelement.save() - def process_personindex_entries(self,xmlPersonindex,xmlElement,Newelement,Newpublication): - for xmlEntry in xmlElement.findall('EOAindexperson'): - if xmlEntry.get("secondary") is not None: - continue - Newindexelement = Indexelement(Element=Newelement) - strMainEntry = xmlEntry.get("main") - if xmlEntry.get("display") is not None: - strHtml = xmlEntry.get("display") + ": " - else: - strHtml = xmlEntry.get("main") + ": " - # Find corresponding Entry in EOAprintindex - for xmlIndexEntry in xmlPersonindex.findall(".//EOAindexentry"): - if xmlIndexEntry.get("main") == strMainEntry: - intLinkNumber = 1 - for xmlIndexLink in xmlIndexEntry.findall("./EOAindexlink"): - strHtml = strHtml + "" - strHtml = strHtml + str(intLinkNumber) - strHtml = strHtml + " " - intLinkNumber += 1 - strHtml = strHtml + "
" - Newindexelement.Html = strHtml - Newindexelement.save() - def process_locationindex_entries(self,xmlLocationindex,xmlElement,Newelement,Newpublication): - for xmlEntry in xmlElement.findall('EOAindexlocation'): + # def process_as_string ends here + + def process_index_entries(self, xmlIndex, xmlElement, xmlChapter, Newelement, Newpublication, index_type): + """Construct the popups for index entries next to paragraphs.""" + + if index_type == "keyword": + xml_entries = xmlElement.findall('.//EOAindex') + elif index_type == "person": + xml_entries = xmlElement.findall('.//EOAindexperson') + elif index_type == "location": + xml_entries = xmlElement.findall('.//EOAindexlocation') + else: + print("No suitable index found.") + + for xmlEntry in xml_entries: + current_chapter_order = xmlChapter.get('order') + current_element_order = xmlElement.get('order') if xmlEntry.get("secondary") is not None: continue Newindexelement = Indexelement(Element=Newelement) @@ -79,27 +49,25 @@ def process_locationindex_entries(self,xmlLocationindex,xmlElement,Newelement,Ne else: strHtml = xmlEntry.get("main") + ": " # Find corresponding Entry in EOAprintindex - for xmlIndexEntry in xmlLocationindex.findall(".//EOAindexentry"): + for xmlIndexEntry in xmlIndex.findall(".//EOAindexentry"): if xmlIndexEntry.get("main") == strMainEntry: intLinkNumber = 1 for xmlIndexLink in xmlIndexEntry.findall("./EOAindexlink"): - strHtml = strHtml + "" + str(intLinkNumber) + " " + else: + strHtml = strHtml + "" - strHtml = strHtml + str(intLinkNumber) - strHtml = strHtml + " " + strHtml = strHtml + str(intLinkNumber) + strHtml = strHtml + " " intLinkNumber += 1 strHtml = strHtml + "
" Newindexelement.Html = strHtml - print ("Index Entry for Location Processed:") - print(strHtml) Newindexelement.save() + # def process_index_entries ends here - - print (xmlEntry.get("main")) - return - def process_indexsection(self, xmlIndexsection, intObjectOrder, intIndexEntry, publication_number, index_type, Newpublication, olddesign=False): """Create HTML code for indexsections""" @@ -545,15 +513,15 @@ def handle(self, **options): if xmlChild.findall("EOAindex") is not None: xmlEOAindex = xmlTree.find(".//EOAprintindex") if xmlEOAindex is not None: - self.process_index_entries(xmlEOAindex,xmlChild,Newelement,Newpublication) + self.process_index_entries(xmlEOAindex,xmlChild,xmlChapter,Newelement,Newpublication, "keyword") if xmlChild.findall("EOAindexperson") is not None: - xmlEOApersonindex = xmlTree.find(".//EOAprintpersonindex") - if xmlEOApersonindex is not None: - self.process_personindex_entries(xmlEOApersonindex,xmlChild,Newelement,Newpublication) + xmlEOAindex = xmlTree.find(".//EOAprintpersonindex") + if xmlEOAindex is not None: + self.process_index_entries(xmlEOAindex,xmlChild,xmlChapter,Newelement,Newpublication, "person") if xmlChild.findall("EOAindexlocation") is not None: - xmlEOAlocationindex = xmlTree.find(".//EOAprintlocationindex") - if xmlEOAlocationindex is not None: - self.process_locationindex_entries(xmlEOAlocationindex,xmlChild,Newelement,Newpublication) + xmlEOAindex = xmlTree.find(".//EOAprintlocationindex") + if xmlEOAindex is not None: + self.process_index_entries(xmlEOAindex,xmlChild,xmlChapter,Newelement,Newpublication, "location") xmlFacsimileparts = xmlTree.findall("EOAfacsimilepart") for xmlFacsimilepart in xmlFacsimileparts: print("Process Facsimileparts")