changeset 469:15394486ab75 elementtree

working with new templates
author casties
date Wed, 03 Aug 2011 21:04:18 +0200
parents dc7c48912110
children c1ba044d4961
files MpdlXmlTextServer.py documentViewer.py
diffstat 2 files changed, 47 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/MpdlXmlTextServer.py	Tue Aug 02 18:29:15 2011 +0200
+++ b/MpdlXmlTextServer.py	Wed Aug 03 21:04:18 2011 +0200
@@ -227,18 +227,13 @@
           
     def processPageInfo(self, dom, docinfo, pageinfo):
         """processes page info divs from dom and stores in docinfo and pageinfo"""
-        # process all toplevel divs
-        alldivs = dom.findall(".//div")
-        pagediv = None
+        # assume first second level div is pageMeta
+        alldivs = dom.find("div")
         for div in alldivs:
             dc = div.get('class')
             
-            # page content div
-            if dc == 'pageContent':
-                pagediv = div
-            
             # pageNumberOrig  
-            elif dc == 'pageNumberOrig':
+            if dc == 'pageNumberOrig':
                 pageinfo['pageNumberOrig'] = div.text
                 
             # pageNumberOrigNorm
@@ -247,12 +242,16 @@
                 
             # pageNumberOrigNorm
             elif dc == 'countFigureEntries':
-                docinfo['countFigureEntries'] = getInt(div.text)
+                docinfo['numFigureEntries'] = getInt(div.text)
                 
             # pageNumberOrigNorm
             elif dc == 'countTocEntries':
                 # WTF: s1 = int(s)/30+1
-                docinfo['countTocEntries'] = getInt(div.text)
+                docinfo['numTocEntries'] = getInt(div.text)
+                
+            # pageHeaderTitle
+            elif dc == 'pageHeaderTitle':
+                docinfo['pageHeaderTitle'] = div.text
                 
             # numTextPages
             elif dc == 'countPages':
@@ -311,7 +310,8 @@
         # page content is in <div class="pageContent">
         pagediv = None
         # ElementTree 1.2 in Python 2.6 can't do div[@class='pageContent']
-        alldivs = dom.findall(".//div")
+        # so we look at the second level divs
+        alldivs = dom.findall("div")
         for div in alldivs:
             dc = div.get('class')
             # page content div
--- a/documentViewer.py	Tue Aug 02 18:29:15 2011 +0200
+++ b/documentViewer.py	Wed Aug 03 21:04:18 2011 +0200
@@ -299,12 +299,7 @@
                 viewMode="images"
                 
         pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, viewMode=viewMode, tocMode=tocMode)
-        
-        if viewMode != 'images' and docinfo.get('textURLPath', None):
-            # get full text page
-            page = self.getTextPage(mode=viewMode, pn=pn, docinfo=docinfo, pageinfo=pageinfo)
-            pageinfo['textPage'] = page
-            
+                    
         # get template /template/viewer_main
         pt = getattr(self.template, 'viewer_main')
         # and execute with parameters
@@ -344,17 +339,20 @@
         else:
             return style
     
-    def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&'):
-        """returns URL to documentviewer with parameter param set to val or from dict params"""
+    def getParams(self, param=None, val=None, params=None):
+        """returns dict with URL parameters.
+        
+        Takes URL parameters and additionally param=val or dict params.
+        Deletes key if value is None."""
         # copy existing request params
-        urlParams=self.REQUEST.form.copy()
+        newParams=self.REQUEST.form.copy()
         # change single param
         if param is not None:
             if val is None:
-                if urlParams.has_key(param):
-                    del urlParams[param]
+                if newParams.has_key(param):
+                    del newParams[param]
             else:
-                urlParams[param] = str(val)
+                newParams[param] = str(val)
                 
         # change more params
         if params is not None:
@@ -362,31 +360,30 @@
                 v = params[k]
                 if v is None:
                     # val=None removes param
-                    if urlParams.has_key(k):
-                        del urlParams[k]
+                    if newParams.has_key(k):
+                        del newParams[k]
                         
                 else:
