--- documentViewer/documentViewer.py 2011/08/12 14:41:39 1.175.2.24 +++ documentViewer/documentViewer.py 2011/08/17 15:00:31 1.175.2.28 @@ -1,4 +1,5 @@ from OFS.Folder import Folder +from OFS.Image import File from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate from Products.PageTemplates.PageTemplateFile import PageTemplateFile from AccessControl import ClassSecurityInfo @@ -122,6 +123,8 @@ class documentViewer(Folder): """MetaDataFolder instance""" # templates and forms + viewer_text = PageTemplateFile('zpt/viewer_text', globals()) + viewer_images = PageTemplateFile('zpt/viewer_images', globals()) viewer_main = PageTemplateFile('zpt/viewer_main', globals()) toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals()) toc_text = PageTemplateFile('zpt/toc_text', globals()) @@ -134,8 +137,9 @@ class documentViewer(Folder): page_main_xml = PageTemplateFile('zpt/page_main_xml', globals()) page_main_pureXml = PageTemplateFile('zpt/page_main_pureXml', globals()) head_main = PageTemplateFile('zpt/head_main', globals()) - docuviewer_css = PageTemplateFile('css/docuviewer.css', globals()) info_xml = PageTemplateFile('zpt/info_xml', globals()) + # TODO: can this be nicer? + docuviewer_css = File('docuviewer_css','',open(os.path.join(package_home(globals()),'css/docuviewer.css')), content_type='text/css') thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) @@ -346,13 +350,32 @@ class documentViewer(Folder): """try to get the digilib URL from zogilib""" url = self.template.zogilib.getDLBaseUrl() return url + + def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None): + """returns URL to digilib Scaler with params""" + url = None + if docinfo is not None: + url = docinfo.get('imageURL', None) + + if url is None: + url = "%s/servlet/Scaler?"%self.digilibBaseUrl + if fn is None and docinfo is not None: + fn = docinfo.get('imagePath','') + + url += "fn=%s"%fn + + if pn: + url += "&pn=%s"%pn + + url += "&dw=%s&dh=%s"%(dw,dh) + return url def getDocumentViewerURL(self): """returns the URL of this instance""" return self.absolute_url() def getStyle(self, idx, selected, style=""): - """returns a string with the given style and append 'sel' if path == selected.""" + """returns a string with the given style and append 'sel' if idx == selected.""" #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) if idx == selected: return style + 'sel' @@ -533,8 +556,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'] @@ -707,6 +728,7 @@ class documentViewer(Folder): current = getInt(current) pageinfo['current'] = current + pageinfo['pn'] = current rows = int(rows or self.thumbrows) pageinfo['rows'] = rows cols = int(cols or self.thumbcols) @@ -717,14 +739,13 @@ class documentViewer(Folder): start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) # int(current / grpsize) * grpsize +1)) pageinfo['start'] = start - pn = self.REQUEST.get('pn','1') - pageinfo['pn'] = pn + np = int(docinfo.get('numPages', 0)) if np == 0: # numPages unknown - maybe we can get it from text page if docinfo.get('textURLPath', None): # cache text page as well - pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo) + pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=current, docinfo=docinfo, pageinfo=pageinfo) np = int(docinfo.get('numPages', 0)) pageinfo['numgroups'] = int(np / grpsize) @@ -736,8 +757,9 @@ class documentViewer(Folder): # add zeroth page for two columns pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) pageinfo['pageZero'] = pageZero - pageinfo['pageList'] = self.getPageList(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) + pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) + # TODO: do we need this here? pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') pageinfo['query'] = self.REQUEST.get('query','') pageinfo['queryType'] = self.REQUEST.get('queryType','') @@ -763,10 +785,27 @@ class documentViewer(Folder): return pageinfo - def getPageList(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): - """returns array of page informations for one screenfull of thumbnails""" + 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 + rows * cols + 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: @@ -791,8 +830,62 @@ class documentViewer(Folder): pages.append(row) - logging.debug("getPageList returns=%s"%(pages)) - return pages + if start > 1: + batch['prevStart'] = max(start - grpsize, 1) + else: + batch['prevStart'] = None + + if start + grpsize < maxIdx: + batch['nextStart'] = start + grpsize + else: + batch['nextStart'] = None + + batch['pages'] = pages + 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 security.declareProtected('View management screens','changeDocumentViewerForm')