# HG changeset patch # User casties # Date 1312914461 -7200 # Node ID 1d93a8cb2d8fd0b3c5081e143537952b86975004 # Parent 5a3ab27385ce91fb7091e2ed11da3e09be1251e8 more new template stuff diff -r 5a3ab27385ce -r 1d93a8cb2d8f MpdlXmlTextServer.py --- a/MpdlXmlTextServer.py Fri Aug 05 19:04:20 2011 +0200 +++ b/MpdlXmlTextServer.py Tue Aug 09 20:27:41 2011 +0200 @@ -29,12 +29,6 @@ """get the cdata content of a node""" if node is None: return "" - # ET: -# text = node.text or "" -# for e in node: -# text += gettext(e) -# if e.tail: -# text += e.tail # 4Suite: nodelist=node.childNodes @@ -187,8 +181,6 @@ if not docpath: return None - url = docinfo['url'] - selfurl = self.absolute_url() pn = pageinfo['current'] hrefList=[] myList= "" @@ -206,10 +198,6 @@ def getAllGisPlaces (self, docinfo=None, pageinfo=None): """Show all Gis Places of whole Book """ xpath ='//echo:place' - docpath =docinfo['textURLPath'] - url = docinfo['url'] - selfurl =self.absolute_url() - pn =pageinfo['current'] hrefList=[] myList="" text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'],xpath)) @@ -504,7 +492,7 @@ return docinfo - def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None): + def getTocPage(self, mode="text", pn=0, pageinfo=None, docinfo=None): """returns single page from the table of contents""" logging.debug("getTocPage mode=%s, pn=%s"%(mode,pn)) if mode == "text": @@ -521,14 +509,10 @@ logging.error("getTocPage: unable to find tocXML") return "No ToC" - pagesize = int(pageinfo['tocPageSize']) - url = docinfo['url'] - urlmode = docinfo['mode'] - selfurl = docinfo['viewerUrl'] - viewMode= pageinfo['viewMode'] - tocMode = pageinfo['tocMode'] - tocPN = int(pageinfo['tocPN']) - pn = tocPN + pagesize = pageinfo['tocPageSize'] + tocPN = pageinfo['tocPN'] + if not pn: + pn = tocPN fulltoc = ET.fromstring(tocxml) @@ -548,8 +532,9 @@ # take pn from href m = re.match(r'page-fragment\.xql.*pn=(\d+)', href) if m is not None: - # and create new url - l.set('href', '%s?mode=%s&url=%s&viewMode=%s&pn=%s&tocMode=%s&tocPN=%s'%(selfurl, urlmode, url, viewMode, m.group(1), tocMode, tocPN)) + # and create new url (assuming parent is documentViewer) + url = self.getLink('pn', m.group(1)) + l.set('href', url) else: logging.warning("getTocPage: Problem with link=%s"%href) diff -r 5a3ab27385ce -r 1d93a8cb2d8f documentViewer.py --- a/documentViewer.py Fri Aug 05 19:04:20 2011 +0200 +++ b/documentViewer.py Tue Aug 09 20:27:41 2011 +0200 @@ -582,7 +582,7 @@ docinfo['pageFlow'] = texttool.get('page-flow', 'ltr') # odd pages are left - docinfo['oddPage'] = texttool.get('odd-scan-orientation', 'left') + docinfo['oddPage'] = texttool.get('odd-scan-position', 'left') # number of title page (0: not defined) docinfo['titlePage'] = texttool.get('title-scan-no', 0) @@ -695,11 +695,10 @@ pageinfo['cols'] = cols grpsize = cols * rows pageinfo['groupsize'] = grpsize - # what does this do? + # is start is empty use one around current start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) # int(current / grpsize) * grpsize +1)) pageinfo['start'] = start - pageinfo['end'] = start + grpsize pn = self.REQUEST.get('pn','1') pageinfo['pn'] = pn np = int(docinfo.get('numPages', 0)) @@ -710,39 +709,74 @@ pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo) np = int(docinfo.get('numPages', 0)) - pageinfo['end'] = min(pageinfo['end'], np) pageinfo['numgroups'] = int(np / grpsize) if np % grpsize > 0: pageinfo['numgroups'] += 1 + + pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl' + oddScanLeft = docinfo.get('oddPage', 'left') != 'right' + # 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['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') pageinfo['query'] = self.REQUEST.get('query','') pageinfo['queryType'] = self.REQUEST.get('queryType','') pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') - pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30') - pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10') - pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') - # WTF?: - toc = int(pageinfo['tocPN']) - pageinfo['textPages'] = int(toc) + pageinfo['tocPageSize'] = getInt(self.REQUEST.get('tocPageSize', 30)) + pageinfo['queryPageSize'] = getInt(self.REQUEST.get('queryPageSize', 10)) + pageinfo['tocPN'] = getInt(self.REQUEST.get('tocPN', '1')) + pageinfo['searchPN'] = getInt(self.REQUEST.get('searchPN','1')) - # What does this do? + # limit tocPN if 'tocSize_%s'%tocMode in docinfo: - tocSize = int(docinfo['tocSize_%s'%tocMode]) - tocPageSize = int(pageinfo['tocPageSize']) + tocSize = docinfo['tocSize_%s'%tocMode] + tocPageSize = pageinfo['tocPageSize'] # cached toc if tocSize%tocPageSize>0: tocPages=tocSize/tocPageSize+1 else: tocPages=tocSize/tocPageSize - pageinfo['tocPN'] = min(tocPages,toc) + pageinfo['tocPN'] = min(tocPages,pageinfo['tocPN']) - pageinfo['searchPN'] =self.REQUEST.get('searchPN','1') 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""" + if maxIdx == 0: + maxIdx = start + rows * cols + + pages = [] + if pageZero and start == 1: + # correct beginning + idx = 0 + else: + idx = start + + for r in range(rows): + row = [] + for c in range(cols): + if idx < minIdx or idx > maxIdx: + page = {'idx':None} + else: + page = {'idx':idx} + + idx += 1 + if pageFlowLtr: + row.append(page) + else: + row.insert(0, page) + + pages.append(row) + + logging.debug("getPageList returns=%s"%(pages)) + return pages + + security.declareProtected('View management screens','changeDocumentViewerForm') changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())