changeset 482:7ca8ac7db06e elementtree

more new template stuff. more batching methods in documentViewer.
author casties
date Tue, 16 Aug 2011 18:27:08 +0200
parents 0a0f7f570f90
children ab9b34a1c62a
files MpdlXmlTextServer.py css/docuviewer.css documentViewer.py zpt/toc_figures.zpt zpt/toc_text.zpt zpt/toc_thumbs.zpt
diffstat 6 files changed, 144 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/MpdlXmlTextServer.py	Tue Aug 16 12:02:00 2011 +0200
+++ b/MpdlXmlTextServer.py	Tue Aug 16 18:27:08 2011 +0200
@@ -479,7 +479,7 @@
 
         return docinfo
     
-    def getTocPage(self, mode="text", pn=0, pageinfo=None, docinfo=None):
+    def getTocPage(self, mode="text", pn=None, start=None, size=None, pageinfo=None, docinfo=None):
         """returns single page from the table of contents"""
         logging.debug("getTocPage mode=%s, pn=%s"%(mode,pn))
         if mode == "text":
@@ -494,20 +494,21 @@
         tocxml = docinfo.get('tocXML_%s'%mode, None)
         if not tocxml:
             logging.error("getTocPage: unable to find tocXML")
-            return "No ToC"
+            return "Error: no table of contents!"
         
-        pagesize = pageinfo['tocPageSize']
-        tocPN = pageinfo['tocPN']
-        if not pn:
-            pn = tocPN
+        if size is None:
+            size = pageinfo.get('tocPageSize', 30)
+            
+        if start is None:
+            start = (pn - 1) * size
 
         fulltoc = ET.fromstring(tocxml)
         
         if fulltoc:
             # paginate
-            start = (pn - 1) * pagesize * 2
-            len = pagesize * 2
-            del fulltoc[:start]
+            first = (start - 1) * 2
+            len = size * 2
+            del fulltoc[:first]
             del fulltoc[len:]
             tocdivs = fulltoc
             
@@ -525,7 +526,17 @@
                     else:
                         logging.warning("getTocPage: Problem with link=%s"%href)
                         
-            return serialize(tocdivs)
+            # fix two-divs-per-row with containing div
+            newtoc = ET.Element('div', {'class':'queryResultPage'})
+            for (d1,d2) in zip(tocdivs[::2],tocdivs[1::2]):
+                e = ET.Element('div',{'class':'tocline'})
+                e.append(d1)
+                e.append(d2)
+                newtoc.append(e)
+                
+            return serialize(newtoc)
+        
+        return "ERROR: no table of contents!"
     
     
     def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
--- a/css/docuviewer.css	Tue Aug 16 12:02:00 2011 +0200
+++ b/css/docuviewer.css	Tue Aug 16 18:27:08 2011 +0200
@@ -10,7 +10,6 @@
 }
 
 div.col_left {
-    /* would be better without fixed width */
     max-width: 20em;
 }
 
--- a/documentViewer.py	Tue Aug 16 12:02:00 2011 +0200
+++ b/documentViewer.py	Tue Aug 16 18:27:08 2011 +0200
@@ -555,8 +555,6 @@
             # override image path from texttool with url
             docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1)
 
-            
-
         # number of images from digilib
         if docinfo.get('imagePath', None):
             docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + docinfo['imagePath']
@@ -786,12 +784,28 @@
         return pageinfo
 
 
