--- documentViewer/documentViewer.py 2011/08/15 19:09:08 1.175.2.26 +++ documentViewer/documentViewer.py 2011/08/16 16:27:08 1.175.2.27 @@ -555,8 +555,6 @@ class documentViewer(Folder): # 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 @@ class documentViewer(Folder): 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 @@ class documentViewer(Folder): pages.append(row) - batch = {} if start > 1: batch['prevStart'] = max(start - grpsize, 1) else: @@ -827,7 +840,50 @@ class documentViewer(Folder): 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