diff documentViewer.py @ 482:7ca8ac7db06e elementtree

more new template stuff. more batching methods in documentViewer.
author casties
date Tue, 16 Aug 2011 18:27:08 +0200
parents 50a28442f21c
children ab9b34a1c62a
line wrap: on
line diff
--- 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