Mercurial > hg > documentViewer
comparison documentViewer.py @ 543:6cdc31e9ed8e
fixed problem with dict-mode in default view.
added configurable footer and logo in site_template.pt
author | casties |
---|---|
date | Wed, 22 Aug 2012 16:25:38 +0200 |
parents | c4cc01b104d7 |
children | 2928037f9a75 |
comparison
equal
deleted
inserted
replaced
542:dbaa7dce60a5 | 543:6cdc31e9ed8e |
---|---|
258 | 258 |
259 | 259 |
260 security.declareProtected('View','index_html') | 260 security.declareProtected('View','index_html') |
261 def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode="thumbs",start=1,pn=1): | 261 def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode="thumbs",start=1,pn=1): |
262 """ | 262 """ |
263 view page | 263 show page |
264 @param url: url which contains display information | 264 @param url: url which contains display information |
265 @param mode: defines how to access the document behind url | 265 @param mode: defines how to access the document behind url |
266 @param viewMode: 'images': display images, 'text': display text, 'xml': display xml, default is 'auto' | 266 @param viewMode: 'images': display images, 'text': display text, 'xml': display xml, default is 'auto' |
267 @param viewLayer: sub-type of viewMode, e.g. 'dict' for viewMode='text' | 267 @param viewLayer: sub-type of viewMode, e.g. layer 'dict' for viewMode='text' |
268 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) | 268 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
269 """ | 269 """ |
270 | 270 |
271 logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s"%(mode,url,viewMode,viewLayer,start,pn)) | 271 logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s"%(mode,url,viewMode,viewLayer,start,pn)) |
272 | 272 |
276 return "ERROR: template folder missing!" | 276 return "ERROR: template folder missing!" |
277 | 277 |
278 if not getattr(self, 'digilibBaseUrl', None): | 278 if not getattr(self, 'digilibBaseUrl', None): |
279 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" | 279 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
280 | 280 |
281 # docinfo: information about document (cached) | |
281 docinfo = self.getDocinfo(mode=mode,url=url,tocMode=tocMode) | 282 docinfo = self.getDocinfo(mode=mode,url=url,tocMode=tocMode) |
283 | |
284 # userinfo: user settings (cached) | |
285 userinfo = self.getUserinfo() | |
282 | 286 |
283 # auto viewMode: text if there is a text else images | 287 # auto viewMode: text if there is a text else images |
284 if viewMode=="auto": | 288 if viewMode=="auto": |
285 if docinfo.get('textURLPath', None): | 289 if docinfo.get('textURLPath', None): |
286 # docinfo.get('textURL', None) not implemented yet | 290 # docinfo.get('textURL', None) not implemented yet |
287 viewMode = "text" | 291 viewMode = "text" |
288 if viewLayer is None: | 292 if viewLayer is None and 'viewLayer' not in userinfo: |
293 # use layer dict as default | |
289 viewLayer = "dict" | 294 viewLayer = "dict" |
290 else: | 295 else: |
291 viewMode = "images" | 296 viewMode = "images" |
292 | 297 |
293 elif viewMode == "text_dict": | 298 elif viewMode == "text_dict": |
294 # legacy fix | 299 # legacy fix |
295 viewMode = "text" | 300 viewMode = "text" |
296 viewLayer = "dict" | 301 viewLayer = "dict" |
297 | 302 |
298 pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode) | 303 # safe viewLayer in userinfo |
304 userinfo['viewLayer'] = viewLayer | |
305 | |
306 # pageinfo: information about page (not cached) | |
307 pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, userinfo=userinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode) | |
299 | 308 |
300 # get template /template/viewer_$viewMode | 309 # get template /template/viewer_$viewMode |
301 pt = getattr(self.template, 'viewer_%s'%viewMode, None) | 310 pt = getattr(self.template, 'viewer_%s'%viewMode, None) |
302 if pt is None: | 311 if pt is None: |
303 logging.error("No template for viewMode=%s!"%viewMode) | 312 logging.error("No template for viewMode=%s!"%viewMode) |
492 | 501 |
493 logging.error("documentViewer (accessOK) unknown access type %s"%access) | 502 logging.error("documentViewer (accessOK) unknown access type %s"%access) |
494 return False | 503 return False |
495 | 504 |
496 | 505 |
506 def getUserinfo(self): | |
507 """returns userinfo object""" | |
508 logging.debug("getUserinfo") | |
509 userinfo = {} | |
510 # look for cached userinfo in session | |
511 if self.REQUEST.SESSION.has_key('userinfo'): | |
512 userinfo = self.REQUEST.SESSION['userinfo'] | |
513 # check if its still current? | |
514 else: | |
515 # store in session | |
516 self.REQUEST.SESSION['userinfo'] = userinfo | |
517 | |
518 return userinfo | |
519 | |
497 def getDocinfo(self, mode, url, tocMode=None): | 520 def getDocinfo(self, mode, url, tocMode=None): |
498 """returns docinfo depending on mode""" | 521 """returns docinfo depending on mode""" |
499 logging.debug("getDocinfo: mode=%s, url=%s"%(mode,url)) | 522 logging.debug("getDocinfo: mode=%s, url=%s"%(mode,url)) |
500 # look for cached docinfo in session | 523 # look for cached docinfo in session |
501 if self.REQUEST.SESSION.has_key('docinfo'): | 524 if self.REQUEST.SESSION.has_key('docinfo'): |
769 docinfo['title']=getText(dom.find(".//title")) | 792 docinfo['title']=getText(dom.find(".//title")) |
770 docinfo['date']=getText(dom.find(".//date")) | 793 docinfo['date']=getText(dom.find(".//date")) |
771 return docinfo | 794 return docinfo |
772 | 795 |
773 | 796 |
774 def getPageinfo(self, current=None, start=None, rows=None, cols=None, docinfo=None, viewMode=None, viewLayer=None, tocMode=None): | 797 def getPageinfo(self, current=None, start=None, rows=None, cols=None, docinfo=None, userinfo=None, viewMode=None, viewLayer=None, tocMode=None): |
775 """returns pageinfo with the given parameters""" | 798 """returns pageinfo with the given parameters""" |
776 logging.debug("getPageInfo(current=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(current,start,rows,cols,viewMode,viewLayer,tocMode)) | 799 logging.debug("getPageInfo(current=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(current,start,rows,cols,viewMode,viewLayer,tocMode)) |
777 pageinfo = {} | 800 pageinfo = {} |
778 pageinfo['viewMode'] = viewMode | 801 pageinfo['viewMode'] = viewMode |
779 # split viewLayer if necessary | 802 # split viewLayer if necessary |