changeset 460:76bc2317146f elementtree

more renovation
author casties
date Wed, 20 Jul 2011 21:36:57 +0200
parents aabfa6124cfb
children 8732f15df5f3
files documentViewer.py zpt/head_main.zpt
diffstat 2 files changed, 35 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/documentViewer.py	Wed Jul 20 10:22:36 2011 +0200
+++ b/documentViewer.py	Wed Jul 20 21:36:57 2011 +0200
@@ -102,6 +102,11 @@
     """returns pathname shortened by one"""
     return '/'.join(path.split('/')[0:-1])
         
+def normalizeBibtype(bt):
+    """returns normalised bib type for looking up mappings"""
+    bt = bt.strip().replace(' ', '-').lower()
+    return bt
+
 def getBibdataFromDom(dom):
     """returns dict with all elements from bib-tag"""
     bibinfo = {}
@@ -109,7 +114,7 @@
     if bib is not None:
         # put type in @type
         type = bib.get('type')
-        bibinfo['@type'] = type
+        bibinfo['@type'] = normalizeBibtype(type)
         # put all subelements in dict
         for e in bib:
             bibinfo[e.tag] = getText(e)
@@ -575,77 +580,19 @@
         # put all raw bib fields in dict "bib"
         bib = getBibdataFromDom(dom)
         docinfo['bib'] = bib
-        
-        # extract some fields (author, title, year) according to their mapping
-        metaData=self.metadata.main.meta.bib
-        bibtype=bib.get("@type")
-        #bibtype=dom.xpath("//bib/@type")
-        if not bibtype:
-            bibtype="generic"
-            
-        bibtype=bibtype.replace("-"," ") # wrong types in index meta "-" instead of " " (not wrong! ROC)
+        bibtype = bib.get('@type', None)
         docinfo['bib_type'] = bibtype
-        bibmap=metaData.generateMappingForType(bibtype)
-        logging.debug("documentViewer (getbibinfofromindexmeta) bibmap:"+repr(bibmap))
-        logging.debug("documentViewer (getbibinfofromindexmeta) bibtype:"+repr(bibtype))
-        # if there is no mapping bibmap is empty (mapping sometimes has empty fields)
-        if len(bibmap) > 0 and bibmap.get('author',None) or bibmap.get('title',None):
-            try:
-                docinfo['author']=bib.get(bibmap['author'][0])
-            except: pass
-            try:
-                docinfo['title']=bib.get(bibmap['title'][0])
-            except: pass
+        if bibtype:
+            # also store standard mapped metadata for convenience
             try:
-                docinfo['year']=bib.get(bibmap['year'][0])
-            except: pass
-            
-            # ROC: why is this here?
-            #            logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype)
-            #            try:
-            #                docinfo['lang']=getTextFromNode(dom.find(".//bib/lang")[0])
-            #            except:
-            #                docinfo['lang']=''
-            #            try:
-            #                docinfo['city']=getTextFromNode(dom.find(".//bib/city")[0])
-            #            except:
-            #                docinfo['city']=''
-            #            try:
-            #                docinfo['number_of_pages']=getTextFromNode(dom.find(".//bib/number_of_pages")[0])
-            #            except:
-            #                docinfo['number_of_pages']=''
-            #            try:
-            #                docinfo['series_volume']=getTextFromNode(dom.find(".//bib/series_volume")[0])
-            #            except:
-            #                docinfo['series_volume']=''
-            #            try:
-            #                docinfo['number_of_volumes']=getTextFromNode(dom.find(".//bib/number_of_volumes")[0])
-            #            except:
-            #                docinfo['number_of_volumes']=''
-            #            try:
-            #                docinfo['translator']=getTextFromNode(dom.find(".//bib/translator")[0])
-            #            except:
-            #                docinfo['translator']=''
-            #            try:
-            #                docinfo['edition']=getTextFromNode(dom.find(".//bib/edition")[0])
-            #            except:
-            #                docinfo['edition']=''
-            #            try:
-            #                docinfo['series_author']=getTextFromNode(dom.find(".//bib/series_author")[0])
-            #            except:
-            #                docinfo['series_author']=''
-            #            try:
-            #                docinfo['publisher']=getTextFromNode(dom.find(".//bib/publisher")[0])
-            #            except:
-            #                docinfo['publisher']=''
-            #            try:
-            #                docinfo['series_title']=getTextFromNode(dom.find(".//bib/series_title")[0])
-            #            except:
-            #                docinfo['series_title']=''
-            #            try:
-            #                docinfo['isbn_issn']=getTextFromNode(dom.find(".//bib/isbn_issn")[0])
-            #            except:
-            #                docinfo['isbn_issn']=''           
+                stdbib = self.metadata.getStdMappedHash(bib)
+                docinfo['std_bib'] = stdbib
+                docinfo['author'] = stdbib['author']
+                docinfo['title'] = stdbib['title']
+                docinfo['year'] = stdbib['year']
+            except:
+                pass
+
         return docinfo
     
     
