diff documentViewer.py @ 516:7d7b639d7be7

add methods to use doc-info.xql. read list of page numbers from doc-info.xql. add original page numbers to thumbs.
author casties
date Mon, 05 Mar 2012 18:04:49 +0100
parents c55e376be01b
children 91051b36b9cc
line wrap: on
line diff
--- a/documentViewer.py	Tue Feb 28 21:22:52 2012 +0100
+++ b/documentViewer.py	Mon Mar 05 18:04:49 2012 +0100
@@ -183,6 +183,10 @@
         """returns one page of the search results"""
         return self.template.fulltextclient.getResultsPage(**args)
 
+    def getTextInfo(self, **args):
+        """returns document info from the text server"""
+        return self.template.fulltextclient.getTextInfo(**args)
+
     def getToc(self, **args):
         """loads table of contents and stores XML in docinfo"""
         return self.template.fulltextclient.getToc(**args)
@@ -479,6 +483,9 @@
             texttool = self.metadataService.getTexttoolData(dom=metaDom)
             if texttool:
                 docinfo = self.getDocinfoFromTexttool(docinfo, texttool)
+                # document info from full text
+                if docinfo.get('textURLPath', None):
+                    docinfo = self.getTextInfo(docinfo=docinfo)
             
             # bib info
             bib = self.metadataService.getBibData(dom=metaDom)
@@ -509,7 +516,7 @@
 
         # image path
         if mode != 'texttool':
-            # override image path from texttool with url
+            # override image path from texttool with url TODO: how about mode=auto?
             docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1)
 
         # number of images from digilib
@@ -517,12 +524,19 @@
             docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + docinfo['imagePath']
             docinfo = self.getDocinfoFromDigilib(docinfo, docinfo['imagePath'])
 
+        # check numPages
+        if docinfo.get('numPages', 0) == 0:
+            if docinfo.get('numTextPages', 0) > 0:
+                # replace with numTextPages (text-only?)
+                docinfo['numPages'] = docinfo['numTextPages']
+
         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
 
+
     def getDocinfoFromResource(self, docinfo, resource):
         """reads contents of resource element into docinfo"""
         docName = resource.get('name', None)
@@ -698,6 +712,7 @@
         pageinfo['viewLayer'] = viewLayer
         pageinfo['tocMode'] = tocMode
 
+        # TODO: unify current and pn!
         current = getInt(current)
         pageinfo['current'] = current
         pageinfo['pn'] = current
@@ -715,6 +730,7 @@
         np = int(docinfo.get('numPages', 0))
         if np == 0:
             # numPages unknown - maybe we can get it from text page
+            logging.warn("getPageInfo: numPages=0 trying getTextPage!")
             if docinfo.get('textURLPath', None):
                 # cache text page as well
                 pageinfo['textPage'] = self.getTextPage(mode=viewLayer, pn=current, docinfo=docinfo, pageinfo=pageinfo)
@@ -732,8 +748,14 @@
         pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft))
         pageinfo['pageZero'] = pageZero
         pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
-                
+        # more page parameters
         pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
+        if docinfo.get('pageNumbers'):
+            # get original page numbers
+            pageNumber = docinfo['pageNumbers'].get(current, None)
+            if pageNumber is not None:
+                pageinfo['pageNumberOrig'] = pageNumber['no']
+                pageinfo['pageNumberOrigNorm'] = pageNumber['non']
         
         # cache search results
         pageinfo['resultPageSize'] = getInt(self.REQUEST.get('resultPageSize', 10))