comparison documentViewer.py @ 516:7d7b639d7be7

add methods to use doc-info.xql. read list of page numbers from doc-info.xql. add original page numbers to thumbs.
author casties
date Mon, 05 Mar 2012 18:04:49 +0100
parents c55e376be01b
children 91051b36b9cc
comparison
equal deleted inserted replaced
515:0afba3afd538 516:7d7b639d7be7
181 181
182 def getResultsPage(self, **args): 182 def getResultsPage(self, **args):
183 """returns one page of the search results""" 183 """returns one page of the search results"""
184 return self.template.fulltextclient.getResultsPage(**args) 184 return self.template.fulltextclient.getResultsPage(**args)
185 185
186 def getTextInfo(self, **args):
187 """returns document info from the text server"""
188 return self.template.fulltextclient.getTextInfo(**args)
189
186 def getToc(self, **args): 190 def getToc(self, **args):
187 """loads table of contents and stores XML in docinfo""" 191 """loads table of contents and stores XML in docinfo"""
188 return self.template.fulltextclient.getToc(**args) 192 return self.template.fulltextclient.getToc(**args)
189 193
190 def getTocPage(self, **args): 194 def getTocPage(self, **args):
477 481
478 # texttool info 482 # texttool info
479 texttool = self.metadataService.getTexttoolData(dom=metaDom) 483 texttool = self.metadataService.getTexttoolData(dom=metaDom)
480 if texttool: 484 if texttool:
481 docinfo = self.getDocinfoFromTexttool(docinfo, texttool) 485 docinfo = self.getDocinfoFromTexttool(docinfo, texttool)
486 # document info from full text
487 if docinfo.get('textURLPath', None):
488 docinfo = self.getTextInfo(docinfo=docinfo)
482 489
483 # bib info 490 # bib info
484 bib = self.metadataService.getBibData(dom=metaDom) 491 bib = self.metadataService.getBibData(dom=metaDom)
485 if bib: 492 if bib:
486 docinfo = self.getDocinfoFromBib(docinfo, bib) 493 docinfo = self.getDocinfoFromBib(docinfo, bib)
507 docinfo['copyright'] = copyright 514 docinfo['copyright'] = copyright
508 #docinfo = self.getDocinfoFromAccess(docinfo, access) 515 #docinfo = self.getDocinfoFromAccess(docinfo, access)
509 516
510 # image path 517 # image path
511 if mode != 'texttool': 518 if mode != 'texttool':
512 # override image path from texttool with url 519 # override image path from texttool with url TODO: how about mode=auto?
513 docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1) 520 docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1)
514 521
515 # number of images from digilib 522 # number of images from digilib
516 if docinfo.get('imagePath', None): 523 if docinfo.get('imagePath', None):
517 docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + docinfo['imagePath'] 524 docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + docinfo['imagePath']
518 docinfo = self.getDocinfoFromDigilib(docinfo, docinfo['imagePath']) 525 docinfo = self.getDocinfoFromDigilib(docinfo, docinfo['imagePath'])
526
527 # check numPages
528 if docinfo.get('numPages', 0) == 0:
529 if docinfo.get('numTextPages', 0) > 0:
530 # replace with numTextPages (text-only?)
531 docinfo['numPages'] = docinfo['numTextPages']
519 532
520 logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys()) 533 logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys())
521 #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) 534 #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo)
522 # store in session 535 # store in session
523 self.REQUEST.SESSION['docinfo'] = docinfo 536 self.REQUEST.SESSION['docinfo'] = docinfo
524 return docinfo 537 return docinfo
538
525 539
526 def getDocinfoFromResource(self, docinfo, resource): 540 def getDocinfoFromResource(self, docinfo, resource):
527 """reads contents of resource element into docinfo""" 541 """reads contents of resource element into docinfo"""
528 docName = resource.get('name', None) 542 docName = resource.get('name', None)
529 docinfo['documentName'] = docName 543 docinfo['documentName'] = docName
696 pageinfo['viewLayers'] = [viewLayer] 710 pageinfo['viewLayers'] = [viewLayer]
697 711
698 pageinfo['viewLayer'] = viewLayer 712 pageinfo['viewLayer'] = viewLayer
699 pageinfo['tocMode'] = tocMode 713 pageinfo['tocMode'] = tocMode
700 714
715 # TODO: unify current and pn!
701 current = getInt(current) 716 current = getInt(current)
702 pageinfo['current'] = current 717 pageinfo['current'] = current
703 pageinfo['pn'] = current 718 pageinfo['pn'] = current
704 rows = int(rows or self.thumbrows) 719 rows = int(rows or self.thumbrows)
705 pageinfo['rows'] = rows 720 pageinfo['rows'] = rows
713 pageinfo['start'] = start 728 pageinfo['start'] = start
714 # get number of pages 729 # get number of pages
715 np = int(docinfo.get('numPages', 0)) 730 np = int(docinfo.get('numPages', 0))
716 if np == 0: 731 if np == 0:
717 # numPages unknown - maybe we can get it from text page 732 # numPages unknown - maybe we can get it from text page
733 logging.warn("getPageInfo: numPages=0 trying getTextPage!")
718 if docinfo.get('textURLPath', None): 734 if docinfo.get('textURLPath', None):
719 # cache text page as well 735 # cache text page as well
720 pageinfo['textPage'] = self.getTextPage(mode=viewLayer, pn=current, docinfo=docinfo, pageinfo=pageinfo) 736 pageinfo['textPage'] = self.getTextPage(mode=viewLayer, pn=current, docinfo=docinfo, pageinfo=pageinfo)
721 np = int(docinfo.get('numPages', 0)) 737 np = int(docinfo.get('numPages', 0))
722 738
730 oddScanLeft = docinfo.get('oddPage', 'left') != 'right' 746 oddScanLeft = docinfo.get('oddPage', 'left') != 'right'
731 # add zeroth page for two columns 747 # add zeroth page for two columns
732 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) 748 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft))
733 pageinfo['pageZero'] = pageZero 749 pageinfo['pageZero'] = pageZero
734 pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) 750 pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
735 751 # more page parameters
736 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') 752 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
753 if docinfo.get('pageNumbers'):
754 # get original page numbers
755 pageNumber = docinfo['pageNumbers'].get(current, None)
756 if pageNumber is not None:
757 pageinfo['pageNumberOrig'] = pageNumber['no']
758 pageinfo['pageNumberOrigNorm'] = pageNumber['non']
737 759
738 # cache search results 760 # cache search results
739 pageinfo['resultPageSize'] = getInt(self.REQUEST.get('resultPageSize', 10)) 761 pageinfo['resultPageSize'] = getInt(self.REQUEST.get('resultPageSize', 10))
740 query = self.REQUEST.get('query',None) 762 query = self.REQUEST.get('query',None)
741 pageinfo['query'] = query 763 pageinfo['query'] = query