-    def getPageBatch(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
+    def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
         """returns dict with array of page informations for one screenfull of thumbnails"""
+        batch = {}
         grpsize = rows * cols
         if maxIdx == 0:
             maxIdx = start + grpsize
 
+        nb = int(math.ceil(maxIdx / float(grpsize)))
+        # list of all batch start and end points
+        batches = []
+        if pageZero:
+            ofs = 0
+        else:
+            ofs = 1
+            
+        for i in range(nb):
+            s = i * grpsize + ofs
+            e = min((i + 1) * grpsize + ofs - 1, maxIdx)
+            batches.append({'start':s, 'end':e})
+            
+        batch['batches'] = batches
+
         pages = []
         if pageZero and start == 1:
             # correct beginning
@@ -815,7 +829,6 @@
                 
             pages.append(row)
             
-        batch = {}
         if start > 1:
             batch['prevStart'] = max(start - grpsize, 1)
         else:
@@ -827,7 +840,50 @@
             batch['nextStart'] = None
 
         batch['pages'] = pages
-        #logging.debug("getPageList returns=%s"%(batch))
+        return batch
+        
+    def getBatch(self, start=1, size=10, end=0, data=None, fullData=True):
+        """returns dict with information for one screenfull of data."""
+        batch = {}
+        if end == 0:
+            end = start + size                    
+            
+        nb = int(math.ceil(end / float(size)))
+        # list of all batch start and end points
+        batches = []
+        for i in range(nb):
+            s = i * size + 1
+            e = min((i + 1) * size, end)
+            batches.append({'start':s, 'end':e})
+            
+        batch['batches'] = batches
+        # list of elements in this batch
+        this = []
+        j = 0
+        for i in range(start, min(start+size, end)):
+            if data:
+                if fullData:
+                    d = data[i]
+                else:
+                    d = data[j]
+                    j += 1
+            
+            else:
+                d = i+1
+                
+            this.append(d)
+            
+        batch['this'] = this
+        if start > 1:
+            batch['prevStart'] = max(start - size, 1)
+        else:
+            batch['prevStart'] = None
+            
+        if start + size < end:
+            batch['nextStart'] = start + size
+        else:
+            batch['nextStart'] = None
+        
         return batch
         
 
--- a/zpt/toc_figures.zpt	Tue Aug 16 12:02:00 2011 +0200
+++ b/zpt/toc_figures.zpt	Tue Aug 16 18:27:08 2011 +0200
@@ -7,8 +7,8 @@
 <body>
   <!-- block used for main content area -->
   <div class="col_left" metal:define-macro="main"
-    tal:define="pn pageinfo/tocPN; tocsize docinfo/tocSize_figures; grpsize pageinfo/tocPageSize;
-                maxpn python:int(math.ceil(tocsize/float(grpsize)));">
+    tal:define="start pageinfo/start; tocsize docinfo/tocSize_figures; grpsize pageinfo/tocPageSize;
+                batch python:here.getBatch(start=start,size=grpsize,end=tocsize);">
     <ul class="switcher">
       <li><a
         tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a>
@@ -17,7 +17,7 @@
         tal:condition="python:docpath and docinfo.get('numTocEntries', None)">
         <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
       </li>
-      <li
+      <li class="sel"
         tal:condition="python:docpath and docinfo.get('numFigureEntries', None)">
         <a
         tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a>
@@ -29,25 +29,25 @@
     <div class="ruler">
       <form class="autosubmit" tal:attributes="action viewerUrl">
         <input type="hidden"
-          tal:define="params python:here.getParams('tocPN', None)"
+          tal:define="params python:here.getParams('start', None)"
           tal:repeat="param params"
           tal:attributes="name param; value python:params[param]" /> 
-        <a tal:condition="python:(pn>1)"
-          tal:attributes="href python:here.getLink('tocPN',pn-1)">&lt;</a>
-        <span tal:condition="python:(pn<=1)">&lt;</span> 
-        <select class="autosubmit" name="tocPN">
-          <option tal:repeat="idx python:range(maxpn)"
-            tal:attributes="selected python:(pn==idx*grpsize+1); value python:(idx*grpsize+1)"
-            tal:content="python:str(idx*grpsize+1)" />
+        <a tal:condition="batch/prevStart"
+          tal:attributes="href python:here.getLink('start',batch['prevStart'])">&lt;</a>
+        <span tal:condition="not:batch/prevStart">&lt;</span> 
+        <select class="autosubmit" name="start">
+          <option tal:repeat="grp batch/batches"
+            tal:attributes="selected python:(start==grp['start']); value grp/start"
+            tal:content="string:${grp/start} - ${grp/end}" />
         </select> 
         <input type="submit" value="Go" /> 
-        <a tal:condition="python:(pn<maxpn)"
-          tal:attributes="href python:here.getLink('tocPN',pn+1)">&gt;</a>
-        <span tal:condition="python:(pn>=maxpn)">&gt;</span> 
+        <a tal:condition="batch/nextStart"
+          tal:attributes="href python:here.getLink('start',batch['nextStart'])">&gt;</a>
+        <span tal:condition="not:batch/nextStart">&gt;</span> 
       </form>
     </div>
     <div class="content"
-      tal:content="structure python:here.getTocPage(mode='figures',pageinfo=pageinfo,docinfo=docinfo)" />
+      tal:content="structure python:here.getTocPage(mode='figures',start=start,pageinfo=pageinfo,docinfo=docinfo)" />
   </div>
   <!-- toc -->
 </body>
--- a/zpt/toc_text.zpt	Tue Aug 16 12:02:00 2011 +0200
+++ b/zpt/toc_text.zpt	Tue Aug 16 18:27:08 2011 +0200
@@ -7,19 +7,48 @@
 <body>
   <!-- block used for main content area -->
   <div class="col_left" metal:define-macro="main"
-     tal:define="docinfo options/docinfo; pageinfo options/pageinfo;  
-  pn python:int(pageinfo['tocPN']); tocsize python:int(docinfo['tocSize_text']); grpsize python:int(pageinfo['tocPageSize']);
-  maxpn python:int(tocsize/grpsize);">
-  <div class="thumbruler">
-    <span tal:condition="python:(pn>1)">
-      <a tal:attributes="href python:here.getLink(param='tocPN',val=pn-1)">&lt;</a>
-    </span>
-    <span tal:content="string:$pn of $tocsize"/>
-    <span>
-    <a tal:attributes="href python:here.getLink(param='tocPN',val=pn+1)">&gt;</a>
-  </span>
-</div>
-  <div class="content" tal:content="structure python:here.getTocPage(mode='text',pageinfo=pageinfo,docinfo=docinfo)"/>
-</div> <!-- toc -->
+    tal:define="start pageinfo/start; tocsize docinfo/tocSize_text; grpsize pageinfo/tocPageSize;
+                batch python:here.getBatch(start=start,size=grpsize,end=tocsize);">
+    <ul class="switcher">
+      <li><a
+        tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a>
+      </li>
+      <li class="sel"
+        tal:condition="python:docpath and docinfo.get('numTocEntries', None)">
+        <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
+      </li>
+      <li
+        tal:condition="python:docpath and docinfo.get('numFigureEntries', None)">
+        <a
+        tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a>
+      </li>
+      <li><a
+        tal:attributes="href python:here.getLink('tocMode','none')">None</a>
+      </li>
+    </ul>
+    <div class="ruler">
+      <form class="autosubmit" tal:attributes="action viewerUrl">
+        <input type="hidden"
+          tal:define="params python:here.getParams('start', None)"
+          tal:repeat="param params"
+          tal:attributes="name param; value python:params[param]" /> 
+        <a tal:condition="batch/prevStart"
+          tal:attributes="href python:here.getLink('start',batch['prevStart'])">&lt;</a>
+        <span tal:condition="not:batch/prevStart">&lt;</span> 
+        <select class="autosubmit" name="start">
+          <option tal:repeat="grp batch/batches"
+            tal:attributes="selected python:(start==grp['start']); value grp/start"
+            tal:content="string:${grp/start} - ${grp/end}" />
+        </select> 
+        <input type="submit" value="Go" /> 
+        <a tal:condition="batch/nextStart"
+          tal:attributes="href python:here.getLink('start',batch['nextStart'])">&gt;</a>
+        <span tal:condition="not:batch/nextStart">&gt;</span> 
+      </form>
+    </div>
+    <div class="content"
+      tal:content="structure python:here.getTocPage(mode='text',start=start,pageinfo=pageinfo,docinfo=docinfo)" />
+  </div>
+  <!-- toc -->
 </body>
 </html>
--- a/zpt/toc_thumbs.zpt	Tue Aug 16 12:02:00 2011 +0200
+++ b/zpt/toc_thumbs.zpt	Tue Aug 16 18:27:08 2011 +0200
@@ -38,10 +38,10 @@
           <span tal:condition="not:left">&lt;</span>
           <select class="autosubmit" name="start"
             tal:define="ofs python:test(pageinfo['pageZero'],0,1)">
-            <tal:block tal:repeat="grp python:range(numgroups)">
-              <option tal:define="idx python:max(grp*grpsize+ofs,1)"
-                tal:attributes="selected python:start==idx; value idx;"
-                tal:content="python:'%s - %s'%(idx,min((grp+1)*grpsize+ofs-1,numPages))" />
+            <tal:block >
+              <option tal:repeat="grp pageBatch/batches"
+                tal:attributes="selected python:start==grp['start']; value grp/start;"
+                tal:content="string:${grp/start} - ${grp/end}" />
             </tal:block>
           </select>
           <input type="submit" value="Go" />