# HG changeset patch # User casties # Date 1313512028 -7200 # Node ID 7ca8ac7db06ec67a02ee19d0560fc5b2e0096777 # Parent 0a0f7f570f90a1b1b1e90200c24b35ff45431d5a more new template stuff. more batching methods in documentViewer. diff -r 0a0f7f570f90 -r 7ca8ac7db06e MpdlXmlTextServer.py --- 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): diff -r 0a0f7f570f90 -r 7ca8ac7db06e css/docuviewer.css --- 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; } diff -r 0a0f7f570f90 -r 7ca8ac7db06e documentViewer.py --- 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 diff -r 0a0f7f570f90 -r 7ca8ac7db06e zpt/toc_figures.zpt --- 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 @@
+ tal:define="start pageinfo/start; tocsize docinfo/tocSize_figures; grpsize pageinfo/tocPageSize; + batch python:here.getBatch(start=start,size=grpsize,end=tocsize);">