Mercurial > hg > documentViewer
changeset 587:6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
author | casties |
---|---|
date | Thu, 15 Nov 2012 17:09:45 +0100 |
parents | 230ba358da3c |
children | e1034c2ca255 |
files | MpiwgXmlTextServer.py documentViewer.py version.txt zpt/layer_images_annotator.zpt zpt/layer_text_annotator.zpt |
diffstat | 5 files changed, 50 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/MpiwgXmlTextServer.py Tue Nov 13 18:20:43 2012 +0100 +++ b/MpiwgXmlTextServer.py Thu Nov 15 17:09:45 2012 +0100 @@ -197,10 +197,6 @@ if not docpath: return None - # just checking - if pageinfo['current'] != pn: - logging.warning("getTextPage: current!=pn!") - # stuff for constructing full urls selfurl = docinfo['viewerUrl'] textParams = {'docId': docpath,
--- a/documentViewer.py Tue Nov 13 18:20:43 2012 +0100 +++ b/documentViewer.py Thu Nov 15 17:09:45 2012 +0100 @@ -47,6 +47,22 @@ # split by /, shorten, and reassemble return '/'.join(path.split('/')[0:-cnt]) +def getPnForPf(docinfo, pf): + """returns image number for image file name or 0""" + if 'imgFileNames' in docinfo: + pn = docinfo['imgFileNames'].get(pf, None) + if pn is None: + # try to cut extension + xi = pf.rfind('.') + if xi > 0: + pf = pf[:xi] + # try again, else return 0 + pn = docinfo['imgFileNames'].get(pf, 0) + + return pn + + return 0 + ## ## documentViewer class @@ -204,7 +220,7 @@ docinfo = self.getDocinfo(mode=mode,url=url) #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) - pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo) + pageinfo = self.getPageinfo(start=start,pn=pn, docinfo=docinfo) ''' ZDES ''' pt = getattr(self.template, 'thumbs_main_rss') @@ -218,7 +234,7 @@ security.declareProtected('View','index_html') - def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode=None,start=1,pn=1): + def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode=None,start=None,pn=None,pf=None): """ show page @param url: url which contains display information @@ -228,7 +244,7 @@ @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) """ - logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s"%(mode,url,viewMode,viewLayer,start,pn)) + logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s pf=%s"%(mode,url,viewMode,viewLayer,start,pn,pf)) if not hasattr(self, 'template'): # this won't work @@ -271,7 +287,7 @@ userinfo['viewLayer'] = viewLayer # pageinfo: information about page (not cached) - pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, userinfo=userinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode) + pageinfo = self.getPageinfo(start=start, pn=pn, pf=pf, docinfo=docinfo, userinfo=userinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode) # get template /template/viewer_$viewMode pt = getattr(self.template, 'viewer_%s'%viewMode, None) @@ -451,7 +467,6 @@ logging.error("documentViewer (accessOK) unknown access type %s"%access) return False - def getUserinfo(self): """returns userinfo object""" logging.debug("getUserinfo") @@ -733,7 +748,7 @@ return docinfo def getDocinfoFromDigilib(self, docinfo, path): - infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path + infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?fn="+path # fetch data txt = getHttpData(infoUrl) if not txt: @@ -741,14 +756,24 @@ return docinfo dom = ET.fromstring(txt) - size = getText(dom.find("size")) + dir = dom + # save size + size = dir.findtext('size') logging.debug("getDocinfoFromDigilib: size=%s"%size) if size: docinfo['numPages'] = int(size) else: docinfo['numPages'] = 0 + return docinfo - # TODO: produce and keep list of image names and numbers + # save list of image names and numbers + imgNames = {} + for f in dir: + fn = f.findtext('name') + pn = f.findtext('index') + imgNames[fn] = getInt(pn) + + docinfo['imgFileNames'] = imgNames return docinfo @@ -766,7 +791,6 @@ metaUrl = url else: # online path - server=self.digilibBaseUrl+"/servlet/Texter?fn=" metaUrl=server+url @@ -782,9 +806,9 @@ return docinfo - def getPageinfo(self, current=None, start=None, rows=None, cols=None, docinfo=None, userinfo=None, viewMode=None, viewLayer=None, tocMode=None): + def getPageinfo(self, pn=None, pf=None, start=None, rows=None, cols=None, docinfo=None, userinfo=None, viewMode=None, viewLayer=None, tocMode=None): """returns pageinfo with the given parameters""" - logging.debug("getPageInfo(current=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(current,start,rows,cols,viewMode,viewLayer,tocMode)) + logging.debug("getPageInfo(pn=%s, pf=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(pn,pf,start,rows,cols,viewMode,viewLayer,tocMode)) pageinfo = {} pageinfo['viewMode'] = viewMode # split viewLayer if necessary @@ -807,17 +831,23 @@ pageinfo['tocMode'] = tocMode # TODO: unify current and pn! - current = getInt(current) - pageinfo['current'] = current - pageinfo['pn'] = current + #pageinfo['current'] = current + # pf takes precedence over pn + if pf: + pageinfo['pf'] = pf + pn = getPnForPf(docinfo, pf) + else: + pn = getInt(pn, 1) + + pageinfo['pn'] = pn rows = int(rows or self.thumbrows) pageinfo['rows'] = rows cols = int(cols or self.thumbcols) pageinfo['cols'] = cols grpsize = cols * rows pageinfo['groupsize'] = grpsize - # is start is empty use one around current - start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) + # is start is empty use one around pn + start = getInt(start, default=(math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1))) # int(current / grpsize) * grpsize +1)) pageinfo['start'] = start # get number of pages @@ -844,7 +874,7 @@ pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') if docinfo.get('pageNumbers'): # get original page numbers - pageNumber = docinfo['pageNumbers'].get(current, None) + pageNumber = docinfo['pageNumbers'].get(pn, None) if pageNumber is not None: pageinfo['pageNumberOrig'] = pageNumber['no'] pageinfo['pageNumberOrigNorm'] = pageNumber['non']
--- a/version.txt Tue Nov 13 18:20:43 2012 +0100 +++ b/version.txt Thu Nov 15 17:09:45 2012 +0100 @@ -1,1 +1,1 @@ -DocumentViewer 2.2.7 \ No newline at end of file +DocumentViewer 2.2.8 \ No newline at end of file
--- a/zpt/layer_images_annotator.zpt Tue Nov 13 18:20:43 2012 +0100 +++ b/zpt/layer_images_annotator.zpt Thu Nov 15 17:09:45 2012 +0100 @@ -72,7 +72,7 @@ </p> </form> <p tal:define="std modules/Products.PythonScripts.standard"> - <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">log in</a> + <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">Log in</a> </p> </div> <!-- END ANNOTATIONS -->
--- a/zpt/layer_text_annotator.zpt Tue Nov 13 18:20:43 2012 +0100 +++ b/zpt/layer_text_annotator.zpt Thu Nov 15 17:09:45 2012 +0100 @@ -125,8 +125,7 @@ </p> </form> <p tal:define="std modules/Products.PythonScripts.standard"> - <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">log in</a> - <!-- <a class="button" tal:attributes="href python:'%s/login/logout?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">log out</a> --> + <a class="button" tal:attributes="href python:'%s/login/login?came_from=%s'%(viewerUrl,std.url_quote(here.getLink()))">Log in</a> </p> </div> <!-- END ANNOTATIONS -->