@@ -790,6 +737,7 @@
         imageUrl=self.digilibBaseUrl+"/servlet/Scaler?fn="+path
         docinfo['imageURL'] = imageUrl
         
+        #TODO: use getDocinfoFromIndexMeta
         #path ist the path to the images it assumes that the index.meta file is one level higher.
         docinfo = self.getBibinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)
         docinfo = self.getAuthinfoFromIndexMeta(pathorig,docinfo=docinfo,cut=cut+1)
@@ -824,12 +772,9 @@
             logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode)
             raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode))
                 
-        # FIXME: fake texturlpath 
-        if not docinfo.has_key('textURLPath'):
-            docinfo['textURLPath'] = None
-        
         logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys())
         #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo)
+        # store in session
         self.REQUEST.SESSION['docinfo'] = docinfo
         return docinfo
                
@@ -845,6 +790,7 @@
         pageinfo['cols'] = cols
         grpsize = cols * rows
         pageinfo['groupsize'] = grpsize
+        # what does this do?
         start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))
         # int(current / grpsize) * grpsize +1))
         pageinfo['start'] = start
@@ -854,7 +800,8 @@
             pageinfo['end'] = min(pageinfo['end'], np)
             pageinfo['numgroups'] = int(np / grpsize)
             if np % grpsize > 0:
-                pageinfo['numgroups'] += 1        
+                pageinfo['numgroups'] += 1
+                
         pageinfo['viewMode'] = viewMode
         pageinfo['tocMode'] = tocMode
         pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
@@ -866,10 +813,12 @@
         pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','')
         pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')
         pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10')
-        pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')     
-        toc = int (pageinfo['tocPN'])
-        pageinfo['textPages'] =int (toc)
+        pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')
+        # WTF?:
+        toc = int(pageinfo['tocPN'])
+        pageinfo['textPages'] =int(toc)
         
+        # What does this do?
         if 'tocSize_%s'%tocMode in docinfo:
             tocSize = int(docinfo['tocSize_%s'%tocMode])
             tocPageSize = int(pageinfo['tocPageSize'])
@@ -878,12 +827,15 @@
                 tocPages=tocSize/tocPageSize+1
             else:
                 tocPages=tocSize/tocPageSize
-            pageinfo['tocPN'] = min (tocPages,toc)                    
+                
+            pageinfo['tocPN'] = min(tocPages,toc)
+            
         pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')
         pageinfo['sn'] =self.REQUEST.get('sn','')
         return pageinfo
+
     
-def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
+    def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
         """init document viewer"""
         self.title=title
         self.digilibBaseUrl = digilibBaseUrl
--- a/zpt/head_main.zpt	Wed Jul 20 10:22:36 2011 +0200
+++ b/zpt/head_main.zpt	Wed Jul 20 21:36:57 2011 +0200
@@ -1,6 +1,4 @@
-<tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo; viewMode python:options.get('viewMode','images')">
-  <span tal:condition="not:exists:docinfo/author">(no bibliographical information)</span>
-  <tal:y tal:condition="exists:docinfo/author">
-    <b tal:content="docinfo/author"/>,<i tal:content="docinfo/title"/><i tal:condition="exists:docinfo/year" tal:content="string:,${docinfo/year}"/>
-  </tal:y>
+<tal:block tal:define="docinfo options/docinfo; pageinfo options/pageinfo; formattedLabel python:here.metadata.getFormattedLabel(bibdata=docinfo.get('bib',None))">
+  <span tal:condition="not:formattedLabel" tal:content="string:(no bibliographical information for ${docinfo/bib_type})"/>
+  <span tal:condition="formattedLabel" tal:content="structure formattedLabel"/>
 </tal:block>