diff documentViewer.py @ 613:c57d80a649ea

CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/281
author casties
date Thu, 17 Oct 2013 16:25:39 +0200
parents a79e4e4b3e37
children d6eca930a534 7aefbddddaf9
line wrap: on
line diff
--- a/documentViewer.py	Thu May 16 18:04:00 2013 +0200
+++ b/documentViewer.py	Thu Oct 17 16:25:39 2013 +0200
@@ -4,34 +4,20 @@
 from App.ImageFile import ImageFile
 from AccessControl import ClassSecurityInfo
 from AccessControl import getSecurityManager
-from Globals import package_home
 
 import xml.etree.ElementTree as ET
 
 import os
-import sys
 import urllib
 import logging
 import math
 import urlparse 
-import re
-import string
 import json
 
 from Products.MetaDataProvider import MetaDataFolder
 
 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml
     
-def serializeNode(node, encoding="utf-8"):
-    """returns a string containing node as XML"""
-    s = ET.tostring(node)
-    
-    # 4Suite:
-    #    stream = cStringIO.StringIO()
-    #    Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding)
-    #    s = stream.getvalue()
-    #    stream.close()
-    return s
 
 def getMDText(node):
     """returns the @text content from the MetaDataProvider metadata node"""
@@ -993,7 +979,23 @@
 
 
     def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
-        """returns dict with array of page information for one screenfull of thumbnails"""
+        """Return dict with array of page information for one screenfull of thumbnails.
+
+        :param start: index of current page
+        :param rows: number of rows in one batch
+        :param cols: number of columns in one batch
+        :param pageFlowLtr: do indexes increase from left to right
+        :param pageZero: is there a zeroth non-visible page
+        :param minIdx: minimum index to use
+        :param maxIdx: maximum index to use
+        :returns: dict with
+            first: first page index
+            last: last page index
+            batches: list of all possible batches(dict: 'start': index, 'end': index)
+            pages: list for current batch of rows(list of cols(list of pages(dict: 'idx': index)))
+            nextStart: first index of next batch
+            prevStart: first index of previous batch 
+        """
         logging.debug("getPageBatch start=%s minIdx=%s maxIdx=%s"%(start,minIdx,maxIdx))
         batch = {}
         grpsize = rows * cols
@@ -1001,7 +1003,12 @@
             maxIdx = start + grpsize
 
         np = maxIdx - minIdx + 1
+        if pageZero:
+            # correct number of pages for batching
+            np += 1
+            
         nb = int(math.ceil(np / float(grpsize)))
+        
         # list of all batch start and end points
         batches = []
         if pageZero:
@@ -1016,6 +1023,7 @@
             
         batch['batches'] = batches
 
+        # list of pages for current screen
         pages = []
         if pageZero and start == minIdx:
             # correct beginning
@@ -1045,15 +1053,21 @@
             batch['prevStart'] = None
             
         if start + grpsize <= maxIdx:
-            batch['nextStart'] = start + grpsize
+            if pageZero and start == minIdx:
+                # correct nextStart for pageZero
+                batch['nextStart'] = grpsize
+            else:
+                batch['nextStart'] = start + grpsize
         else:
             batch['nextStart'] = None
 
         batch['pages'] = pages
         batch['first'] = minIdx
         batch['last'] = maxIdx
+        logging.debug("batch: %s"%repr(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 = {}