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