Mercurial > hg > documentViewer
annotate documentViewer.py @ 525:70c3ae5eac7c
layers can have their own templates.
first version of annotations layer.
author | casties |
---|---|
date | Thu, 05 Apr 2012 19:29:50 +0200 |
parents | 91051b36b9cc |
children | 3f375a048402 |
rev | line source |
---|---|
0 | 1 from OFS.Folder import Folder |
2 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate | |
486 | 3 from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
487 | 4 from App.ImageFile import ImageFile |
0 | 5 from AccessControl import ClassSecurityInfo |
32 | 6 from AccessControl import getSecurityManager |
0 | 7 from Globals import package_home |
8 | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
9 import xml.etree.ElementTree as ET |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
10 |
489
55e3398e395e
more new templates. monkey-patch for App.ImageFile.
casties
parents:
488
diff
changeset
|
11 import os |
31 | 12 import sys |
0 | 13 import urllib |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
14 import logging |
61 | 15 import math |
46 | 16 import urlparse |
174 | 17 import re |
389 | 18 import string |
231 | 19 |
514 | 20 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml |
52 | 21 |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
22 def serializeNode(node, encoding="utf-8"): |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
23 """returns a string containing node as XML""" |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
24 s = ET.tostring(node) |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
25 |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
26 # 4Suite: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
27 # stream = cStringIO.StringIO() |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
28 # Ft.Xml.Domlette.Print(node, stream=stream, encoding=encoding) |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
29 # s = stream.getvalue() |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
30 # stream.close() |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
31 return s |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
32 |
387 | 33 def browserCheck(self): |
34 """check the browsers request to find out the browser type""" | |
35 bt = {} | |
36 ua = self.REQUEST.get_header("HTTP_USER_AGENT") | |
37 bt['ua'] = ua | |
38 bt['isIE'] = False | |
39 bt['isN4'] = False | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
40 bt['versFirefox']="" |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
41 bt['versIE']="" |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
42 bt['versSafariChrome']="" |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
43 bt['versOpera']="" |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
44 |
387 | 45 if string.find(ua, 'MSIE') > -1: |
46 bt['isIE'] = True | |
47 else: | |
48 bt['isN4'] = (string.find(ua, 'Mozilla/4.') > -1) | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
49 # Safari oder Chrome identification |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
50 try: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
51 nav = ua[string.find(ua, '('):] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
52 nav1=ua[string.find(ua,')'):] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
53 nav2=nav1[string.find(nav1,'('):] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
54 nav3=nav2[string.find(nav2,')'):] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
55 ie = string.split(nav, "; ")[1] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
56 ie1 =string.split(nav1, " ")[2] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
57 ie2 =string.split(nav3, " ")[1] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
58 ie3 =string.split(nav3, " ")[2] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
59 if string.find(ie3, "Safari") >-1: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
60 bt['versSafariChrome']=string.split(ie2, "/")[1] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
61 except: pass |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
62 # IE identification |
387 | 63 try: |
64 nav = ua[string.find(ua, '('):] | |
65 ie = string.split(nav, "; ")[1] | |
66 if string.find(ie, "MSIE") > -1: | |
67 bt['versIE'] = string.split(ie, " ")[1] | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
68 except:pass |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
69 # Firefox identification |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
70 try: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
71 nav = ua[string.find(ua, '('):] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
72 nav1=ua[string.find(ua,')'):] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
73 if string.find(ie1, "Firefox") >-1: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
74 nav5= string.split(ie1, "/")[1] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
75 logging.debug("FIREFOX: %s"%(nav5)) |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
76 bt['versFirefox']=nav5[0:3] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
77 except:pass |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
78 #Opera identification |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
79 try: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
80 if string.find(ua,"Opera") >-1: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
81 nav = ua[string.find(ua, '('):] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
82 nav1=nav[string.find(nav,')'):] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
83 bt['versOpera']=string.split(nav1,"/")[2] |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
84 except:pass |
387 | 85 |
86 bt['isMac'] = string.find(ua, 'Macintosh') > -1 | |
87 bt['isWin'] = string.find(ua, 'Windows') > -1 | |
88 bt['isIEWin'] = bt['isIE'] and bt['isWin'] | |
89 bt['isIEMac'] = bt['isIE'] and bt['isMac'] | |
90 bt['staticHTML'] = False | |
91 | |
92 return bt | |
234 | 93 |
464 | 94 def getParentPath(path, cnt=1): |
95 """returns pathname shortened by cnt""" | |
96 # make sure path doesn't end with / | |
97 path = path.rstrip('/') | |
98 # split by /, shorten, and reassemble | |
99 return '/'.join(path.split('/')[0:-cnt]) | |
100 | |
22 | 101 ## |
102 ## documentViewer class | |
103 ## | |
104 class documentViewer(Folder): | |
0 | 105 """document viewer""" |
106 meta_type="Document viewer" | |
107 | |
108 security=ClassSecurityInfo() | |
22 | 109 manage_options=Folder.manage_options+( |
507 | 110 {'label':'Configuration','action':'changeDocumentViewerForm'}, |
0 | 111 ) |
463 | 112 |
113 metadataService = None | |
114 """MetaDataFolder instance""" | |
525 | 115 |
0 | 116 |
525 | 117 # |
22 | 118 # templates and forms |
525 | 119 # |
120 # viewMode templates | |
479 | 121 viewer_text = PageTemplateFile('zpt/viewer_text', globals()) |
503 | 122 viewer_xml = PageTemplateFile('zpt/viewer_xml', globals()) |
483 | 123 viewer_images = PageTemplateFile('zpt/viewer_images', globals()) |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
124 viewer_index = PageTemplateFile('zpt/viewer_index', globals()) |
525 | 125 # available layer types |
126 availableLayers = {'text': ['dict','search','gis','annotator'], | |
127 'xml': None, 'images': None, 'index': None} | |
128 # layer templates | |
129 layer_text_annotator = PageTemplateFile('zpt/layer_text_annotator', globals()) | |
130 layer_text_gis = PageTemplateFile('zpt/layer_text_gis', globals()) | |
131 # toc templates | |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
132 toc_thumbs = PageTemplateFile('zpt/toc_thumbs', globals()) |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
133 toc_text = PageTemplateFile('zpt/toc_text', globals()) |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
134 toc_figures = PageTemplateFile('zpt/toc_figures', globals()) |
491 | 135 toc_none = PageTemplateFile('zpt/toc_none', globals()) |
525 | 136 # other templates |
501 | 137 common_template = PageTemplateFile('zpt/common_template', globals()) |
511 | 138 search_template = PageTemplateFile('zpt/search_template', globals()) |
57 | 139 info_xml = PageTemplateFile('zpt/info_xml', globals()) |
487 | 140 docuviewer_css = ImageFile('css/docuviewer.css',globals()) |
489
55e3398e395e
more new templates. monkey-patch for App.ImageFile.
casties
parents:
488
diff
changeset
|
141 # make ImageFile better for development |
490
6f116b86a226
more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents:
489
diff
changeset
|
142 docuviewer_css.index_html = refreshingImageFileIndexHtml |
501 | 143 jquery_js = ImageFile('js/jquery.js',globals()) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
144 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
145 |
95 | 146 def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=5,authgroups="mpiwg"): |
0 | 147 """init document viewer""" |
148 self.id=id | |
149 self.title=title | |
25 | 150 self.thumbcols = thumbcols |
151 self.thumbrows = thumbrows | |
32 | 152 # authgroups is list of authorized groups (delimited by ,) |
153 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
154 # create template folder so we can always use template.something |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
155 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
156 templateFolder = Folder('template') |
498 | 157 self['template'] = templateFolder # Zope-2.12 style |
158 #self._setObject('template',templateFolder) # old style | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
159 try: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
160 import MpdlXmlTextServer |
132 | 161 textServer = MpdlXmlTextServer.MpdlXmlTextServer(id='fulltextclient',serverName=textServerName) |
498 | 162 templateFolder['fulltextclient'] = textServer |
163 #templateFolder._setObject('fulltextclient',textServer) | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
164 except Exception, e: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
165 logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e)) |
463 | 166 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
167 try: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
168 from Products.zogiLib.zogiLib import zogiLib |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
169 zogilib = zogiLib(id="zogilib", title="zogilib for docuviewer", dlServerURL=imageScalerUrl, layout="book") |
498 | 170 templateFolder['zogilib'] = zogilib |
171 #templateFolder._setObject('zogilib',zogilib) | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
172 except Exception, e: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
173 logging.error("Unable to create zogiLib for zogilib: "+str(e)) |
463 | 174 |
175 try: | |
176 # assume MetaDataFolder instance is called metadata | |
177 self.metadataService = getattr(self, 'metadata') | |
178 except Exception, e: | |
179 logging.error("Unable to find MetaDataFolder 'metadata': "+str(e)) | |
180 | |
477 | 181 if digilibBaseUrl is not None: |
182 self.digilibBaseUrl = digilibBaseUrl | |
183 | |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
184 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
185 # proxy text server methods to fulltextclient |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
186 def getTextPage(self, **args): |
498 | 187 """returns full text content of page""" |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
188 return self.template.fulltextclient.getTextPage(**args) |
22 | 189 |
508 | 190 def getSearchResults(self, **args): |
191 """loads list of search results and stores XML in docinfo""" | |
192 return self.template.fulltextclient.getSearchResults(**args) | |
193 | |
194 def getResultsPage(self, **args): | |
195 """returns one page of the search results""" | |
196 return self.template.fulltextclient.getResultsPage(**args) | |
197 | |
516 | 198 def getTextInfo(self, **args): |
199 """returns document info from the text server""" | |
200 return self.template.fulltextclient.getTextInfo(**args) | |
201 | |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
202 def getToc(self, **args): |
508 | 203 """loads table of contents and stores XML in docinfo""" |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
204 return self.template.fulltextclient.getToc(**args) |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
205 |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
206 def getTocPage(self, **args): |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
207 """returns one page of the table of contents""" |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
208 return self.template.fulltextclient.getTocPage(**args) |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
209 |
506 | 210 def getPlacesOnPage(self, **args): |
211 """get list of gis places on one page""" | |
212 return self.template.fulltextclient.getPlacesOnPage(**args) | |
307 | 213 |
498 | 214 #WTF? |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
215 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) |
68 | 216 security.declareProtected('View','thumbs_rss') |
217 def thumbs_rss(self,mode,url,viewMode="auto",start=None,pn=1): | |
218 ''' | |
219 view it | |
220 @param mode: defines how to access the document behind url | |
221 @param url: url which contains display information | |
222 @param viewMode: if images display images, if text display text, default is images (text,images or auto) | |
223 | |
224 ''' | |
167 | 225 logging.debug("HHHHHHHHHHHHHH:load the rss") |
458 | 226 logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
68 | 227 |
228 if not hasattr(self, 'template'): | |
229 # create template folder if it doesn't exist | |
230 self.manage_addFolder('template') | |
231 | |
232 if not self.digilibBaseUrl: | |
233 self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | |
234 | |
235 docinfo = self.getDocinfo(mode=mode,url=url) | |
338 | 236 #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) |
345 | 237 pageinfo = self.getPageinfo(start=start,current=pn, docinfo=docinfo) |
331 | 238 ''' ZDES ''' |
68 | 239 pt = getattr(self.template, 'thumbs_main_rss') |
240 | |
241 if viewMode=="auto": # automodus gewaehlt | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
242 if docinfo.has_key("textURL") or docinfo.get('textURLPath',None): #texturl gesetzt und textViewer konfiguriert |
68 | 243 viewMode="text" |
244 else: | |
245 viewMode="images" | |
246 | |
247 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) | |
465 | 248 |
68 | 249 |
22 | 250 security.declareProtected('View','index_html') |
503 | 251 def index_html(self,url,mode="texttool",viewMode="auto",viewLayer=None,tocMode="thumbs",start=1,pn=1): |
464 | 252 """ |
471 | 253 view page |
254 @param url: url which contains display information | |
57 | 255 @param mode: defines how to access the document behind url |
503 | 256 @param viewMode: 'images': display images, 'text': display text, 'xml': display xml, default is 'auto' |
257 @param viewLayer: sub-type of viewMode, e.g. 'dict' for viewMode='text' | |
99 | 258 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
464 | 259 """ |
0 | 260 |
503 | 261 logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s"%(mode,url,viewMode,viewLayer,start,pn)) |
22 | 262 |
263 if not hasattr(self, 'template'): | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
264 # this won't work |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
265 logging.error("template folder missing!") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
266 return "ERROR: template folder missing!" |
22 | 267 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
268 if not getattr(self, 'digilibBaseUrl', None): |
132 | 269 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
22 | 270 |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
271 docinfo = self.getDocinfo(mode=mode,url=url,tocMode=tocMode) |
97 | 272 |
471 | 273 # auto viewMode: text if there is a text else images |
455 | 274 if viewMode=="auto": |
275 if docinfo.get('textURL', None) or docinfo.get('textURLPath', None): | |
471 | 276 viewMode = "text" |
508 | 277 if viewLayer is None: |
278 viewLayer = "dict" | |
51
c5d3aabbf61b
textviewer now integrated, new modus auto introduced as standard for viewing
dwinter
parents:
50
diff
changeset
|
279 else: |
471 | 280 viewMode = "images" |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
281 |
474 | 282 elif viewMode == "text_dict": |
283 # legacy fix | |
284 viewMode = "text" | |
503 | 285 viewLayer = "dict" |
474 | 286 |
503 | 287 pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode) |
469 | 288 |
475 | 289 # get template /template/viewer_$viewMode |
290 pt = getattr(self.template, 'viewer_%s'%viewMode, None) | |
291 if pt is None: | |
292 logging.error("No template for viewMode=%s!"%viewMode) | |
293 # TODO: error page? | |
294 return "No template for viewMode=%s!"%viewMode | |
295 | |
455 | 296 # and execute with parameters |
471 | 297 return pt(docinfo=docinfo, pageinfo=pageinfo) |
0 | 298 |
506 | 299 #WTF? |
74 | 300 def generateMarks(self,mk): |
301 ret="" | |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
302 if mk is None: |
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
303 return "" |
134 | 304 if not isinstance(mk, list): |
132 | 305 mk=[mk] |
74 | 306 for m in mk: |
75
9673218e155b
minorCVS: ----------------------------------------------------------------------
dwinter
parents:
74
diff
changeset
|
307 ret+="mk=%s"%m |
74 | 308 return ret |
389 | 309 |
310 | |
525 | 311 def getAvailableLayers(self): |
312 """returns dict with list of available layers per viewMode""" | |
313 return self.availableLayers | |
314 | |
387 | 315 def getBrowser(self): |
316 """getBrowser the version of browser """ | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
317 bt = browserCheck(self) |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
318 logging.debug("BROWSER VERSION: %s"%(bt)) |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
319 return bt |
387 | 320 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
321 def findDigilibUrl(self): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
322 """try to get the digilib URL from zogilib""" |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
323 url = self.template.zogilib.getDLBaseUrl() |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
324 return url |
480 | 325 |
326 def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None): | |
327 """returns URL to digilib Scaler with params""" | |
328 url = None | |
329 if docinfo is not None: | |
330 url = docinfo.get('imageURL', None) | |
331 | |
332 if url is None: | |
333 url = "%s/servlet/Scaler?"%self.digilibBaseUrl | |
334 if fn is None and docinfo is not None: | |
335 fn = docinfo.get('imagePath','') | |
336 | |
337 url += "fn=%s"%fn | |
338 | |
339 if pn: | |
340 url += "&pn=%s"%pn | |
341 | |
342 url += "&dw=%s&dh=%s"%(dw,dh) | |
343 return url | |
126 | 344 |
345 def getDocumentViewerURL(self): | |
346 """returns the URL of this instance""" | |
347 return self.absolute_url() | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
348 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
349 def getStyle(self, idx, selected, style=""): |
480 | 350 """returns a string with the given style and append 'sel' if idx == selected.""" |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
351 #logger("documentViewer (getstyle)", logging.INFO, "idx: %s selected: %s style: %s"%(idx,selected,style)) |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
352 if idx == selected: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
353 return style + 'sel' |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
354 else: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
355 return style |
74 | 356 |
478 | 357 def getParams(self, param=None, val=None, params=None, duplicates=None): |
469 | 358 """returns dict with URL parameters. |
359 | |
360 Takes URL parameters and additionally param=val or dict params. | |
361 Deletes key if value is None.""" | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
362 # copy existing request params |
469 | 363 newParams=self.REQUEST.form.copy() |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
364 # change single param |
25 | 365 if param is not None: |
31 | 366 if val is None: |
469 | 367 if newParams.has_key(param): |
368 del newParams[param] | |
25 | 369 else: |
469 | 370 newParams[param] = str(val) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
371 |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
372 # change more params |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
373 if params is not None: |
478 | 374 for (k, v) in params.items(): |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
375 if v is None: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
376 # val=None removes param |
469 | 377 if newParams.has_key(k): |
378 del newParams[k] | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
379 |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
380 else: |
469 | 381 newParams[k] = v |
478 | 382 |
383 if duplicates: | |
384 # eliminate lists (coming from duplicate keys) | |
385 for (k,v) in newParams.items(): | |
386 if isinstance(v, list): | |
387 if duplicates == 'comma': | |
388 # make comma-separated list of non-empty entries | |
389 newParams[k] = ','.join([t for t in v if t]) | |
390 elif duplicates == 'first': | |
391 # take first non-empty entry | |
392 newParams[k] = [t for t in v if t][0] | |
393 | |
469 | 394 return newParams |
395 | |
478 | 396 def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&', duplicates='comma'): |
469 | 397 """returns URL to documentviewer with parameter param set to val or from dict params""" |
478 | 398 urlParams = self.getParams(param=param, val=val, params=params, duplicates=duplicates) |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
399 # quote values and assemble into query string (not escaping '/') |
514 | 400 ps = paramSep.join(["%s=%s"%(k, urllib.quote_plus(utf8ify(v), '/')) for (k, v) in urlParams.items()]) |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
401 if baseUrl is None: |
469 | 402 baseUrl = self.getDocumentViewerURL() |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
403 |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
404 url = "%s?%s"%(baseUrl, ps) |
25 | 405 return url |
406 | |
478 | 407 def getLinkAmp(self, param=None, val=None, params=None, baseUrl=None, duplicates='comma'): |
68 | 408 """link to documentviewer with parameter param set to val""" |
478 | 409 return self.getLink(param=param, val=val, params=params, baseUrl=baseUrl, paramSep='&', duplicates=duplicates) |
81
fae97f071724
fixed problem with info.xml when url without index.meta
casties
parents:
79
diff
changeset
|
410 |
469 | 411 |
57 | 412 def getInfo_xml(self,url,mode): |
413 """returns info about the document as XML""" | |
414 if not self.digilibBaseUrl: | |
514 | 415 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
57 | 416 |
417 docinfo = self.getDocinfo(mode=mode,url=url) | |
418 pt = getattr(self.template, 'info_xml') | |
419 return pt(docinfo=docinfo) | |
420 | |
35 | 421 def isAccessible(self, docinfo): |
32 | 422 """returns if access to the resource is granted""" |
423 access = docinfo.get('accessType', None) | |
167 | 424 logging.debug("documentViewer (accessOK) access type %s"%access) |
465 | 425 if access == 'free': |
167 | 426 logging.debug("documentViewer (accessOK) access is free") |
32 | 427 return True |
465 | 428 |
45 | 429 elif access is None or access in self.authgroups: |
35 | 430 # only local access -- only logged in users |
431 user = getSecurityManager().getUser() | |
167 | 432 logging.debug("documentViewer (accessOK) user=%s ip=%s"%(user,self.REQUEST.getClientAddr())) |
35 | 433 if user is not None: |
434 #print "user: ", user | |
435 return (user.getUserName() != "Anonymous User") | |
436 else: | |
437 return False | |
32 | 438 |
167 | 439 logging.error("documentViewer (accessOK) unknown access type %s"%access) |
32 | 440 return False |
35 | 441 |
464 | 442 |
443 | |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
444 def getDocinfo(self, mode, url, tocMode=None): |
464 | 445 """returns docinfo depending on mode""" |
446 logging.debug("getDocinfo: mode=%s, url=%s"%(mode,url)) | |
447 # look for cached docinfo in session | |
448 if self.REQUEST.SESSION.has_key('docinfo'): | |
449 docinfo = self.REQUEST.SESSION['docinfo'] | |
450 # check if its still current | |
451 if docinfo is not None and docinfo.get('mode', None) == mode and docinfo.get('url', None) == url: | |
452 logging.debug("getDocinfo: docinfo in session. keys=%s"%docinfo.keys()) | |
453 return docinfo | |
454 | |
455 # new docinfo | |
456 docinfo = {'mode': mode, 'url': url} | |
457 # add self url | |
458 docinfo['viewerUrl'] = self.getDocumentViewerURL() | |
477 | 459 docinfo['digilibBaseUrl'] = self.digilibBaseUrl |
464 | 460 # get index.meta DOM |
461 docUrl = None | |
462 metaDom = None | |
463 if mode=="texttool": | |
464 # url points to document dir or index.meta | |
465 metaDom = self.metadataService.getDomFromPathOrUrl(url) | |
466 docUrl = url.replace('/index.meta', '') | |
467 if metaDom is None: | |
468 raise IOError("Unable to find index.meta for mode=texttool!") | |
469 | |
470 elif mode=="imagepath": | |
471 # url points to folder with images, index.meta optional | |
472 # asssume index.meta in parent dir | |
473 docUrl = getParentPath(url) | |
474 metaDom = self.metadataService.getDomFromPathOrUrl(docUrl) | |
475 | |
476 elif mode=="filepath": | |
477 # url points to image file, index.meta optional | |
478 # asssume index.meta is two path segments up | |
479 docUrl = getParentPath(url, 2) | |
480 metaDom = self.metadataService.getDomFromPathOrUrl(docUrl) | |
481 | |
482 else: | |
483 logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode) | |
484 raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) | |
485 | |
486 docinfo['documentUrl'] = docUrl | |
487 # process index.meta contents | |
473 | 488 if metaDom is not None and metaDom.tag == 'resource': |
464 | 489 # document directory name and path |
490 resource = self.metadataService.getResourceData(dom=metaDom) | |
491 if resource: | |
492 docinfo = self.getDocinfoFromResource(docinfo, resource) | |
493 | |
494 # texttool info | |
495 texttool = self.metadataService.getTexttoolData(dom=metaDom) | |
496 if texttool: | |
497 docinfo = self.getDocinfoFromTexttool(docinfo, texttool) | |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
498 # document info (including toc) from full text |
516 | 499 if docinfo.get('textURLPath', None): |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
500 docinfo = self.getTextInfo(mode=tocMode, docinfo=docinfo) |
464 | 501 |
502 # bib info | |
503 bib = self.metadataService.getBibData(dom=metaDom) | |
504 if bib: | |
505 docinfo = self.getDocinfoFromBib(docinfo, bib) | |
465 | 506 else: |
507 # no bib - try info.xml | |
508 docinfo = self.getDocinfoFromPresentationInfoXml(docinfo) | |
464 | 509 |
510 # auth info | |
511 access = self.metadataService.getAccessData(dom=metaDom) | |
512 if access: | |
513 docinfo = self.getDocinfoFromAccess(docinfo, access) | |
514 | |
466 | 515 # attribution info |
516 attribution = self.metadataService.getAttributionData(dom=metaDom) | |
517 if attribution: | |
518 logging.debug("getDocinfo: attribution=%s"%repr(attribution)) | |
519 docinfo['attribution'] = attribution | |
520 #docinfo = self.getDocinfoFromAccess(docinfo, access) | |
521 | |
522 # copyright info | |
523 copyright = self.metadataService.getCopyrightData(dom=metaDom) | |
524 if copyright: | |
525 logging.debug("getDocinfo: copyright=%s"%repr(copyright)) | |
526 docinfo['copyright'] = copyright | |
527 #docinfo = self.getDocinfoFromAccess(docinfo, access) | |
528 | |
464 | 529 # image path |
530 if mode != 'texttool': | |
516 | 531 # override image path from texttool with url TODO: how about mode=auto? |
465 | 532 docinfo['imagePath'] = url.replace('/mpiwg/online/', '', 1) |
464 | 533 |
534 # number of images from digilib | |
535 if docinfo.get('imagePath', None): | |
536 docinfo['imageURL'] = self.digilibBaseUrl + "/servlet/Scaler?fn=" + docinfo['imagePath'] | |
537 docinfo = self.getDocinfoFromDigilib(docinfo, docinfo['imagePath']) | |
538 | |
516 | 539 # check numPages |
540 if docinfo.get('numPages', 0) == 0: | |
541 if docinfo.get('numTextPages', 0) > 0: | |
542 # replace with numTextPages (text-only?) | |
543 docinfo['numPages'] = docinfo['numTextPages'] | |
544 | |
464 | 545 logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys()) |
546 #logging.debug("documentViewer (getdocinfo) docinfo: %s"%docinfo) | |
547 # store in session | |
548 self.REQUEST.SESSION['docinfo'] = docinfo | |
549 return docinfo | |
550 | |
516 | 551 |
464 | 552 def getDocinfoFromResource(self, docinfo, resource): |
553 """reads contents of resource element into docinfo""" | |
554 docName = resource.get('name', None) | |
555 docinfo['documentName'] = docName | |
556 docPath = resource.get('archive-path', None) | |
557 if docPath: | |
558 # clean up document path | |
559 if docPath[0] != '/': | |
560 docPath = '/' + docPath | |
561 | |
562 if docName and (not docPath.endswith(docName)): | |
563 docPath += "/" + docName | |
564 | |
565 else: | |
566 # use docUrl as docPath | |
567 docUrl = docinfo['documentURL'] | |
568 if not docUrl.startswith('http:'): | |
569 docPath = docUrl | |
465 | 570 if docPath: |
571 # fix URLs starting with /mpiwg/online | |
572 docPath = docPath.replace('/mpiwg/online', '', 1) | |
573 | |
464 | 574 docinfo['documentPath'] = docPath |
575 return docinfo | |
576 | |
577 def getDocinfoFromTexttool(self, docinfo, texttool): | |
578 """reads contents of texttool element into docinfo""" | |
579 # image dir | |
580 imageDir = texttool.get('image', None) | |
581 docPath = docinfo.get('documentPath', None) | |
582 if imageDir and docPath: | |
583 #print "image: ", imageDir, " archivepath: ", archivePath | |
584 imageDir = os.path.join(docPath, imageDir) | |
585 imageDir = imageDir.replace('/mpiwg/online', '', 1) | |
586 docinfo['imagePath'] = imageDir | |
587 | |
588 # old style text URL | |
589 textUrl = texttool.get('text', None) | |
590 if textUrl and docPath: | |
591 if urlparse.urlparse(textUrl)[0] == "": #keine url | |
592 textUrl = os.path.join(docPath, textUrl) | |
593 | |
594 docinfo['textURL'] = textUrl | |
595 | |
596 # new style text-url-path | |
597 textUrl = texttool.get('text-url-path', None) | |
598 if textUrl: | |
599 docinfo['textURLPath'] = textUrl | |
468 | 600 |
601 # page flow | |
602 docinfo['pageFlow'] = texttool.get('page-flow', 'ltr') | |
603 | |
604 # odd pages are left | |
476 | 605 docinfo['oddPage'] = texttool.get('odd-scan-position', 'left') |
468 | 606 |
469 | 607 # number of title page (0: not defined) |
468 | 608 docinfo['titlePage'] = texttool.get('title-scan-no', 0) |
464 | 609 |
610 # old presentation stuff | |
611 presentation = texttool.get('presentation', None) | |
612 if presentation and docPath: | |
465 | 613 if presentation.startswith('http:'): |
614 docinfo['presentationUrl'] = presentation | |
615 else: | |
616 docinfo['presentationUrl'] = os.path.join(docPath, presentation) | |
464 | 617 |
468 | 618 |
464 | 619 return docinfo |
620 | |
621 def getDocinfoFromBib(self, docinfo, bib): | |
622 """reads contents of bib element into docinfo""" | |
465 | 623 logging.debug("getDocinfoFromBib bib=%s"%repr(bib)) |
464 | 624 # put all raw bib fields in dict "bib" |
625 docinfo['bib'] = bib | |
626 bibtype = bib.get('@type', None) | |
627 docinfo['bibType'] = bibtype | |
628 # also store DC metadata for convenience | |
629 dc = self.metadataService.getDCMappedData(bib) | |
630 docinfo['creator'] = dc.get('creator',None) | |
631 docinfo['title'] = dc.get('title',None) | |
632 docinfo['date'] = dc.get('date',None) | |
633 return docinfo | |
634 | |
635 def getDocinfoFromAccess(self, docinfo, acc): | |
636 """reads contents of access element into docinfo""" | |
637 #TODO: also read resource type | |
465 | 638 logging.debug("getDocinfoFromAccess acc=%s"%repr(acc)) |
464 | 639 try: |
465 | 640 acctype = acc['@attr']['type'] |
464 | 641 if acctype: |
642 access=acctype | |
643 if access in ['group', 'institution']: | |
644 access = acc['name'].lower() | |
645 | |
646 docinfo['accessType'] = access | |
647 | |
648 except: | |
649 pass | |
650 | |
651 return docinfo | |
652 | |
653 def getDocinfoFromDigilib(self, docinfo, path): | |
654 infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?mo=dir&fn="+path | |
655 # fetch data | |
656 txt = getHttpData(infoUrl) | |
657 if not txt: | |
658 logging.error("Unable to get dir-info from %s"%(infoUrl)) | |
659 return docinfo | |
660 | |
661 dom = ET.fromstring(txt) | |
662 size = getText(dom.find("size")) | |
663 logging.debug("getDocinfoFromDigilib: size=%s"%size) | |
664 if size: | |
665 docinfo['numPages'] = int(size) | |
666 else: | |
667 docinfo['numPages'] = 0 | |
668 | |
669 # TODO: produce and keep list of image names and numbers | |
670 return docinfo | |
671 | |
672 | |
465 | 673 def getDocinfoFromPresentationInfoXml(self,docinfo): |
674 """gets DC-like bibliographical information from the presentation entry in texttools""" | |
675 url = docinfo.get('presentationUrl', None) | |
676 if not url: | |
677 logging.error("getDocinfoFromPresentation: no URL!") | |
678 return docinfo | |
679 | |
680 dom = None | |
681 metaUrl = None | |
682 if url.startswith("http://"): | |
683 # real URL | |
684 metaUrl = url | |
685 else: | |
686 # online path | |
687 | |
688 server=self.digilibBaseUrl+"/servlet/Texter?fn=" | |
689 metaUrl=server+url | |
690 | |
691 txt=getHttpData(metaUrl) | |
692 if txt is None: | |
693 logging.error("Unable to read info.xml from %s"%(url)) | |
694 return docinfo | |
695 | |
696 dom = ET.fromstring(txt) | |
697 docinfo['creator']=getText(dom.find(".//author")) | |
698 docinfo['title']=getText(dom.find(".//title")) | |
699 docinfo['date']=getText(dom.find(".//date")) | |
700 return docinfo | |
701 | |
702 | |
503 | 703 def getPageinfo(self, current=None, start=None, rows=None, cols=None, docinfo=None, viewMode=None, viewLayer=None, tocMode=None): |
22 | 704 """returns pageinfo with the given parameters""" |
503 | 705 logging.debug("getPageInfo(current=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(current,start,rows,cols,viewMode,viewLayer,tocMode)) |
22 | 706 pageinfo = {} |
471 | 707 pageinfo['viewMode'] = viewMode |
508 | 708 # split viewLayer if necessary |
709 if isinstance(viewLayer,basestring): | |
710 viewLayer = viewLayer.split(',') | |
711 | |
712 if isinstance(viewLayer, list): | |
713 logging.debug("getPageinfo: viewLayer is list:%s"%viewLayer) | |
714 # save (unique) list in viewLayers | |
715 seen = set() | |
716 viewLayers = [l for l in viewLayer if l and l not in seen and not seen.add(l)] | |
717 pageinfo['viewLayers'] = viewLayers | |
718 # stringify viewLayer | |
719 viewLayer = ','.join(viewLayers) | |
720 else: | |
721 #create list | |
722 pageinfo['viewLayers'] = [viewLayer] | |
723 | |
503 | 724 pageinfo['viewLayer'] = viewLayer |
471 | 725 pageinfo['tocMode'] = tocMode |
726 | |
516 | 727 # TODO: unify current and pn! |
25 | 728 current = getInt(current) |
729 pageinfo['current'] = current | |
480 | 730 pageinfo['pn'] = current |
25 | 731 rows = int(rows or self.thumbrows) |
732 pageinfo['rows'] = rows | |
733 cols = int(cols or self.thumbcols) | |
734 pageinfo['cols'] = cols | |
735 grpsize = cols * rows | |
736 pageinfo['groupsize'] = grpsize | |
476 | 737 # is start is empty use one around current |
61 | 738 start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1))) |
739 # int(current / grpsize) * grpsize +1)) | |
22 | 740 pageinfo['start'] = start |
511 | 741 # get number of pages |
469 | 742 np = int(docinfo.get('numPages', 0)) |
743 if np == 0: | |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
744 # try numTextPages |
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
745 np = docinfo.get('numTextPages', 0) |
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
746 if np != 0: |
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
747 docinfo['numPages'] = np |
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
748 |
511 | 749 # cache table of contents |
750 pageinfo['tocPageSize'] = getInt(self.REQUEST.get('tocPageSize', 30)) | |
469 | 751 pageinfo['numgroups'] = int(np / grpsize) |
752 if np % grpsize > 0: | |
753 pageinfo['numgroups'] += 1 | |
476 | 754 |
755 pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl' | |
756 oddScanLeft = docinfo.get('oddPage', 'left') != 'right' | |
757 # add zeroth page for two columns | |
758 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) | |
759 pageinfo['pageZero'] = pageZero | |
480 | 760 pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np) |
516 | 761 # more page parameters |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
762 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
516 | 763 if docinfo.get('pageNumbers'): |
764 # get original page numbers | |
765 pageNumber = docinfo['pageNumbers'].get(current, None) | |
766 if pageNumber is not None: | |
767 pageinfo['pageNumberOrig'] = pageNumber['no'] | |
768 pageinfo['pageNumberOrigNorm'] = pageNumber['non'] | |
158 | 769 |
511 | 770 # cache search results |
771 pageinfo['resultPageSize'] = getInt(self.REQUEST.get('resultPageSize', 10)) | |
772 query = self.REQUEST.get('query',None) | |
773 pageinfo['query'] = query | |
774 if query: | |
775 queryType = self.REQUEST.get('queryType', 'fulltextMorph') | |
776 pageinfo['queryType'] = queryType | |
777 pageinfo['resultStart'] = getInt(self.REQUEST.get('resultStart', '1')) | |
778 self.getSearchResults(mode=queryType, query=query, pageinfo=pageinfo, docinfo=docinfo) | |
779 | |
780 # highlighting | |
781 highlightQuery = self.REQUEST.get('highlightQuery', None) | |
782 if highlightQuery: | |
783 pageinfo['highlightQuery'] = highlightQuery | |
784 pageinfo['highlightElement'] = self.REQUEST.get('highlightElement', '') | |
785 pageinfo['highlightElementPos'] = self.REQUEST.get('highlightElementPos', '') | |
460 | 786 |
22 | 787 return pageinfo |
460 | 788 |
463 | 789 |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
790 def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): |
480 | 791 """returns dict with array of page informations for one screenfull of thumbnails""" |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
792 batch = {} |
480 | 793 grpsize = rows * cols |
476 | 794 if maxIdx == 0: |
480 | 795 maxIdx = start + grpsize |
476 | 796 |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
797 nb = int(math.ceil(maxIdx / float(grpsize))) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
798 # list of all batch start and end points |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
799 batches = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
800 if pageZero: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
801 ofs = 0 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
802 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
803 ofs = 1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
804 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
805 for i in range(nb): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
806 s = i * grpsize + ofs |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
807 e = min((i + 1) * grpsize + ofs - 1, maxIdx) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
808 batches.append({'start':s, 'end':e}) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
809 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
810 batch['batches'] = batches |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
811 |
476 | 812 pages = [] |
813 if pageZero and start == 1: | |
814 # correct beginning | |
815 idx = 0 | |
816 else: | |
817 idx = start | |
818 | |
819 for r in range(rows): | |
820 row = [] | |
821 for c in range(cols): | |
822 if idx < minIdx or idx > maxIdx: | |
823 page = {'idx':None} | |
824 else: | |
825 page = {'idx':idx} | |
826 | |
827 idx += 1 | |
828 if pageFlowLtr: | |
829 row.append(page) | |
830 else: | |
831 row.insert(0, page) | |
832 | |
833 pages.append(row) | |
834 | |
480 | 835 if start > 1: |
836 batch['prevStart'] = max(start - grpsize, 1) | |
837 else: | |
838 batch['prevStart'] = None | |
839 | |
840 if start + grpsize < maxIdx: | |
841 batch['nextStart'] = start + grpsize | |
842 else: | |
843 batch['nextStart'] = None | |
844 | |
845 batch['pages'] = pages | |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
846 return batch |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
847 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
848 def getBatch(self, start=1, size=10, end=0, data=None, fullData=True): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
849 """returns dict with information for one screenfull of data.""" |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
850 batch = {} |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
851 if end == 0: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
852 end = start + size |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
853 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
854 nb = int(math.ceil(end / float(size))) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
855 # list of all batch start and end points |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
856 batches = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
857 for i in range(nb): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
858 s = i * size + 1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
859 e = min((i + 1) * size, end) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
860 batches.append({'start':s, 'end':e}) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
861 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
862 batch['batches'] = batches |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
863 # list of elements in this batch |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
864 this = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
865 j = 0 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
866 for i in range(start, min(start+size, end)): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
867 if data: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
868 if fullData: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
869 d = data[i] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
870 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
871 d = data[j] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
872 j += 1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
873 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
874 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
875 d = i+1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
876 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
877 this.append(d) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
878 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
879 batch['this'] = this |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
880 if start > 1: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
881 batch['prevStart'] = max(start - size, 1) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
882 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
883 batch['prevStart'] = None |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
884 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
885 if start + size < end: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
886 batch['nextStart'] = start + size |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
887 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
888 batch['nextStart'] = None |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
889 |
480 | 890 return batch |
476 | 891 |
892 | |
463 | 893 security.declareProtected('View management screens','changeDocumentViewerForm') |
894 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) | |
22 | 895 |
460 | 896 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None): |
22 | 897 """init document viewer""" |
898 self.title=title | |
899 self.digilibBaseUrl = digilibBaseUrl | |
25 | 900 self.thumbrows = thumbrows |
901 self.thumbcols = thumbcols | |
32 | 902 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] |
463 | 903 try: |
904 # assume MetaDataFolder instance is called metadata | |
905 self.metadataService = getattr(self, 'metadata') | |
906 except Exception, e: | |
907 logging.error("Unable to find MetaDataFolder 'metadata': "+str(e)) | |
908 | |
22 | 909 if RESPONSE is not None: |
910 RESPONSE.redirect('manage_main') | |
0 | 911 |
912 def manage_AddDocumentViewerForm(self): | |
913 """add the viewer form""" | |
22 | 914 pt=PageTemplateFile('zpt/addDocumentViewer', globals()).__of__(self) |
0 | 915 return pt() |
916 | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
917 def manage_AddDocumentViewer(self,id,imageScalerUrl="",textServerName="",title="",RESPONSE=None): |
0 | 918 """add the viewer""" |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
919 newObj=documentViewer(id,imageScalerUrl=imageScalerUrl,title=title,textServerName=textServerName) |
0 | 920 self._setObject(id,newObj) |
921 | |
922 if RESPONSE is not None: | |
923 RESPONSE.redirect('manage_main') |