comparison documentViewer.py @ 95:db6d594aa4d9

Last update with search function (getSearch)
author abukhman
date Mon, 19 Apr 2010 15:13:13 +0200
parents 6a4a72033d58
children a679c8c7148d
comparison
equal deleted inserted replaced
94:9d08a21fdd83 95:db6d594aa4d9
100 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) 100 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals())
101 security.declareProtected('View management screens','changeDocumentViewerForm') 101 security.declareProtected('View management screens','changeDocumentViewerForm')
102 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) 102 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
103 103
104 104
105 def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=10,authgroups="mpiwg"): 105 def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=5,authgroups="mpiwg"):
106 """init document viewer""" 106 """init document viewer"""
107 self.id=id 107 self.id=id
108 self.title=title 108 self.title=title
109 self.thumbcols = thumbcols 109 self.thumbcols = thumbcols
110 self.thumbrows = thumbrows 110 self.thumbrows = thumbrows
161 viewMode="images" 161 viewMode="images"
162 162
163 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) 163 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode)
164 164
165 security.declareProtected('View','index_html') 165 security.declareProtected('View','index_html')
166 def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None): 166 def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None, query=None, querySearch=None):
167 ''' 167 '''
168 view it 168 view it
169 @param mode: defines how to access the document behind url 169 @param mode: defines how to access the document behind url
170 @param url: url which contains display information 170 @param url: url which contains display information
171 @param viewMode: if images display images, if text display text, default is auto (text,images or auto) 171 @param viewMode: if images display images, if text display text, default is auto (text,images or auto)
172 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures) 172 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, search)
173 @param querySearch: type of different search modes (fulltext, fulltextMorph, xpath, xquery, ftIndex, ftIndexMorph)
173 ''' 174 '''
174 175
175 logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) 176 logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn))
176 177
177 if not hasattr(self, 'template'): 178 if not hasattr(self, 'template'):
647 if np % grpsize > 0: 648 if np % grpsize > 0:
648 pageinfo['numgroups'] += 1 649 pageinfo['numgroups'] += 1
649 650
650 pageinfo['viewMode'] = viewMode 651 pageinfo['viewMode'] = viewMode
651 pageinfo['tocMode'] = tocMode 652 pageinfo['tocMode'] = tocMode
652 pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '10') 653 pageinfo['query'] = self.REQUEST.get('query',' ')
654 pageinfo['queryType'] = self.REQUEST.get('queryType',' ')
655 pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext')
656 pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')
657 pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '20')
653 pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1') 658 pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')
659 pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')
660 pageinfo['sn'] =self.REQUEST.get('sn','1')
654 661
655 return pageinfo 662 return pageinfo
656 663
657 664 def getSearch(self, pn=1, pageinfo=None, docinfo=None, query=None, queryType=None):
665 """get search list"""
666 docpath = docinfo['textURLPath']
667 pagesize = pageinfo['queryPageSize']
668 pn = pageinfo['searchPN']
669 sn = pageinfo['sn']
670 query =pageinfo['query']
671 queryType =pageinfo['queryType']
672
673 pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn) ,outputUnicode=False)
674 pagedom = Parse(pagexml)
675 #pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
676
677 return pagexml
678 #if len(pagedivs) > 0:
679 # pagenode = pagedom[0]
680 # return serializeNode(pagenode)
681 #else:
682 # return "xaxa"
658 683
659 def getNumPages(self,docinfo=None): 684 def getNumPages(self,docinfo=None):
660 """get list of pages from fulltext and put in docinfo""" 685 """get list of pages from fulltext and put in docinfo"""
661 xquery = '//pb' 686 xquery = '//pb'
662 text = self.template.fulltextclient.eval("/mpdl/interface/xquery.xql", "document=%s&xquery=%s"%(docinfo['textURLPath'],xquery)) 687 text = self.template.fulltextclient.eval("/mpdl/interface/xquery.xql", "document=%s&xquery=%s"%(docinfo['textURLPath'],xquery))
671 textmode = "textPollux" 696 textmode = "textPollux"
672 else: 697 else:
673 textmode = mode 698 textmode = mode
674 699
675 pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn), outputUnicode=False) 700 pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", "document=%s&mode=%s&pn=%s"%(docpath,textmode,pn), outputUnicode=False)
701 #######
702 #textpython = pagexml.replace('page-fragment.xql?document=/echo/la/Benedetti_1585.xml','?url=/mpiwg/online/permanent/library/163127KK&tocMode='+str(tocMode)+'&queryResultPN='+str(queryResultPN)+'&viewMode='+str(viewMode))
703 #textnew =textpython.replace('mode=text','mode=texttool')
704 #######
676 # post-processing downloaded xml 705 # post-processing downloaded xml
677 pagedom = Parse(pagexml) 706 pagedom = Parse(pagexml)
678 # plain text mode 707 # plain text mode
679 if mode == "text": 708 if mode == "text":
680 # first div contains text 709 # first div contains text
681 pagedivs = pagedom.xpath("/div") 710 pagedivs = pagedom.xpath("/div")
711 #queryResultPage
682 if len(pagedivs) > 0: 712 if len(pagedivs) > 0:
683 pagenode = pagedivs[0] 713 pagenode = pagedivs[0]
684 return serializeNode(pagenode) 714 return serializeNode(pagenode)
685 715
686 # text-with-links mode 716 # text-with-links mode
739 769
740 docinfo['tocSize_%s'%mode] = tocSize 770 docinfo['tocSize_%s'%mode] = tocSize
741 #docinfo['tocDiv_%s'%mode] = tocDiv 771 #docinfo['tocDiv_%s'%mode] = tocDiv
742 return docinfo 772 return docinfo
743 773
744 def getTocPage(self, mode="toc", pn=1, pageinfo=None, docinfo=None): 774 def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None):
745 """returns single page from the table of contents""" 775 """returns single page from the table of contents"""
746 # TODO: this should use the cached TOC 776 # TODO: this should use the cached TOC
747 if mode == "text": 777 if mode == "text":
748 queryType = "toc" 778 queryType = "toc"
749 else: 779 else:
750 queryType = mode 780 queryType = mode
751 docpath = docinfo['textURLPath'] 781 docpath = docinfo['textURLPath']
752 pagesize = pageinfo['tocPageSize'] 782 pagesize = pageinfo['tocPageSize']
753 pn = pageinfo['tocPN'] 783 pn = pageinfo['tocPN']
754 pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False) 784 pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn), outputUnicode=False)
755 # post-processing downloaded xml 785 # post-processing downloaded xml
756 pagedom = Parse(pagexml) 786 pagedom = Parse(pagexml)
757 # div contains text 787 # div contains text
758 pagedivs = pagedom.xpath("//div[@class='queryResultPage']") 788 pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
759 if len(pagedivs) > 0: 789 if len(pagedivs) > 0:
761 return serializeNode(pagenode) 791 return serializeNode(pagenode)
762 else: 792 else:
763 return "No TOC!" 793 return "No TOC!"
764 794
765 795
766 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10,authgroups='mpiwg',RESPONSE=None): 796 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
767 """init document viewer""" 797 """init document viewer"""
768 self.title=title 798 self.title=title
769 self.digilibBaseUrl = digilibBaseUrl 799 self.digilibBaseUrl = digilibBaseUrl
770 self.thumbrows = thumbrows 800 self.thumbrows = thumbrows
771 self.thumbcols = thumbcols 801 self.thumbcols = thumbcols