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