-                    urlParams[k] = v
-
-        # FIXME: does this belong here?
-        if urlParams.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath
-                urlParams["mode"] = "imagepath"
-                urlParams["url"] = getParentPath(urlParams["url"])
-                
+                    newParams[k] = v
+                    
+        return newParams
+    
+    def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&'):
+        """returns URL to documentviewer with parameter param set to val or from dict params"""
+        urlParams = self.getParams(param=param, val=val, params=params)
         # quote values and assemble into query string (not escaping '/')
         ps = paramSep.join(["%s=%s"%(k,urllib.quote_plus(v,'/')) for (k, v) in urlParams.items()])
-        #ps = urllib.urlencode(urlParams)
         if baseUrl is None:
-            baseUrl = self.REQUEST['URL1']
+            baseUrl = self.getDocumentViewerURL()
             
         url = "%s?%s"%(baseUrl, ps)
         return url
 
-
     def getLinkAmp(self, param=None, val=None, params=None, baseUrl=None):
         """link to documentviewer with parameter param set to val"""
         return self.getLink(param, val, params, baseUrl, '&amp;')
     
+    
     def getInfo_xml(self,url,mode):
         """returns info about the document as XML"""
         if not self.digilibBaseUrl:
@@ -464,7 +461,6 @@
         # process index.meta contents
         if metaDom is not None:
             # document directory name and path
-            logging.debug("RESOURCE: %s"%repr(self.metadataService.resource.meta.getData(dom=metaDom, all=True, recursive=2)))
             resource = self.metadataService.getResourceData(dom=metaDom)
             if resource:
                 docinfo = self.getDocinfoFromResource(docinfo, resource)
@@ -572,7 +568,7 @@
         # odd pages are left
         docinfo['oddPage'] = texttool.get('odd-scan-orientation', 'left')
             
-        # number of title page
+        # number of title page (0: not defined)
         docinfo['titlePage'] = texttool.get('title-scan-no', 0)
             
         # old presentation stuff
@@ -672,7 +668,6 @@
         """returns pageinfo with the given parameters"""
         pageinfo = {}
         current = getInt(current)
-    
         pageinfo['current'] = current
         rows = int(rows or self.thumbrows)
         pageinfo['rows'] = rows
@@ -685,12 +680,20 @@
         # int(current / grpsize) * grpsize +1))
         pageinfo['start'] = start
         pageinfo['end'] = start + grpsize
-        if (docinfo is not None) and ('numPages' in docinfo):
-            np = int(docinfo['numPages'])
-            pageinfo['end'] = min(pageinfo['end'], np)
-            pageinfo['numgroups'] = int(np / grpsize)
-            if np % grpsize > 0:
-                pageinfo['numgroups'] += 1
+        pn = self.REQUEST.get('pn','1')
+        pageinfo['pn'] = pn
+        np = int(docinfo.get('numPages', 0))
+        if np == 0:
+            # numPages unknown - maybe we can get it from text page
+            if docinfo.get('textURLPath', None):
+                # cache text page as well
+                pageinfo['textPage'] = self.getTextPage(mode=viewMode, pn=pn, docinfo=docinfo, pageinfo=pageinfo)
+                np = int(docinfo.get('numPages', 0))
+                
+        pageinfo['end'] = min(pageinfo['end'], np)
+        pageinfo['numgroups'] = int(np / grpsize)
+        if np % grpsize > 0:
+            pageinfo['numgroups'] += 1
                 
         pageinfo['viewMode'] = viewMode
         pageinfo['tocMode'] = tocMode
@@ -699,7 +702,6 @@
         pageinfo['query'] = self.REQUEST.get('query','') 
         pageinfo['queryType'] = self.REQUEST.get('queryType','')
         pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext')
-        pageinfo['textPN'] = self.REQUEST.get('textPN','1')
         pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','')
         pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')
         pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10')
@@ -721,7 +723,6 @@
             pageinfo['tocPN'] = min(tocPages,toc)
             
         pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')
-        pageinfo['sn'] =self.REQUEST.get('sn','')
         return pageinfo