Mercurial > hg > documentViewer
comparison documentViewer.py @ 623:6012fe93f78c
better scheme-less URL code.
author | casties |
---|---|
date | Mon, 15 Dec 2014 16:10:05 +0100 |
parents | bc68ca0d2c0a |
children | 80a0191ae51c |
comparison
equal
deleted
inserted
replaced
622:bc68ca0d2c0a | 623:6012fe93f78c |
---|---|
14 import urlparse | 14 import urlparse |
15 import json | 15 import json |
16 | 16 |
17 from Products.MetaDataProvider import MetaDataFolder | 17 from Products.MetaDataProvider import MetaDataFolder |
18 | 18 |
19 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml | 19 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml, sslifyUrl |
20 | 20 |
21 | 21 |
22 def getMDText(node): | 22 def getMDText(node): |
23 """returns the @text content from the MetaDataProvider metadata node""" | 23 """returns the @text content from the MetaDataProvider metadata node""" |
24 | |
25 | |
26 | |
27 if isinstance(node, dict): | 24 if isinstance(node, dict): |
28 return node.get('@text', None) | 25 return node.get('@text', None) |
29 | 26 |
30 if isinstance(node,list): #more than one text file if there is an attribute don't choose it | 27 if isinstance(node,list): #more than one text file if there is an attribute don't choose it |
31 for nodeInList in node: | 28 for nodeInList in node: |
32 attr = nodeInList.get("@attr",None) | 29 attr = nodeInList.get("@attr",None) |
33 if attr is None: | 30 if attr is None: |
34 return node.get('@text',None) | 31 return node.get('@text',None) |
35 return None | 32 return None |
36 | |
37 | |
38 | 33 |
39 return node | 34 return node |
40 | 35 |
41 def getParentPath(path, cnt=1): | 36 def getParentPath(path, cnt=1): |
42 """returns pathname shortened by cnt""" | 37 """returns pathname shortened by cnt""" |
171 if digilibBaseUrl is not None: | 166 if digilibBaseUrl is not None: |
172 self.digilibBaseUrl = digilibBaseUrl | 167 self.digilibBaseUrl = digilibBaseUrl |
173 self.digilibScalerUrl = digilibBaseUrl + '/servlet/Scaler' | 168 self.digilibScalerUrl = digilibBaseUrl + '/servlet/Scaler' |
174 self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html' | 169 self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html' |
175 | 170 |
176 | 171 |
177 # proxy text server methods to fulltextclient | 172 # proxy text server methods to fulltextclient |
178 def getTextPage(self, **args): | 173 def getTextPage(self, **args): |
179 """returns full text content of page""" | 174 """returns full text content of page""" |
180 | |
181 return self.template.fulltextclient.getTextPage(**args) | 175 return self.template.fulltextclient.getTextPage(**args) |
182 | |
183 | |
184 | |
185 | 176 |
186 def getSearchResults(self, **args): | 177 def getSearchResults(self, **args): |
187 """loads list of search results and stores XML in docinfo""" | 178 """loads list of search results and stores XML in docinfo""" |
188 return self.template.fulltextclient.getSearchResults(**args) | 179 return self.template.fulltextclient.getSearchResults(**args) |
189 | 180 |
231 # this won't work | 222 # this won't work |
232 logging.error("template folder missing!") | 223 logging.error("template folder missing!") |
233 return "ERROR: template folder missing!" | 224 return "ERROR: template folder missing!" |
234 | 225 |
235 if not self.digilibBaseUrl: | 226 if not self.digilibBaseUrl: |
236 self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary" | 227 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
237 | 228 |
238 docinfo = self.getDocinfo(mode=mode,url=url) | 229 docinfo = self.getDocinfo(mode=mode,url=url) |
239 #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) | 230 #pageinfo = self.getPageinfo(start=start,current=pn,docinfo=docinfo) |
240 pageinfo = self.getPageinfo(start=start,pn=pn, docinfo=docinfo) | 231 pageinfo = self.getPageinfo(start=start,pn=pn, docinfo=docinfo) |
241 ''' ZDES ''' | 232 ''' ZDES ''' |
265 | 256 |
266 if not hasattr(self, 'template'): | 257 if not hasattr(self, 'template'): |
267 # this won't work | 258 # this won't work |
268 logging.error("template folder missing!") | 259 logging.error("template folder missing!") |
269 return "ERROR: template folder missing!" | 260 return "ERROR: template folder missing!" |
270 | |
271 | |
272 | 261 |
273 if not getattr(self, 'digilibBaseUrl', None): | 262 if not getattr(self, 'digilibBaseUrl', None): |
274 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" | 263 self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary" |
275 | 264 |
276 # mode=filepath should not have toc-thumbs | 265 # mode=filepath should not have toc-thumbs |
304 | 293 |
305 elif viewMode == 'images': | 294 elif viewMode == 'images': |
306 # legacy fix | 295 # legacy fix |
307 viewMode = 'image' | 296 viewMode = 'image' |
308 self.REQUEST['viewMode'] = 'image' | 297 self.REQUEST['viewMode'] = 'image' |
309 | |
310 | |
311 | |
312 | 298 |
313 # safe viewLayer in userinfo | 299 # safe viewLayer in userinfo |
314 userinfo['viewLayer'] = viewLayer | 300 userinfo['viewLayer'] = viewLayer |
315 | 301 |
316 # pageinfo: information about page (not cached) | 302 # pageinfo: information about page (not cached) |
331 return self.availableLayers | 317 return self.availableLayers |
332 | 318 |
333 def findDigilibUrl(self): | 319 def findDigilibUrl(self): |
334 """try to get the digilib URL from zogilib""" | 320 """try to get the digilib URL from zogilib""" |
335 url = self.template.zogilib.getDLBaseUrl() | 321 url = self.template.zogilib.getDLBaseUrl() |
336 return url | 322 return sslifyUrl(url, self, force=True) |
337 | 323 |
338 def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None): | 324 def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None): |
339 """returns URL to digilib Scaler with params""" | 325 """returns URL to digilib Scaler with params""" |
340 url = None | 326 url = None |
341 if docinfo is not None: | 327 if docinfo is not None: |
762 if imgEndNo: | 748 if imgEndNo: |
763 docinfo['maxPageNo'] = getInt(imgEndNo) | 749 docinfo['maxPageNo'] = getInt(imgEndNo) |
764 | 750 |
765 # old style text URL | 751 # old style text URL |
766 textUrl = getMDText(texttool.get('text', None)) | 752 textUrl = getMDText(texttool.get('text', None)) |
767 | |
768 | |
769 | |
770 | 753 |
771 if textUrl and docPath: | 754 if textUrl and docPath: |
772 if urlparse.urlparse(textUrl)[0] == "": #keine url | 755 if urlparse.urlparse(textUrl)[0] == "": #keine url |
773 textUrl = os.path.join(docPath, textUrl) | 756 textUrl = os.path.join(docPath, textUrl) |
774 | 757 |
1159 | 1142 |
1160 | 1143 |
1161 def getAnnotatorGroupsForUser(self, user, annotationServerUrl="http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager"): | 1144 def getAnnotatorGroupsForUser(self, user, annotationServerUrl="http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager"): |
1162 """returns list of groups {name:*, id:*} on the annotation server for the user""" | 1145 """returns list of groups {name:*, id:*} on the annotation server for the user""" |
1163 groups = [] | 1146 groups = [] |
1164 if annotationServerUrl.startswith('//'): | 1147 # add matching http(s) from our URL |
1165 # add matching http(s) from our URL | 1148 annotationServerUrl = sslifyUrl(annotationServerUrl, self) |
1166 myUrl = self.REQUEST['URL'] | |
1167 logging.debug("my URL: %s"%myUrl) | |
1168 if myUrl.startswith('https:'): | |
1169 annotationServerUrl = "https:%s"%annotationServerUrl | |
1170 else: | |
1171 annotationServerUrl = "http:%s"%annotationServerUrl | |
1172 | 1149 |
1173 groupsUrl = "%s/annotator/groups?user=%s"%(annotationServerUrl,user) | 1150 groupsUrl = "%s/annotator/groups?user=%s"%(annotationServerUrl,user) |
1174 data = getHttpData(url=groupsUrl, noExceptions=True) | 1151 data = getHttpData(url=groupsUrl, noExceptions=True) |
1175 if data: | 1152 if data: |
1176 res = json.loads(data) | 1153 res = json.loads(data) |
1203 | 1180 |
1204 self.setAvailableLayers(availableLayers) | 1181 self.setAvailableLayers(availableLayers) |
1205 | 1182 |
1206 if RESPONSE is not None: | 1183 if RESPONSE is not None: |
1207 RESPONSE.redirect('manage_main') | 1184 RESPONSE.redirect('manage_main') |
1185 | |
1208 | 1186 |
1209 def manage_AddDocumentViewerForm(self): | 1187 def manage_AddDocumentViewerForm(self): |
1210 """add the viewer form""" | 1188 """add the viewer form""" |
1211 pt=PageTemplateFile('zpt/addDocumentViewer', globals()).__of__(self) | 1189 pt=PageTemplateFile('zpt/addDocumentViewer', globals()).__of__(self) |
1212 return pt() | 1190 return pt() |