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