Mercurial > hg > documentViewer
annotate documentViewer.py @ 613:c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/281
author | casties |
---|---|
date | Thu, 17 Oct 2013 16:25:39 +0200 |
parents | a79e4e4b3e37 |
children | d6eca930a534 7aefbddddaf9 |
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 |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
8 import xml.etree.ElementTree as ET |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
9 |
489
55e3398e395e
more new templates. monkey-patch for App.ImageFile.
casties
parents:
488
diff
changeset
|
10 import os |
0 | 11 import urllib |
50
6c0f20cecc60
added evaluation of the presentation/info.xml in texttools
dwinter
parents:
49
diff
changeset
|
12 import logging |
61 | 13 import math |
46 | 14 import urlparse |
526 | 15 import json |
231 | 16 |
541 | 17 from Products.MetaDataProvider import MetaDataFolder |
18 | |
514 | 19 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml |
52 | 20 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
21 |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
22 def getMDText(node): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
23 """returns the @text content from the MetaDataProvider metadata node""" |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
24 if isinstance(node, dict): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
25 return node.get('@text', None) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
26 |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
27 return node |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
28 |
464 | 29 def getParentPath(path, cnt=1): |
30 """returns pathname shortened by cnt""" | |
31 # make sure path doesn't end with / | |
32 path = path.rstrip('/') | |
33 # split by /, shorten, and reassemble | |
34 return '/'.join(path.split('/')[0:-cnt]) | |
35 | |
589 | 36 def getPnForPf(docinfo, pf, default=0): |
37 """returns image number for image file name or default""" | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
38 if 'imgFileNames' in docinfo: |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
39 pn = docinfo['imgFileNames'].get(pf, None) |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
40 if pn is None: |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
41 # try to cut extension |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
42 xi = pf.rfind('.') |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
43 if xi > 0: |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
44 pf = pf[:xi] |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
45 # try again, else return 0 |
589 | 46 pn = docinfo['imgFileNames'].get(pf, default) |
47 else: | |
48 # no extension | |
49 pn = default | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
50 |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
51 return pn |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
52 |
589 | 53 return default |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
54 |
591 | 55 def getPfForPn(docinfo, pn, default=None): |
56 """returns image file name for image number or default""" | |
57 if 'imgFileIndexes' in docinfo: | |
58 pn = docinfo['imgFileIndexes'].get(pn, default) | |
59 return pn | |
60 | |
61 return default | |
62 | |
585 | 63 |
22 | 64 ## |
65 ## documentViewer class | |
66 ## | |
67 class documentViewer(Folder): | |
0 | 68 """document viewer""" |
69 meta_type="Document viewer" | |
70 | |
71 security=ClassSecurityInfo() | |
22 | 72 manage_options=Folder.manage_options+( |
507 | 73 {'label':'Configuration','action':'changeDocumentViewerForm'}, |
0 | 74 ) |
463 | 75 |
76 metadataService = None | |
77 """MetaDataFolder instance""" | |
525 | 78 |
0 | 79 |
525 | 80 # |
22 | 81 # templates and forms |
525 | 82 # |
83 # viewMode templates | |
594 | 84 viewer_text = PageTemplateFile('zpt/viewer/viewer_text', globals()) |
85 viewer_xml = PageTemplateFile('zpt/viewer/viewer_xml', globals()) | |
86 viewer_image = PageTemplateFile('zpt/viewer/viewer_image', globals()) | |
87 viewer_index = PageTemplateFile('zpt/viewer/viewer_index', globals()) | |
88 viewer_thumbs = PageTemplateFile('zpt/viewer/viewer_thumbs', globals()) | |
89 viewer_indexonly = PageTemplateFile('zpt/viewer/viewer_indexonly', globals()) | |
546 | 90 # available layer types (annotator not default) |
91 builtinLayers = {'text': ['dict','search','gis'], | |
590 | 92 'xml': None, 'image': None, 'index': ['extended']} |
526 | 93 availableLayers = builtinLayers; |
525 | 94 # layer templates |
594 | 95 layer_text_dict = PageTemplateFile('zpt/viewer/layer_text_dict', globals()) |
96 layer_text_search = PageTemplateFile('zpt/viewer/layer_text_search', globals()) | |
97 layer_text_annotator = PageTemplateFile('zpt/viewer/layer_text_annotator', globals()) | |
98 layer_text_gis = PageTemplateFile('zpt/viewer/layer_text_gis', globals()) | |
99 layer_text_pundit = PageTemplateFile('zpt/viewer/layer_text_pundit', globals()) | |
100 layer_image_annotator = PageTemplateFile('zpt/viewer/layer_image_annotator', globals()) | |
101 layer_image_search = PageTemplateFile('zpt/viewer/layer_image_search', globals()) | |
102 layer_index_extended = PageTemplateFile('zpt/viewer/layer_index_extended', globals()) | |
525 | 103 # toc templates |
594 | 104 toc_thumbs = PageTemplateFile('zpt/viewer/toc_thumbs', globals()) |
105 toc_text = PageTemplateFile('zpt/viewer/toc_text', globals()) | |
106 toc_figures = PageTemplateFile('zpt/viewer/toc_figures', globals()) | |
107 toc_concordance = PageTemplateFile('zpt/viewer/toc_concordance', globals()) | |
609 | 108 toc_notes = PageTemplateFile('zpt/viewer/toc_notes', globals()) |
594 | 109 toc_handwritten = PageTemplateFile('zpt/viewer/toc_handwritten', globals()) |
110 toc_none = PageTemplateFile('zpt/viewer/toc_none', globals()) | |
525 | 111 # other templates |
594 | 112 common_template = PageTemplateFile('zpt/viewer/common_template', globals()) |
113 info_xml = PageTemplateFile('zpt/viewer/info_xml', globals()) | |
487 | 114 docuviewer_css = ImageFile('css/docuviewer.css',globals()) |
532 | 115 # make docuviewer_css refreshable for development |
490
6f116b86a226
more new template stuff. moved ImageFile index method to SrvTxtUtils
casties
parents:
489
diff
changeset
|
116 docuviewer_css.index_html = refreshingImageFileIndexHtml |
535
510bae2b593b
more fixes, e.g. IE support. first version of index page.
casties
parents:
532
diff
changeset
|
117 docuviewer_ie_css = ImageFile('css/docuviewer_ie.css',globals()) |
510bae2b593b
more fixes, e.g. IE support. first version of index page.
casties
parents:
532
diff
changeset
|
118 # make docuviewer_ie_css refreshable for development |
585 | 119 #docuviewer_ie_css.index_html = refreshingImageFileIndexHtml |
501 | 120 jquery_js = ImageFile('js/jquery.js',globals()) |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
121 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
122 |
95 | 123 def __init__(self,id,imageScalerUrl=None,textServerName=None,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=5,authgroups="mpiwg"): |
0 | 124 """init document viewer""" |
125 self.id=id | |
126 self.title=title | |
25 | 127 self.thumbcols = thumbcols |
128 self.thumbrows = thumbrows | |
32 | 129 # authgroups is list of authorized groups (delimited by ,) |
130 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
|
131 # 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
|
132 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
133 templateFolder = Folder('template') |
498 | 134 self['template'] = templateFolder # Zope-2.12 style |
135 #self._setObject('template',templateFolder) # old style | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
136 try: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
137 import MpdlXmlTextServer |
132 | 138 textServer = MpdlXmlTextServer.MpdlXmlTextServer(id='fulltextclient',serverName=textServerName) |
498 | 139 templateFolder['fulltextclient'] = textServer |
140 #templateFolder._setObject('fulltextclient',textServer) | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
141 except Exception, e: |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
142 logging.error("Unable to create MpdlXmlTextServer for fulltextclient: "+str(e)) |
463 | 143 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
144 try: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
145 from Products.zogiLib.zogiLib import zogiLib |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
146 zogilib = zogiLib(id="zogilib", title="zogilib for docuviewer", dlServerURL=imageScalerUrl, layout="book") |
498 | 147 templateFolder['zogilib'] = zogilib |
148 #templateFolder._setObject('zogilib',zogilib) | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
149 except Exception, e: |
607 | 150 logging.error("Unable to create zogiLib for 'zogilib': "+str(e)) |
463 | 151 |
152 try: | |
153 # assume MetaDataFolder instance is called metadata | |
154 self.metadataService = getattr(self, 'metadata') | |
155 except Exception, e: | |
156 logging.error("Unable to find MetaDataFolder 'metadata': "+str(e)) | |
157 | |
477 | 158 if digilibBaseUrl is not None: |
159 self.digilibBaseUrl = digilibBaseUrl | |
566 | 160 self.digilibScalerUrl = digilibBaseUrl + '/servlet/Scaler' |
161 self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html' | |
477 | 162 |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
163 |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
164 # proxy text server methods to fulltextclient |
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
165 def getTextPage(self, **args): |
498 | 166 """returns full text content of page""" |
130
5c779d7b5f71
more modular version with separate object MpdlXmlTextServer
casties
parents:
128
diff
changeset
|
167 return self.template.fulltextclient.getTextPage(**args) |
22 | 168 |
508 | 169 def getSearchResults(self, **args): |
170 """loads list of search results and stores XML in docinfo""" | |
171 return self.template.fulltextclient.getSearchResults(**args) | |
172 | |
173 def getResultsPage(self, **args): | |
174 """returns one page of the search results""" | |
175 return self.template.fulltextclient.getResultsPage(**args) | |
176 | |
516 | 177 def getTextInfo(self, **args): |
178 """returns document info from the text server""" | |
179 return self.template.fulltextclient.getTextInfo(**args) | |
180 | |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
181 def getToc(self, **args): |
508 | 182 """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
|
183 return self.template.fulltextclient.getToc(**args) |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
184 |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
185 def getTocPage(self, **args): |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
186 """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
|
187 return self.template.fulltextclient.getTocPage(**args) |
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
188 |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
189 def getRepositoryType(self, **args): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
190 """get repository type""" |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
191 return self.template.fulltextclient.getRepositoryType(**args) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
192 |
559 | 193 def getTextDownloadUrl(self, **args): |
610 | 194 """get URL to download the full text""" |
559 | 195 return self.template.fulltextclient.getTextDownloadUrl(**args) |
196 | |
506 | 197 def getPlacesOnPage(self, **args): |
198 """get list of gis places on one page""" | |
199 return self.template.fulltextclient.getPlacesOnPage(**args) | |
307 | 200 |
548 | 201 # Thumb list for CoolIris Plugin |
499
3f9703746fef
more cleanup. new template for viewMode=index (not pretty so far).
casties
parents:
498
diff
changeset
|
202 thumbs_main_rss = PageTemplateFile('zpt/thumbs_main_rss', globals()) |
68 | 203 security.declareProtected('View','thumbs_rss') |
204 def thumbs_rss(self,mode,url,viewMode="auto",start=None,pn=1): | |
205 ''' | |
206 view it | |
207 @param mode: defines how to access the document behind url | |
208 @param url: url which contains display information | |
590 | 209 @param viewMode: image: display images, text: display text, default is auto (try text, else image) |
68 | 210 |
211 ''' | |
212 | |
213 if not hasattr(self, 'template'): | |
590 | 214 # this won't work |
215 logging.error("template folder missing!") | |
216 return "ERROR: template folder missing!" | |
217 | |
68 | 218 if not self.digilibBaseUrl: |
219 self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | |
220 | |
221 docinfo = self.getDocinfo(mode=mode,url=url) | |
338 | 222 #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
223 pageinfo = self.getPageinfo(start=start,pn=pn, docinfo=docinfo) |
331 | 224 ''' ZDES ''' |
68 | 225 pt = getattr(self.template, 'thumbs_main_rss') |
226 | |
227 if viewMode=="auto": # automodus gewaehlt | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
228 if docinfo.has_key("textURL") or docinfo.get('textURLPath',None): #texturl gesetzt und textViewer konfiguriert |
68 | 229 viewMode="text" |
230 else: | |
590 | 231 viewMode="image" |
68 | 232 |
233 return pt(docinfo=docinfo,pageinfo=pageinfo,viewMode=viewMode) | |
465 | 234 |
68 | 235 |
22 | 236 security.declareProtected('View','index_html') |
589 | 237 def index_html(self, url, mode="texttool", viewMode="auto", viewLayer=None, tocMode=None, start=None, pn=None, pf=None): |
464 | 238 """ |
543 | 239 show page |
471 | 240 @param url: url which contains display information |
57 | 241 @param mode: defines how to access the document behind url |
590 | 242 @param viewMode: 'image': display images, 'text': display text, 'xml': display xml, default is 'auto' |
543 | 243 @param viewLayer: sub-type of viewMode, e.g. layer 'dict' for viewMode='text' |
99 | 244 @param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
464 | 245 """ |
0 | 246 |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
247 logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewLayer=%s start=%s pn=%s pf=%s"%(mode,url,viewMode,viewLayer,start,pn,pf)) |
22 | 248 |
249 if not hasattr(self, 'template'): | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
250 # this won't work |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
251 logging.error("template folder missing!") |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
252 return "ERROR: template folder missing!" |
22 | 253 |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
254 if not getattr(self, 'digilibBaseUrl', None): |
132 | 255 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
22 | 256 |
548 | 257 # mode=filepath should not have toc-thumbs |
258 if tocMode is None: | |
259 if mode == "filepath": | |
260 tocMode = "none" | |
261 else: | |
262 tocMode = "thumbs" | |
263 | |
543 | 264 # docinfo: information about document (cached) |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
265 docinfo = self.getDocinfo(mode=mode,url=url,tocMode=tocMode) |
97 | 266 |
543 | 267 # userinfo: user settings (cached) |
268 userinfo = self.getUserinfo() | |
269 | |
471 | 270 # auto viewMode: text if there is a text else images |
455 | 271 if viewMode=="auto": |
530 | 272 if docinfo.get('textURLPath', None): |
273 # docinfo.get('textURL', None) not implemented yet | |
471 | 274 viewMode = "text" |
543 | 275 if viewLayer is None and 'viewLayer' not in userinfo: |
276 # use layer dict as default | |
508 | 277 viewLayer = "dict" |
51
c5d3aabbf61b
textviewer now integrated, new modus auto introduced as standard for viewing
dwinter
parents:
50
diff
changeset
|
278 else: |
590 | 279 viewMode = "image" |
90
6a4a72033d58
new version with new full-text infrastructure and some more changed templates
casties
parents:
84
diff
changeset
|
280 |
474 | 281 elif viewMode == "text_dict": |
282 # legacy fix | |
283 viewMode = "text" | |
503 | 284 viewLayer = "dict" |
474 | 285 |
590 | 286 elif viewMode == 'images': |
287 # legacy fix | |
288 viewMode = 'image' | |
289 self.REQUEST['viewMode'] = 'image' | |
290 | |
543 | 291 # safe viewLayer in userinfo |
292 userinfo['viewLayer'] = viewLayer | |
548 | 293 |
543 | 294 # pageinfo: information about page (not cached) |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
295 pageinfo = self.getPageinfo(start=start, pn=pn, pf=pf, docinfo=docinfo, userinfo=userinfo, viewMode=viewMode, viewLayer=viewLayer, tocMode=tocMode) |
469 | 296 |
475 | 297 # get template /template/viewer_$viewMode |
298 pt = getattr(self.template, 'viewer_%s'%viewMode, None) | |
299 if pt is None: | |
300 logging.error("No template for viewMode=%s!"%viewMode) | |
301 # TODO: error page? | |
302 return "No template for viewMode=%s!"%viewMode | |
303 | |
455 | 304 # and execute with parameters |
471 | 305 return pt(docinfo=docinfo, pageinfo=pageinfo) |
0 | 306 |
525 | 307 def getAvailableLayers(self): |
308 """returns dict with list of available layers per viewMode""" | |
309 return self.availableLayers | |
310 | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
311 def findDigilibUrl(self): |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
312 """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
|
313 url = self.template.zogilib.getDLBaseUrl() |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
314 return url |
480 | 315 |
316 def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None): | |
317 """returns URL to digilib Scaler with params""" | |
318 url = None | |
319 if docinfo is not None: | |
320 url = docinfo.get('imageURL', None) | |
321 | |
322 if url is None: | |
566 | 323 url = self.digilibScalerUrl |
480 | 324 if fn is None and docinfo is not None: |
325 fn = docinfo.get('imagePath','') | |
326 | |
327 url += "fn=%s"%fn | |
328 | |
329 if pn: | |
330 url += "&pn=%s"%pn | |
331 | |
332 url += "&dw=%s&dh=%s"%(dw,dh) | |
333 return url | |
126 | 334 |
335 def getDocumentViewerURL(self): | |
336 """returns the URL of this instance""" | |
337 return self.absolute_url() | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
338 |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
339 def getStyle(self, idx, selected, style=""): |
480 | 340 """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
|
341 #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
|
342 if idx == selected: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
343 return style + 'sel' |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
344 else: |
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
345 return style |
74 | 346 |
478 | 347 def getParams(self, param=None, val=None, params=None, duplicates=None): |
469 | 348 """returns dict with URL parameters. |
349 | |
350 Takes URL parameters and additionally param=val or dict params. | |
351 Deletes key if value is None.""" | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
352 # copy existing request params |
469 | 353 newParams=self.REQUEST.form.copy() |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
354 # change single param |
25 | 355 if param is not None: |
31 | 356 if val is None: |
469 | 357 if newParams.has_key(param): |
358 del newParams[param] | |
25 | 359 else: |
469 | 360 newParams[param] = str(val) |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
361 |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
362 # change more params |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
363 if params is not None: |
478 | 364 for (k, v) in params.items(): |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
365 if v is None: |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
366 # val=None removes param |
469 | 367 if newParams.has_key(k): |
368 del newParams[k] | |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
369 |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
370 else: |
469 | 371 newParams[k] = v |
478 | 372 |
373 if duplicates: | |
374 # eliminate lists (coming from duplicate keys) | |
375 for (k,v) in newParams.items(): | |
376 if isinstance(v, list): | |
377 if duplicates == 'comma': | |
378 # make comma-separated list of non-empty entries | |
379 newParams[k] = ','.join([t for t in v if t]) | |
380 elif duplicates == 'first': | |
381 # take first non-empty entry | |
382 newParams[k] = [t for t in v if t][0] | |
383 | |
469 | 384 return newParams |
385 | |
478 | 386 def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&', duplicates='comma'): |
469 | 387 """returns URL to documentviewer with parameter param set to val or from dict params""" |
478 | 388 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
|
389 # quote values and assemble into query string (not escaping '/') |
514 | 390 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
|
391 if baseUrl is None: |
469 | 392 baseUrl = self.getDocumentViewerURL() |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
393 |
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
394 url = "%s?%s"%(baseUrl, ps) |
25 | 395 return url |
396 | |
478 | 397 def getLinkAmp(self, param=None, val=None, params=None, baseUrl=None, duplicates='comma'): |
68 | 398 """link to documentviewer with parameter param set to val""" |
478 | 399 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
|
400 |
526 | 401 |
402 def setAvailableLayers(self, newLayerString=None): | |
403 """sets availableLayers to newLayerString or tries to autodetect available layers. | |
404 assumes layer templates have the form layer_{m}_{l} for layer l in mode m. | |
405 newLayerString is parsed as JSON.""" | |
406 if newLayerString is not None: | |
407 try: | |
408 layers = json.loads(newLayerString) | |
590 | 409 if 'text' in layers and 'image' in layers: |
526 | 410 self.availableLayers = layers |
411 return | |
412 except: | |
413 pass | |
414 | |
415 logging.error("invalid layers=%s! autodetecting..."%repr(newLayerString)) | |
416 | |
417 # start with builtin layers | |
418 self.availableLayers = self.builtinLayers.copy() | |
419 # add layers from templates | |
420 for t in self.template: | |
421 if t.startswith('layer_'): | |
422 try: | |
423 (x, m, l) = t.split('_', 3) | |
424 if m not in self.availableLayers: | |
425 # mode m doesn't exist -> new list | |
426 self.availableLayers[m] = [l] | |
427 | |
428 else: | |
429 # m exists -> append | |
430 if l not in self.availableLayers[m]: | |
431 self.availableLayers[m].append() | |
432 | |
433 except: | |
434 pass | |
435 | |
436 def getAvailableLayersJson(self): | |
437 """returns available layers as JSON string.""" | |
438 return json.dumps(self.availableLayers) | |
439 | |
469 | 440 |
57 | 441 def getInfo_xml(self,url,mode): |
442 """returns info about the document as XML""" | |
443 if not self.digilibBaseUrl: | |
514 | 444 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
57 | 445 |
446 docinfo = self.getDocinfo(mode=mode,url=url) | |
447 pt = getattr(self.template, 'info_xml') | |
448 return pt(docinfo=docinfo) | |
449 | |
528 | 450 def getAuthenticatedUser(self, anon=None): |
451 """returns the authenticated user object or None. (ignores Zopes anonymous user)""" | |
452 user = getSecurityManager().getUser() | |
453 if user is not None and user.getUserName() != "Anonymous User": | |
454 return user | |
455 else: | |
456 return anon | |
457 | |
35 | 458 def isAccessible(self, docinfo): |
32 | 459 """returns if access to the resource is granted""" |
460 access = docinfo.get('accessType', None) | |
167 | 461 logging.debug("documentViewer (accessOK) access type %s"%access) |
465 | 462 if access == 'free': |
167 | 463 logging.debug("documentViewer (accessOK) access is free") |
32 | 464 return True |
465 | 465 |
45 | 466 elif access is None or access in self.authgroups: |
35 | 467 # only local access -- only logged in users |
528 | 468 user = self.getAuthenticatedUser() |
167 | 469 logging.debug("documentViewer (accessOK) user=%s ip=%s"%(user,self.REQUEST.getClientAddr())) |
528 | 470 return (user is not None) |
32 | 471 |
167 | 472 logging.error("documentViewer (accessOK) unknown access type %s"%access) |
32 | 473 return False |
464 | 474 |
543 | 475 def getUserinfo(self): |
476 """returns userinfo object""" | |
477 logging.debug("getUserinfo") | |
478 userinfo = {} | |
479 # look for cached userinfo in session | |
480 if self.REQUEST.SESSION.has_key('userinfo'): | |
481 userinfo = self.REQUEST.SESSION['userinfo'] | |
482 # check if its still current? | |
483 else: | |
484 # store in session | |
485 self.REQUEST.SESSION['userinfo'] = userinfo | |
486 | |
487 return userinfo | |
488 | |
612 | 489 def getDocinfoJSON(self, mode, url, tocMode=None): |
490 """returns docinfo depending on mode""" | |
491 import json | |
492 | |
493 dc = self.getDocinfo( mode, url, tocMode) | |
494 | |
495 return json.dumps(dc) | |
496 | |
497 | |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
498 def getDocinfo(self, mode, url, tocMode=None): |
464 | 499 """returns docinfo depending on mode""" |
500 logging.debug("getDocinfo: mode=%s, url=%s"%(mode,url)) | |
501 # look for cached docinfo in session | |
502 if self.REQUEST.SESSION.has_key('docinfo'): | |
503 docinfo = self.REQUEST.SESSION['docinfo'] | |
504 # check if its still current | |
505 if docinfo is not None and docinfo.get('mode', None) == mode and docinfo.get('url', None) == url: | |
506 logging.debug("getDocinfo: docinfo in session. keys=%s"%docinfo.keys()) | |
507 return docinfo | |
508 | |
509 # new docinfo | |
510 docinfo = {'mode': mode, 'url': url} | |
511 # add self url | |
512 docinfo['viewerUrl'] = self.getDocumentViewerURL() | |
477 | 513 docinfo['digilibBaseUrl'] = self.digilibBaseUrl |
566 | 514 docinfo['digilibScalerUrl'] = self.digilibScalerUrl |
515 docinfo['digilibViewerUrl'] = self.digilibViewerUrl | |
464 | 516 # get index.meta DOM |
517 docUrl = None | |
518 metaDom = None | |
519 if mode=="texttool": | |
520 # url points to document dir or index.meta | |
521 metaDom = self.metadataService.getDomFromPathOrUrl(url) | |
522 if metaDom is None: | |
523 raise IOError("Unable to find index.meta for mode=texttool!") | |
580
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
524 |
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
525 docUrl = url.replace('/index.meta', '') |
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
526 if url.startswith('/mpiwg/online/'): |
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
527 docUrl = url.replace('/mpiwg/online/', '', 1) |
464 | 528 |
529 elif mode=="imagepath": | |
530 # url points to folder with images, index.meta optional | |
531 # asssume index.meta in parent dir | |
532 docUrl = getParentPath(url) | |
533 metaDom = self.metadataService.getDomFromPathOrUrl(docUrl) | |
599 | 534 docinfo['imagePath'] = url.replace('/mpiwg/online', '', 1) |
464 | 535 |
536 elif mode=="filepath": | |
537 # url points to image file, index.meta optional | |
566 | 538 docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, url) |
548 | 539 docinfo['numPages'] = 1 |
464 | 540 # asssume index.meta is two path segments up |
541 docUrl = getParentPath(url, 2) | |
542 metaDom = self.metadataService.getDomFromPathOrUrl(docUrl) | |
543 | |
544 else: | |
545 logging.error("documentViewer (getdocinfo) unknown mode: %s!"%mode) | |
546 raise ValueError("Unknown mode %s! Has to be one of 'texttool','imagepath','filepath'."%(mode)) | |
547 | |
548 docinfo['documentUrl'] = docUrl | |
549 # process index.meta contents | |
473 | 550 if metaDom is not None and metaDom.tag == 'resource': |
464 | 551 # document directory name and path |
608 | 552 resource = self.metadataService.getResourceData(dom=metaDom, recursive=1) |
464 | 553 if resource: |
554 docinfo = self.getDocinfoFromResource(docinfo, resource) | |
555 | |
556 # texttool info | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
557 texttool = self.metadataService.getTexttoolData(dom=metaDom, recursive=1, all=True) |
464 | 558 if texttool: |
559 docinfo = self.getDocinfoFromTexttool(docinfo, texttool) | |
568 | 560 # document info from full text server |
516 | 561 if docinfo.get('textURLPath', None): |
565 | 562 docinfo = self.getTextInfo(mode=None, docinfo=docinfo) |
568 | 563 # include list of pages TODO: do we need this always? |
564 docinfo = self.getTextInfo(mode='pages', docinfo=docinfo) | |
464 | 565 |
566 # bib info | |
567 bib = self.metadataService.getBibData(dom=metaDom) | |
568 if bib: | |
548 | 569 # save extended version as 'bibx' TODO: ugly |
541 | 570 bibx = self.metadataService.getBibData(dom=metaDom, all=True, recursive=1) |
571 if len(bibx) == 1: | |
572 # unwrap list if possible | |
573 bibx = bibx[0] | |
574 | |
575 docinfo['bibx'] = bibx | |
576 docinfo = self.getDocinfoFromBib(docinfo, bib, bibx) | |
465 | 577 else: |
578 # no bib - try info.xml | |
579 docinfo = self.getDocinfoFromPresentationInfoXml(docinfo) | |
464 | 580 |
581 # auth info | |
582 access = self.metadataService.getAccessData(dom=metaDom) | |
583 if access: | |
584 docinfo = self.getDocinfoFromAccess(docinfo, access) | |
585 | |
466 | 586 # attribution info |
587 attribution = self.metadataService.getAttributionData(dom=metaDom) | |
588 if attribution: | |
589 logging.debug("getDocinfo: attribution=%s"%repr(attribution)) | |
590 docinfo['attribution'] = attribution | |
591 | |
592 # copyright info | |
593 copyright = self.metadataService.getCopyrightData(dom=metaDom) | |
594 if copyright: | |
595 logging.debug("getDocinfo: copyright=%s"%repr(copyright)) | |
596 docinfo['copyright'] = copyright | |
538 | 597 |
598 # DRI (permanent ID) | |
581 | 599 dri = self.metadataService.getDRI(dom=metaDom, type='mpiwg') |
538 | 600 if dri: |
601 docinfo['DRI'] = dri | |
466 | 602 |
578 | 603 # (presentation) context |
604 ctx = self.metadataService.getContextData(dom=metaDom, all=True) | |
605 if ctx: | |
606 logging.debug("getcontext: ctx=%s"%repr(ctx)) | |
607 docinfo['presentationContext'] = ctx | |
608 | |
464 | 609 # image path |
610 if mode != 'texttool': | |
532 | 611 # override image path from texttool with url parameter TODO: how about mode=auto? |
599 | 612 docinfo['imagePath'] = url.replace('/mpiwg/online', '', 1) |
464 | 613 |
548 | 614 # check numPages |
615 if docinfo.get('numPages', 0) == 0: | |
616 # number of images from digilib | |
617 if docinfo.get('imagePath', None): | |
599 | 618 imgpath = docinfo['imagePath'].replace('/mpiwg/online', '', 1) |
580
0806cb9061c1
fixed another bug when url starts with /mpiwg/online/
casties
parents:
578
diff
changeset
|
619 logging.debug("imgpath=%s"%imgpath) |
566 | 620 docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, imgpath) |
562 | 621 docinfo = self.getDocinfoFromDigilib(docinfo, imgpath) |
548 | 622 else: |
623 # imagePath still missing? try "./pageimg" | |
624 imgPath = os.path.join(docUrl, 'pageimg') | |
625 docinfo = self.getDocinfoFromDigilib(docinfo, imgPath) | |
626 if docinfo.get('numPages', 0) > 0: | |
627 # there are pages | |
628 docinfo['imagePath'] = imgPath | |
566 | 629 docinfo['imageURL'] = "%s?fn=%s"%(self.digilibScalerUrl, docinfo['imagePath']) |
464 | 630 |
516 | 631 # check numPages |
632 if docinfo.get('numPages', 0) == 0: | |
633 if docinfo.get('numTextPages', 0) > 0: | |
634 # replace with numTextPages (text-only?) | |
635 docinfo['numPages'] = docinfo['numTextPages'] | |
607 | 636 |
637 # min and max page no | |
638 docinfo['minPageNo'] = docinfo.get('minPageNo', 1) | |
639 docinfo['maxPageNo'] = docinfo.get('maxPageNo', docinfo['numPages']) | |
516 | 640 |
608 | 641 # part-of information |
642 partOfPath = docinfo.get('partOfPath', None) | |
643 if partOfPath is not None: | |
644 partOfDom = self.metadataService.getDomFromPathOrUrl(partOfPath) | |
645 if partOfDom is not None: | |
646 docinfo['partOfLabel'] = self.metadataService.getBibFormattedLabel(dom=partOfDom) | |
647 docinfo['partOfUrl'] = "%s?url=%s"%(self.getDocumentViewerURL(), partOfPath) | |
648 logging.debug("partOfLabel=%s partOfUrl=%s"%(docinfo['partOfLabel'],docinfo['partOfUrl'])) | |
649 | |
599 | 650 # normalize path |
651 if 'imagePath' in docinfo and not docinfo['imagePath'].startswith('/'): | |
652 docinfo['imagePath'] = '/' + docinfo['imagePath'] | |
653 | |
464 | 654 logging.debug("documentViewer (getdocinfo) docinfo: keys=%s"%docinfo.keys()) |
655 # store in session | |
656 self.REQUEST.SESSION['docinfo'] = docinfo | |
657 return docinfo | |
658 | |
516 | 659 |
464 | 660 def getDocinfoFromResource(self, docinfo, resource): |
661 """reads contents of resource element into docinfo""" | |
608 | 662 logging.debug("getDocinfoFromResource: resource=%s"%(repr(resource))) |
663 docName = getMDText(resource.get('name', None)) | |
464 | 664 docinfo['documentName'] = docName |
608 | 665 docPath = getMDText(resource.get('archive-path', None)) |
464 | 666 if docPath: |
667 # clean up document path | |
668 if docPath[0] != '/': | |
669 docPath = '/' + docPath | |
670 | |
671 if docName and (not docPath.endswith(docName)): | |
672 docPath += "/" + docName | |
673 | |
674 else: | |
675 # use docUrl as docPath | |
676 docUrl = docinfo['documentURL'] | |
677 if not docUrl.startswith('http:'): | |
678 docPath = docUrl | |
608 | 679 |
465 | 680 if docPath: |
681 # fix URLs starting with /mpiwg/online | |
682 docPath = docPath.replace('/mpiwg/online', '', 1) | |
683 | |
464 | 684 docinfo['documentPath'] = docPath |
608 | 685 |
686 # is this part-of? | |
687 partOf = resource.get('is-part-of', None) | |
688 if partOf is not None: | |
689 partOf = getMDText(partOf.get('archive-path', None)) | |
690 if partOf is not None: | |
691 docinfo['partOfPath'] = partOf.strip() | |
692 | |
464 | 693 return docinfo |
694 | |
695 def getDocinfoFromTexttool(self, docinfo, texttool): | |
696 """reads contents of texttool element into docinfo""" | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
697 logging.debug("texttool=%s"%repr(texttool)) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
698 # unpack list if necessary |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
699 if isinstance(texttool, list): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
700 texttool = texttool[0] |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
701 |
464 | 702 # image dir |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
703 imageDir = getMDText(texttool.get('image', None)) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
704 docPath = getMDText(docinfo.get('documentPath', None)) |
607 | 705 if imageDir: |
706 if imageDir.startswith('/'): | |
707 # absolute path | |
708 imageDir = imageDir.replace('/mpiwg/online', '', 1) | |
709 docinfo['imagePath'] = imageDir | |
710 | |
711 elif docPath: | |
712 # relative path | |
713 imageDir = os.path.join(docPath, imageDir) | |
714 imageDir = imageDir.replace('/mpiwg/online', '', 1) | |
715 docinfo['imagePath'] = imageDir | |
716 | |
717 # start and end page (for subdocuments of other documents) | |
718 imgStartNo = getMDText(texttool.get('image-start-no', None)) | |
719 minPageNo = getInt(imgStartNo, 1) | |
720 docinfo['minPageNo'] = minPageNo | |
721 | |
722 imgEndNo = getMDText(texttool.get('image-end-no', None)) | |
723 if imgEndNo: | |
724 docinfo['maxPageNo'] = getInt(imgEndNo) | |
464 | 725 |
726 # old style text URL | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
727 textUrl = getMDText(texttool.get('text', None)) |
464 | 728 if textUrl and docPath: |
729 if urlparse.urlparse(textUrl)[0] == "": #keine url | |
730 textUrl = os.path.join(docPath, textUrl) | |
731 | |
732 docinfo['textURL'] = textUrl | |
733 | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
734 # new style text-url-path (can be more than one with "repository" attribute) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
735 textUrlNode = texttool.get('text-url-path', None) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
736 if not isinstance(textUrlNode, list): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
737 textUrlNode = [textUrlNode] |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
738 |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
739 for tun in textUrlNode: |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
740 textUrl = getMDText(tun) |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
741 if textUrl: |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
742 textUrlAtts = tun.get('@attr') |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
743 if (textUrlAtts and 'repository' in textUrlAtts): |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
744 textRepo = textUrlAtts['repository'] |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
745 # use matching repository |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
746 if self.getRepositoryType() == textRepo: |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
747 docinfo['textURLPath'] = textUrl |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
748 docinfo['textURLRepository'] = textRepo |
564 | 749 break |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
750 |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
751 else: |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
752 # no repo attribute - use always |
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
753 docinfo['textURLPath'] = textUrl |
468 | 754 |
755 # page flow | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
756 docinfo['pageFlow'] = getMDText(texttool.get('page-flow', 'ltr')) |
468 | 757 |
758 # odd pages are left | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
759 docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left')) |
468 | 760 |
541 | 761 # number of title page (default 1) |
607 | 762 docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', minPageNo)) |
464 | 763 |
764 # old presentation stuff | |
561
9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
casties
parents:
560
diff
changeset
|
765 presentation = getMDText(texttool.get('presentation', None)) |
464 | 766 if presentation and docPath: |
465 | 767 if presentation.startswith('http:'): |
768 docinfo['presentationUrl'] = presentation | |
769 else: | |
770 docinfo['presentationUrl'] = os.path.join(docPath, presentation) | |
602 | 771 |
772 # make sure we have at least fake DC data | |
773 if 'creator' not in docinfo: | |
774 docinfo['creator'] = '[no author found]' | |
775 | |
776 if 'title' not in docinfo: | |
777 docinfo['title'] = '[no title found]' | |
778 | |
779 if 'date' not in docinfo: | |
780 docinfo['date'] = '[no date found]' | |
468 | 781 |
464 | 782 return docinfo |
783 | |
541 | 784 def getDocinfoFromBib(self, docinfo, bib, bibx=None): |
464 | 785 """reads contents of bib element into docinfo""" |
465 | 786 logging.debug("getDocinfoFromBib bib=%s"%repr(bib)) |
464 | 787 # put all raw bib fields in dict "bib" |
788 docinfo['bib'] = bib | |
789 bibtype = bib.get('@type', None) | |
790 docinfo['bibType'] = bibtype | |
791 # also store DC metadata for convenience | |
792 dc = self.metadataService.getDCMappedData(bib) | |
536
abd36d4d97b8
new version of index page. improvements for digilib page and thumbnail overview.
casties
parents:
535
diff
changeset
|
793 docinfo['creator'] = dc.get('creator','') |
abd36d4d97b8
new version of index page. improvements for digilib page and thumbnail overview.
casties
parents:
535
diff
changeset
|
794 docinfo['title'] = dc.get('title','') |
abd36d4d97b8
new version of index page. improvements for digilib page and thumbnail overview.
casties
parents:
535
diff
changeset
|
795 docinfo['date'] = dc.get('date','') |
464 | 796 return docinfo |
797 | |
798 def getDocinfoFromAccess(self, docinfo, acc): | |
799 """reads contents of access element into docinfo""" | |
800 #TODO: also read resource type | |
465 | 801 logging.debug("getDocinfoFromAccess acc=%s"%repr(acc)) |
464 | 802 try: |
465 | 803 acctype = acc['@attr']['type'] |
464 | 804 if acctype: |
805 access=acctype | |
806 if access in ['group', 'institution']: | |
807 access = acc['name'].lower() | |
808 | |
809 docinfo['accessType'] = access | |
810 | |
811 except: | |
812 pass | |
813 | |
814 return docinfo | |
815 | |
816 def getDocinfoFromDigilib(self, docinfo, path): | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
817 infoUrl=self.digilibBaseUrl+"/dirInfo-xml.jsp?fn="+path |
464 | 818 # fetch data |
819 txt = getHttpData(infoUrl) | |
820 if not txt: | |
821 logging.error("Unable to get dir-info from %s"%(infoUrl)) | |
822 return docinfo | |
823 | |
824 dom = ET.fromstring(txt) | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
825 dir = dom |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
826 # save size |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
827 size = dir.findtext('size') |
464 | 828 logging.debug("getDocinfoFromDigilib: size=%s"%size) |
829 if size: | |
830 docinfo['numPages'] = int(size) | |
831 else: | |
832 docinfo['numPages'] = 0 | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
833 return docinfo |
464 | 834 |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
835 # save list of image names and numbers |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
836 imgNames = {} |
591 | 837 imgIndexes = {} |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
838 for f in dir: |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
839 fn = f.findtext('name') |
591 | 840 pn = getInt(f.findtext('index')) |
841 imgNames[fn] = pn | |
842 imgIndexes[pn] = fn | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
843 |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
844 docinfo['imgFileNames'] = imgNames |
591 | 845 docinfo['imgFileIndexes'] = imgIndexes |
464 | 846 return docinfo |
847 | |
848 | |
465 | 849 def getDocinfoFromPresentationInfoXml(self,docinfo): |
850 """gets DC-like bibliographical information from the presentation entry in texttools""" | |
851 url = docinfo.get('presentationUrl', None) | |
852 if not url: | |
853 logging.error("getDocinfoFromPresentation: no URL!") | |
854 return docinfo | |
855 | |
856 dom = None | |
857 metaUrl = None | |
858 if url.startswith("http://"): | |
859 # real URL | |
860 metaUrl = url | |
861 else: | |
862 # online path | |
863 server=self.digilibBaseUrl+"/servlet/Texter?fn=" | |
864 metaUrl=server+url | |
865 | |
866 txt=getHttpData(metaUrl) | |
867 if txt is None: | |
868 logging.error("Unable to read info.xml from %s"%(url)) | |
869 return docinfo | |
870 | |
871 dom = ET.fromstring(txt) | |
872 docinfo['creator']=getText(dom.find(".//author")) | |
873 docinfo['title']=getText(dom.find(".//title")) | |
874 docinfo['date']=getText(dom.find(".//date")) | |
875 return docinfo | |
876 | |
877 | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
878 def getPageinfo(self, pn=None, pf=None, start=None, rows=None, cols=None, docinfo=None, userinfo=None, viewMode=None, viewLayer=None, tocMode=None): |
22 | 879 """returns pageinfo with the given parameters""" |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
880 logging.debug("getPageInfo(pn=%s, pf=%s, start=%s, rows=%s, cols=%s, viewMode=%s, viewLayer=%s, tocMode=%s)"%(pn,pf,start,rows,cols,viewMode,viewLayer,tocMode)) |
22 | 881 pageinfo = {} |
471 | 882 pageinfo['viewMode'] = viewMode |
508 | 883 # split viewLayer if necessary |
884 if isinstance(viewLayer,basestring): | |
885 viewLayer = viewLayer.split(',') | |
886 | |
887 if isinstance(viewLayer, list): | |
888 logging.debug("getPageinfo: viewLayer is list:%s"%viewLayer) | |
889 # save (unique) list in viewLayers | |
890 seen = set() | |
891 viewLayers = [l for l in viewLayer if l and l not in seen and not seen.add(l)] | |
892 pageinfo['viewLayers'] = viewLayers | |
893 # stringify viewLayer | |
894 viewLayer = ','.join(viewLayers) | |
895 else: | |
896 #create list | |
897 pageinfo['viewLayers'] = [viewLayer] | |
898 | |
503 | 899 pageinfo['viewLayer'] = viewLayer |
471 | 900 pageinfo['tocMode'] = tocMode |
901 | |
607 | 902 minPageNo = docinfo.get('minPageNo', 1) |
903 | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
904 # pf takes precedence over pn |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
905 if pf: |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
906 pageinfo['pf'] = pf |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
907 pn = getPnForPf(docinfo, pf) |
589 | 908 # replace pf in request params (used for creating new URLs) |
909 self.REQUEST.form.pop('pf', None) | |
910 self.REQUEST.form['pn'] = pn | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
911 else: |
607 | 912 pn = getInt(pn, minPageNo) |
591 | 913 pf = getPfForPn(docinfo, pn) |
914 pageinfo['pf'] = pf | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
915 |
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
916 pageinfo['pn'] = pn |
25 | 917 rows = int(rows or self.thumbrows) |
918 pageinfo['rows'] = rows | |
919 cols = int(cols or self.thumbcols) | |
920 pageinfo['cols'] = cols | |
921 grpsize = cols * rows | |
922 pageinfo['groupsize'] = grpsize | |
607 | 923 # if start is empty use one around pn |
924 grouppn = math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1) | |
925 # but not smaller than minPageNo | |
926 start = getInt(start, max(grouppn, minPageNo)) | |
22 | 927 pageinfo['start'] = start |
511 | 928 # get number of pages |
607 | 929 numPages = int(docinfo.get('numPages', 0)) |
930 if numPages == 0: | |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
931 # try numTextPages |
607 | 932 numPages = docinfo.get('numTextPages', 0) |
933 if numPages != 0: | |
934 docinfo['numPages'] = numPages | |
935 | |
936 maxPageNo = docinfo.get('maxPageNo', numPages) | |
937 logging.debug("minPageNo=%s maxPageNo=%s start=%s numPages=%s"%(minPageNo,maxPageNo,start,numPages)) | |
938 np = maxPageNo | |
518
91051b36b9cc
uses xml info from doc-info.xql for table of contents now.
casties
parents:
516
diff
changeset
|
939 |
511 | 940 # cache table of contents |
941 pageinfo['tocPageSize'] = getInt(self.REQUEST.get('tocPageSize', 30)) | |
469 | 942 pageinfo['numgroups'] = int(np / grpsize) |
943 if np % grpsize > 0: | |
944 pageinfo['numgroups'] += 1 | |
476 | 945 |
946 pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl' | |
947 oddScanLeft = docinfo.get('oddPage', 'left') != 'right' | |
948 # add zeroth page for two columns | |
949 pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft)) | |
950 pageinfo['pageZero'] = pageZero | |
607 | 951 pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=minPageNo, maxIdx=np) |
516 | 952 # more page parameters |
453
beb7ccb92564
first version using elementtree instead of 4suite xml
casties
parents:
405
diff
changeset
|
953 pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
516 | 954 if docinfo.get('pageNumbers'): |
955 # get original page numbers | |
587
6000c7e24d8a
new parameter "pf" to specify image file name. (still some issues)
casties
parents:
585
diff
changeset
|
956 pageNumber = docinfo['pageNumbers'].get(pn, None) |
516 | 957 if pageNumber is not None: |
958 pageinfo['pageNumberOrig'] = pageNumber['no'] | |
959 pageinfo['pageNumberOrigNorm'] = pageNumber['non'] | |
158 | 960 |
511 | 961 # cache search results |
962 query = self.REQUEST.get('query',None) | |
963 pageinfo['query'] = query | |
591 | 964 if query and viewMode == 'text': |
965 pageinfo['resultPageSize'] = getInt(self.REQUEST.get('resultPageSize', 10)) | |
511 | 966 queryType = self.REQUEST.get('queryType', 'fulltextMorph') |
967 pageinfo['queryType'] = queryType | |
968 pageinfo['resultStart'] = getInt(self.REQUEST.get('resultStart', '1')) | |
969 self.getSearchResults(mode=queryType, query=query, pageinfo=pageinfo, docinfo=docinfo) | |
970 | |
971 # highlighting | |
972 highlightQuery = self.REQUEST.get('highlightQuery', None) | |
973 if highlightQuery: | |
974 pageinfo['highlightQuery'] = highlightQuery | |
975 pageinfo['highlightElement'] = self.REQUEST.get('highlightElement', '') | |
976 pageinfo['highlightElementPos'] = self.REQUEST.get('highlightElementPos', '') | |
460 | 977 |
22 | 978 return pageinfo |
460 | 979 |
463 | 980 |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
981 def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0): |
613
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
982 """Return dict with array of page information for one screenfull of thumbnails. |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
983 |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
984 :param start: index of current page |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
985 :param rows: number of rows in one batch |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
986 :param cols: number of columns in one batch |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
987 :param pageFlowLtr: do indexes increase from left to right |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
988 :param pageZero: is there a zeroth non-visible page |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
989 :param minIdx: minimum index to use |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
990 :param maxIdx: maximum index to use |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
991 :returns: dict with |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
992 first: first page index |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
993 last: last page index |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
994 batches: list of all possible batches(dict: 'start': index, 'end': index) |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
995 pages: list for current batch of rows(list of cols(list of pages(dict: 'idx': index))) |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
996 nextStart: first index of next batch |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
997 prevStart: first index of previous batch |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
998 """ |
607 | 999 logging.debug("getPageBatch start=%s minIdx=%s maxIdx=%s"%(start,minIdx,maxIdx)) |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1000 batch = {} |
480 | 1001 grpsize = rows * cols |
476 | 1002 if maxIdx == 0: |
480 | 1003 maxIdx = start + grpsize |
476 | 1004 |
607 | 1005 np = maxIdx - minIdx + 1 |
613
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1006 if pageZero: |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1007 # correct number of pages for batching |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1008 np += 1 |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1009 |
607 | 1010 nb = int(math.ceil(np / float(grpsize))) |
613
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1011 |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1012 # list of all batch start and end points |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1013 batches = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1014 if pageZero: |
607 | 1015 ofs = minIdx - 1 |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1016 else: |
607 | 1017 ofs = minIdx |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1018 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1019 for i in range(nb): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1020 s = i * grpsize + ofs |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1021 e = min((i + 1) * grpsize + ofs - 1, maxIdx) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1022 batches.append({'start':s, 'end':e}) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1023 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1024 batch['batches'] = batches |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1025 |
613
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1026 # list of pages for current screen |
476 | 1027 pages = [] |
607 | 1028 if pageZero and start == minIdx: |
476 | 1029 # correct beginning |
607 | 1030 idx = minIdx - 1 |
476 | 1031 else: |
1032 idx = start | |
1033 | |
1034 for r in range(rows): | |
1035 row = [] | |
1036 for c in range(cols): | |
1037 if idx < minIdx or idx > maxIdx: | |
1038 page = {'idx':None} | |
1039 else: | |
1040 page = {'idx':idx} | |
1041 | |
1042 idx += 1 | |
1043 if pageFlowLtr: | |
1044 row.append(page) | |
1045 else: | |
1046 row.insert(0, page) | |
1047 | |
1048 pages.append(row) | |
1049 | |
607 | 1050 if start > minIdx: |
1051 batch['prevStart'] = max(start - grpsize, minIdx) | |
480 | 1052 else: |
1053 batch['prevStart'] = None | |
1054 | |
526 | 1055 if start + grpsize <= maxIdx: |
613
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1056 if pageZero and start == minIdx: |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1057 # correct nextStart for pageZero |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1058 batch['nextStart'] = grpsize |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1059 else: |
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1060 batch['nextStart'] = start + grpsize |
480 | 1061 else: |
1062 batch['nextStart'] = None | |
1063 | |
1064 batch['pages'] = pages | |
571 | 1065 batch['first'] = minIdx |
1066 batch['last'] = maxIdx | |
613
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1067 logging.debug("batch: %s"%repr(batch)) |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1068 return batch |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1069 |
613
c57d80a649ea
CLOSED - # 281: List of thumbnails verschluckt Seite, wenn odd-scan-position gesetzt ist
casties
parents:
612
diff
changeset
|
1070 |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1071 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
|
1072 """returns dict with information for one screenfull of data.""" |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1073 batch = {} |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1074 if end == 0: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1075 end = start + size |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1076 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1077 nb = int(math.ceil(end / float(size))) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1078 # list of all batch start and end points |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1079 batches = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1080 for i in range(nb): |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1081 s = i * size + 1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1082 e = min((i + 1) * size, end) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1083 batches.append({'start':s, 'end':e}) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1084 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1085 batch['batches'] = batches |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1086 # list of elements in this batch |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1087 this = [] |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1088 j = 0 |
526 | 1089 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
|
1090 if data: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1091 if fullData: |
526 | 1092 d = data.get(i, None) |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1093 else: |
526 | 1094 d = data.get(j, None) |
482
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1095 j += 1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1096 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1097 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1098 d = i+1 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1099 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1100 this.append(d) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1101 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1102 batch['this'] = this |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1103 if start > 1: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1104 batch['prevStart'] = max(start - size, 1) |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1105 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1106 batch['prevStart'] = None |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1107 |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1108 if start + size < end: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1109 batch['nextStart'] = start + size |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1110 else: |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1111 batch['nextStart'] = None |
7ca8ac7db06e
more new template stuff. more batching methods in documentViewer.
casties
parents:
480
diff
changeset
|
1112 |
571 | 1113 batch['first'] = start |
1114 batch['last'] = end | |
480 | 1115 return batch |
476 | 1116 |
1117 | |
546 | 1118 def getAnnotatorGroupsForUser(self, user, annotationServerUrl="http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager"): |
1119 """returns list of groups {name:*, id:*} on the annotation server for the user""" | |
1120 groups = [] | |
1121 groupsUrl = "%s/annotator/groups?user=%s"%(annotationServerUrl,user) | |
1122 data = getHttpData(url=groupsUrl, noExceptions=True) | |
1123 if data: | |
1124 res = json.loads(data) | |
1125 rows = res.get('rows', None) | |
1126 if rows is None: | |
1127 return groups | |
1128 for r in rows: | |
1129 groups.append({'id': r.get('id', None), 'name': r.get('name', None), 'uri': r.get('uri', None)}) | |
1130 | |
1131 return groups | |
1132 | |
1133 | |
463 | 1134 security.declareProtected('View management screens','changeDocumentViewerForm') |
1135 changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals()) | |
22 | 1136 |
526 | 1137 def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',availableLayers=None,RESPONSE=None): |
22 | 1138 """init document viewer""" |
1139 self.title=title | |
1140 self.digilibBaseUrl = digilibBaseUrl | |
566 | 1141 self.digilibScalerUrl = digilibBaseUrl + '/servlet/Scaler' |
1142 self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html' | |
25 | 1143 self.thumbrows = thumbrows |
1144 self.thumbcols = thumbcols | |
32 | 1145 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] |
463 | 1146 try: |
1147 # assume MetaDataFolder instance is called metadata | |
1148 self.metadataService = getattr(self, 'metadata') | |
1149 except Exception, e: | |
1150 logging.error("Unable to find MetaDataFolder 'metadata': "+str(e)) | |
526 | 1151 |
1152 self.setAvailableLayers(availableLayers) | |
463 | 1153 |
22 | 1154 if RESPONSE is not None: |
1155 RESPONSE.redirect('manage_main') | |
0 | 1156 |
1157 def manage_AddDocumentViewerForm(self): | |
1158 """add the viewer form""" | |
22 | 1159 pt=PageTemplateFile('zpt/addDocumentViewer', globals()).__of__(self) |
0 | 1160 return pt() |
1161 | |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
1162 def manage_AddDocumentViewer(self,id,imageScalerUrl="",textServerName="",title="",RESPONSE=None): |
0 | 1163 """add the viewer""" |
84
a6e4f9b6729a
first version with new full-text infrastructure and slightly changed templates
casties
parents:
83
diff
changeset
|
1164 newObj=documentViewer(id,imageScalerUrl=imageScalerUrl,title=title,textServerName=textServerName) |
0 | 1165 self._setObject(id,newObj) |
1166 | |
1167 if RESPONSE is not None: | |
1168 RESPONSE.redirect('manage_main') |