comparison documentViewer.py @ 480:50a28442f21c elementtree

more new template stuff
author casties
date Mon, 15 Aug 2011 21:09:08 +0200
parents fe5b0e4ac5f2
children 7ca8ac7db06e
comparison
equal deleted inserted replaced
479:fe5b0e4ac5f2 480:50a28442f21c
1 from OFS.Folder import Folder 1 from OFS.Folder import Folder
2 from OFS.Image import File
2 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate 3 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
3 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 4 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
4 from AccessControl import ClassSecurityInfo 5 from AccessControl import ClassSecurityInfo
5 from AccessControl import getSecurityManager 6 from AccessControl import getSecurityManager
6 from Globals import package_home 7 from Globals import package_home
133 page_main_text_dict = PageTemplateFile('zpt/page_main_text_dict', globals()) 134 page_main_text_dict = PageTemplateFile('zpt/page_main_text_dict', globals())
134 page_main_gis =PageTemplateFile ('zpt/page_main_gis', globals()) 135 page_main_gis =PageTemplateFile ('zpt/page_main_gis', globals())
135 page_main_xml = PageTemplateFile('zpt/page_main_xml', globals()) 136 page_main_xml = PageTemplateFile('zpt/page_main_xml', globals())
136 page_main_pureXml = PageTemplateFile('zpt/page_main_pureXml', globals()) 137 page_main_pureXml = PageTemplateFile('zpt/page_main_pureXml', globals())
137 head_main = PageTemplateFile('zpt/head_main', globals()) 138 head_main = PageTemplateFile('zpt/head_main', globals())
138 docuviewer_css = PageTemplateFile('css/docuviewer.css', globals())
139 info_xml = PageTemplateFile('zpt/info_xml', globals()) 139 info_xml = PageTemplateFile('zpt/info_xml', globals())
140 # TODO: can this be nicer?
141 docuviewer_css = File('docuviewer_css','',open(os.path.join(package_home(globals()),'css/docuviewer.css')), content_type='text/css')
140 142
141 143
142 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) 144 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals())
143 145
144 146
345 347
346 def findDigilibUrl(self): 348 def findDigilibUrl(self):
347 """try to get the digilib URL from zogilib""" 349 """try to get the digilib URL from zogilib"""
348 url = self.template.zogilib.getDLBaseUrl() 350 url = self.template.zogilib.getDLBaseUrl()
349 return url 351 return url
352
353 def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None):
354 """returns URL to digilib Scaler with params"""
355 url = None
356 if docinfo is not None:
357 url = docinfo.get('imageURL', None)
358
359 if url is None:
360 url = "%s/servlet/Scaler?"%self.digilibBaseUrl
361 if fn is None and docinfo is not None:
362 fn = docinfo.get('imagePath','')
363
364 url += "fn=%s"%fn
365
366 if pn:
367 url += "&pn=%s"%pn
368
369 url += "&dw=%s&dh=%s"%(dw,dh)
370 return url
350 371
351 def getDocumentViewerURL(self): 372 def getDocumentViewerURL(self):
352 """returns the URL of this instance""" 373 """returns the URL of this instance"""
353 return self.absolute_url() 374 return self.absolute_url()
354 375
355 def getStyle(self, idx, selected, style=""): 376 def getStyle(self, idx, selected, style=""):
356 """returns a string with the given style and append 'sel' if path == selected.""" 377 """returns a string with the given style and append 'sel' if idx == selected."""
357 #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) 378 #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style))
358 if idx == selected: 379 if idx == selected:
359 return style + 'sel' 380 return style + 'sel'
360 else: 381 else:
361 return style 382 return style
706 pageinfo['viewType'] = viewType 727 pageinfo['viewType'] = viewType
707 pageinfo['tocMode'] = tocMode 728 pageinfo['tocMode'] = tocMode
708 729
709 current = getInt(current) 730 current = getInt(current)
710 pageinfo['current'] = current 731 pageinfo['current'] = current
732 pageinfo['pn'] = current
711 rows = int(rows or self.thumbrows) 733 rows = int(rows or self.thumbrows)
712 pageinfo['rows'] = rows 734 pageinfo['rows'] = rows
713 cols = int(cols or self.thumbcols) 735 cols = int(cols or self.thumbcols)
714 pageinfo['cols'] = cols 736 pageinfo['cols'] = cols
715 grpsize = cols * rows 737 grpsize = cols * rows
716 pageinfo['groupsize'] = grpsize 738 pageinfo['groupsize'] = grpsize
717 # is start is empty use one around current 739 # is start is empty use one around current
718 start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) 740 start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))
719 # int(current / grpsize) * grpsize +1)) 741 # int(current / grpsize) * grpsize +1))
720 pageinfo['start'] = start 742 pageinfo['start'] = start
721 pn = self.REQUEST.get('pn','1') 743
722 pageinfo['pn'] = pn
723 np = int(docinfo.get('numPages', 0)) 744 np = int(docinfo.get('numPages', 0))
724 if np == 0: 745 if np == 0:
725 # numPages unknown - maybe we can get it from text page 746 # numPages unknown - maybe we can get it from text page
726 if docinfo.get('textURLPath', None): 747 if docinfo.get('textURLPath', None):
727 # cache text page as well 748 # cache text page as well
728 pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo) 749 pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=current, docinfo=docinfo, pageinfo=pageinfo)
729 np = int(docinfo.get('numPages', 0)) 750 np = int(docinfo.get('numPages', 0))
730 751
731 pageinfo['numgroups'] = int(np / grpsize) 752 pageinfo['numgroups'] = int(np / grpsize)
732 if np % grpsize > 0: 753 if np % grpsize > 0:
733 pageinfo['numgroups'] += 1 754 pageinfo['numgroups'] += 1
735 pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl' 756 pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl'
736 oddScanLeft = docinfo.get('oddPage', 'left') != 'right' 757 oddScanLeft = docinfo.get('oddPage', 'left') != 'right'
737 # add zeroth page for two columns 758 # add zeroth page for two columns
738 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) 759 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft))
739 pageinfo['pageZero'] = pageZero 760 pageinfo['pageZero'] = pageZero
740 pageinfo['pageList'] = self.getPageList(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) 761 pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
741 762
763 # TODO: do we need this here?
742 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') 764 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
743 pageinfo['query'] = self.REQUEST.get('query','') 765 pageinfo['query'] = self.REQUEST.get('query','')
744 pageinfo['queryType'] = self.REQUEST.get('queryType','') 766 pageinfo['queryType'] = self.REQUEST.get('queryType','')
745 pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') 767 pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext')
746 pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','') 768 pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','')
762 pageinfo['tocPN'] = min(tocPages,pageinfo['tocPN']) 784 pageinfo['tocPN'] = min(tocPages,pageinfo['tocPN'])
763 785
764 return pageinfo 786 return pageinfo
765 787
766 788
767 def getPageList(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): 789 def getPageBatch(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
768 """returns array of page informations for one screenfull of thumbnails""" 790 """returns dict with array of page informations for one screenfull of thumbnails"""
791 grpsize = rows * cols
769 if maxIdx == 0: 792 if maxIdx == 0:
770 maxIdx = start + rows * cols 793 maxIdx = start + grpsize
771 794
772 pages = [] 795 pages = []
773 if pageZero and start == 1: 796 if pageZero and start == 1:
774 # correct beginning 797 # correct beginning
775 idx = 0 798 idx = 0
790 else: 813 else:
791 row.insert(0, page) 814 row.insert(0, page)
792 815
793 pages.append(row) 816 pages.append(row)
794 817
795 logging.debug("getPageList returns=%s"%(pages)) 818 batch = {}
796 return pages 819 if start > 1:
820 batch['prevStart'] = max(start - grpsize, 1)
821 else:
822 batch['prevStart'] = None
823
824 if start + grpsize < maxIdx:
825 batch['nextStart'] = start + grpsize
826 else:
827 batch['nextStart'] = None
828
829 batch['pages'] = pages
830 #logging.debug("getPageList returns=%s"%(batch))
831 return batch
797 832
798 833
799 security.declareProtected('View management screens','changeDocumentViewerForm') 834 security.declareProtected('View management screens','changeDocumentViewerForm')
800 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) 835 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
801 836