Changeset 32:b25c89d693cf in documentViewer
- Timestamp:
- Apr 11, 2006, 5:27:57 PM (18 years ago)
- Branch:
- default
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
documentViewer.py
r31 r32 1 2 genericDigilib="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/"3 4 1 from OFS.Folder import Folder 5 2 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate 6 3 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 7 4 from AccessControl import ClassSecurityInfo 5 from AccessControl import getSecurityManager 8 6 from Globals import package_home 9 7 … … 29 27 30 28 def getTextFromNode(nodename): 29 if nodename is None: 30 return "" 31 31 nodelist=nodename.childNodes 32 32 rc = "" … … 38 38 import socket 39 39 40 def urlopen(url ):40 def urlopen(url,timeout=2): 41 41 """urlopen mit timeout""" 42 socket.setdefaulttimeout( 2)42 socket.setdefaulttimeout(timeout) 43 43 ret=urllib.urlopen(url) 44 44 socket.setdefaulttimeout(5) … … 70 70 71 71 72 def __init__(self,id,imageViewerUrl,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=10 ):72 def __init__(self,id,imageViewerUrl,title="",digilibBaseUrl=None,thumbcols=2,thumbrows=10,authgroups="mpiwg"): 73 73 """init document viewer""" 74 74 self.id=id … … 81 81 self.thumbcols = thumbcols 82 82 self.thumbrows = thumbrows 83 # authgroups is list of authorized groups (delimited by ,) 84 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] 83 85 # add template folder so we can always use template.something 84 86 self.manage_addFolder('template') … … 132 134 return style 133 135 136 def accessOK(self, docinfo): 137 """returns if access to the resource is granted""" 138 access = docinfo.get('accessType', None) 139 if access is None: 140 # no information - no access (not yet) 141 return True 142 elif access == 'free': 143 return True 144 145 print "access: ", access, " authgroups: ", self.authgroups 146 if access in self.authgroups: 147 # local access OK 148 user = getSecurityManager().getUser().getUserName() 149 print "user: ", user 150 return (user != "Anonymous User") 151 152 zLOG.LOG("documentViewer (accessOK)", zLOG.INFO, "unknown access group %s"%access) 153 return False 154 134 155 135 156 def getDirinfoFromDigilib(self,path,docinfo=None): … … 152 173 153 174 if params: 154 docinfo['numPages'] = getTextFromNode(params[0])175 docinfo['numPages'] = int(getTextFromNode(params[0])) 155 176 else: 156 177 docinfo['numPages'] = 0 157 178 158 179 return docinfo 159 160 180 181 182 def getAuthinfoFromIndexMeta(self,path,docinfo=None,dom=None): 183 """gets authorization info from the index.meta file at url or given by dom""" 184 zLOG.LOG("documentViewer (getbibinfofromindexmeta)", zLOG.INFO,"path: %s"%(path)) 185 186 access = None 187 188 if docinfo is None: 189 docinfo = {} 190 191 if dom is None: 192 server=self.digilibBaseUrl+"/servlet/Texter?fn=" 193 path="/".join(path.split("/")[0:-1]) 194 metaUrl=server+path+"/index.meta" 195 try: 196 dom = NonvalidatingReader.parseUri(metaUrl) 197 except: 198 return docinfo 199 200 acctype = dom.xpath("//access-conditions/access/@type") 201 if acctype and (len(acctype)>0): 202 access=acctype[0].value 203 if access == 'group': 204 access = getTextFromNode(dom.xpath("//access-conditions/access/name")[0]).lower() 205 206 docinfo['accessType'] = access 207 return docinfo 208 209 161 210 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): 162 211 """gets bibliographical info from the index.meta file at url or given by dom""" … … 184 233 bibmap=metaData.generateMappingForType(bibtype) 185 234 print "bibmap: ", bibmap, " for: ", bibtype 235 # if there is no mapping bibmap is empty (mapping sometimes has empty fields) 186 236 if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: 187 237 docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) … … 192 242 193 243 194 def getDocinfoFromTextTool(self,url,do cinfo=None):244 def getDocinfoFromTextTool(self,url,dom=None,docinfo=None): 195 245 """parse texttool tag in index meta""" 196 246 zLOG.LOG("documentViewer (getdocinfofromtexttool)", zLOG.INFO,"url: %s"%(url)) … … 198 248 docinfo = {} 199 249 200 try: 201 dom = NonvalidatingReader.parseUri(url) 202 except: 203 zLOG.LOG("documentViewer (parseUrlTexttool)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) 204 raise IOError("Unable to get texttool info from %s"%(url)) 250 if dom is None: 251 try: 252 dom = NonvalidatingReader.parseUri(url) 253 except: 254 zLOG.LOG("documentViewer (parseUrlTexttool)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) 255 raise IOError("Unable to get texttool info from %s"%(url)) 256 257 archiveNames=dom.xpath("//resource/name") 258 if archiveNames and (len(archiveNames)>0): 259 archiveName=getTextFromNode(archiveNames[0]) 205 260 206 261 archivePaths=dom.xpath("//resource/archive-path") 207 262 if archivePaths and (len(archivePaths)>0): 208 263 archivePath=getTextFromNode(archivePaths[0]) 264 # clean up archive path 265 if archivePath[0] != '/': 266 archivePath = '/' + archivePath 267 if not archivePath.endswith(archiveName): 268 archivePath += "/" + archiveName 209 269 else: 210 270 archivePath=None … … 217 277 218 278 if image and archivePath: 279 print "image: ", image, " archivepath: ", archivePath 219 280 image=os.path.join(archivePath,image) 220 281 image=image.replace("/mpiwg/online",'') … … 234 295 235 296 docinfo = self.getBibinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) 297 docinfo = self.getAuthinfoFromIndexMeta(url,docinfo=docinfo,dom=dom) 236 298 return docinfo 237 299 … … 249 311 250 312 docinfo = self.getBibinfoFromIndexMeta(path,docinfo=docinfo) 313 docinfo = self.getAuthinfoFromIndexMeta(path,docinfo=docinfo) 251 314 return docinfo 252 315 … … 361 424 return None 362 425 363 def changeDocumentViewer(self,imageViewerUrl,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10, RESPONSE=None):426 def changeDocumentViewer(self,imageViewerUrl,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=10,authgroups='mpiwg',RESPONSE=None): 364 427 """init document viewer""" 365 428 self.title=title … … 368 431 self.thumbrows = thumbrows 369 432 self.thumbcols = thumbcols 370 433 self.authgroups = [s.strip().lower() for s in authgroups.split(',')] 371 434 if RESPONSE is not None: 372 435 RESPONSE.redirect('manage_main') -
version.txt
r31 r32 1 DocumentViewer 0.2. 21 DocumentViewer 0.2.3 -
zpt/thumbs_main.zpt
r25 r32 11 11 tal:content="python:(grp*grpsize+1)"/> 12 12 </select> 13 <span tal:condition="python:(start+grpsize< docinfo['numPages'])">13 <span tal:condition="python:(start+grpsize<int(docinfo['numPages']))"> 14 14 <a tal:attributes="href python:here.getLink(param='start',val=start+grpsize)">></a> 15 15 </span>
Note: See TracChangeset
for help on using the changeset viewer.