Annotation of ImageArchive/ImageArchive.py, revision 1.1.1.1

1.1       dwinter     1: from OFS.Folder import Folder
                      2: from OFS.SimpleItem import SimpleItem
                      3: from Globals import Persistent
                      4: from Acquisition import Implicit
                      5: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
                      6: from Products.PageTemplates.PageTemplate import PageTemplate
                      7: import re
                      8: import os
                      9: import os.path
                     10: import urllib
                     11: import xml.dom.minidom
                     12: 
                     13: def getText(nodelist):
                     14:     
                     15:     rc = ""
                     16:     for node in nodelist:
                     17:     
                     18:        if node.nodeType == node.TEXT_NODE:
                     19:            rc = rc + node.data
                     20:     return rc
                     21: 
                     22: 
                     23: class ImageDigilib(SimpleItem,Persistent,Implicit):
                     24:     """Anzeige object fuer digilib"""
                     25:     meta_type="ImageDigilib"
                     26: 
                     27:     def __init__(self,id,filename):
                     28:         self.id=id
                     29:         self.title=filename
                     30:         self.filename=filename
                     31: 
                     32:     def uploadImage(self,fileupload,path_name):
                     33:         """upload an Image from an Requast"""
                     34:         #path_name=self.ImageStoragePath
                     35:         filename=path_name+"/"+fileupload.filename
                     36:         filedata=fileupload.read()
                     37:         f=open(filename,"w")
                     38:         f.write(filedata)
                     39:         f.close()
                     40:         os.chmod(filename,0644)
                     41: 
                     42:     def download(self):
                     43:         """download"""
                     44:         path="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+self.filename+"&mo=file"
                     45:         #self.REQUEST.SESSION['string']="<img src=\"%s\">"% path
                     46:         #pt=PageTemplateFile('Products/ImageArchive/thumb.zpt').__of__(self)
                     47:         return self.REQUEST.RESPONSE.redirect(path)
                     48:     
                     49:     def thumb(self):
                     50:         """show thumb"""
                     51:         if not os.path.exists("/mpiwg/temp/online/scaled/small/"+self.ImageViewerPath+"/"+self.filename):
                     52:             #image=urllib.urlopen("http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+self.filename+"&dw=150").read()
                     53:             #f=open("/mpiwg/temp/online/scaled/small/"+self.ImageViewerPath+"/"+self.filename,"w")
                     54:             #f.write(image)
                     55:             #f.close()
                     56:             os.popen("ssh nausikaa2.rz-berlin.mpg.de /usr/local/mpiwg/scripts/scaleomat.pl %s /mpiwg/temp/online/scaled/small 150 &"% self.ImageViewerPath)
                     57:             
                     58:         
                     59:         #path="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?fn="+self.ImageViewerPath+"/"+self.filename+"&dw=100&dh=100"
                     60:         path="/thumbs"+self.ImageViewerPath+"/"+self.filename
                     61:         self.REQUEST.SESSION['string']="<img src=\"%s\">"% path
                     62:         pt=PageTemplateFile('Products/ImageArchive/thumb.zpt').__of__(self)
                     63:         return pt()
                     64:     
                     65:     def index_html(self):
                     66:         """show image"""
                     67:         path="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/digilib.jsp?fn="+self.ImageViewerPath+"/"+self.filename
                     68:         #self.REQUEST.SESSION['string']="<img src=\"%s\">"% path
                     69:         #pt=PageTemplateFile('Products/ImageArchive/thumb.zpt').__of__(self)
                     70:         return self.REQUEST.RESPONSE.redirect(path)
                     71: 
                     72:     
                     73: def manage_AddImageDigilibForm(self):
                     74:     """Nothing yet"""
                     75:     pt=PageTemplateFile('Products/ImageArchive/AddImageDigilibForm.zpt').__of__(self)
                     76:     return pt()
                     77:     
                     78: def manage_AddImageDigilib(self,id,fileupload,RESPONSE=None):
                     79:     """Add ImageCollection"""
                     80:     #fileupload=self.REQUEST['fileupload']
                     81:     newObj=ImageDigilib(id,fileupload.filename)
                     82:     
                     83:     self._setObject(id,newObj)
                     84:     getattr(self,id).uploadImage(fileupload,self.ImageStoragePath)
                     85:     
                     86:     if RESPONSE is not None:
                     87:         RESPONSE.redirect('manage_main')
                     88: 
                     89:                  
                     90: class ImageCollection(Folder, Persistent, Implicit):
                     91:     """Sammelordner für Bilder"""
                     92:     meta_type="ImageCollection"
                     93: 
                     94:     def __init__(self,id,title,ImageStoragePath,ImageViewerPath):
                     95:         self.id=id
                     96:         self.title=title
                     97:         self.ImageStoragePath=ImageStoragePath
                     98:         self.ImageViewerPath=ImageViewerPath
                     99: 
                    100: 
                    101:     manage_options = Folder.manage_options+(
                    102:         {'label':'Main Config','action':'ImageCollection_config'},
                    103:         {'label':'Import','action':'ImportFiles'},
                    104:         )
                    105: 
                    106:     def xmlinput(self,url):
                    107:         """Anzeige von ausgewaehlten thumbs"""
                    108:         #return url
                    109:         xmldoc=urllib.urlopen(url).read()
                    110:         
                    111:         dom=xml.dom.minidom.parseString(xmldoc)
                    112:         
                    113:         images=dom.getElementsByTagName('imagename')
                    114:         rc=[]
                    115:         for image in images:
                    116:             text=getText(image.childNodes)
                    117:             if not text=="":
                    118:                 rc.append(str(text))
                    119: 
                    120:         self.REQUEST.SESSION['filenames']=rc
                    121:         pt=PageTemplateFile('Products/ImageArchive/overview_selected.zpt').__of__(self)
                    122:         return pt()        
                    123: 
                    124:     
                    125:     def addImage(self):
                    126:         """Add an Image"""
                    127:         pt=PageTemplateFile('Products/ImageArchive/addImage.zpt').__of__(self)
                    128:         return pt()
                    129:     
                    130:     def addImage2(self,fileupload,RESPONSE=None):
                    131:         """Add"""
                    132:         #print "FU",fileupload
                    133:         manage_AddImageDigilib(self,fileupload.filename,fileupload)
                    134:         return RESPONSE.redirect(self.REQUEST['URL1']+'/'+fileupload.filename)
                    135:         #return  self.REQUEST['URL1']+'/'+fileupload.filename
                    136:     
                    137:     def ImportFiles(self,RESPONSE=None):
                    138:         """Import the existing files of a folder"""
                    139:         files=os.listdir(self.ImageStoragePath)
                    140:         ret=""
                    141:         #print self.__dict__
                    142:         for file in files:
                    143:             if self.__dict__.has_key(file):
                    144:                 
                    145:                 ret=ret+"<br>"+file+" already exists!"
                    146:             else:
                    147:                 ret=ret+"<br>"+file+" created!"
                    148:                 newObj=ImageDigilib(file,file)
                    149:                 #print newObj,file
                    150:                 #print newObj
                    151:                 self._setObject(file,newObj)
                    152:         #print ret
                    153:         pt=PageTemplateFile('Products/ImageArchive/out.zpt',ret).__of__(self)
                    154:         RESPONSE.redirect('manage_main')
                    155:         
                    156:     def ImageCollection_config(self):
                    157:         """Nothing yet"""
                    158:         pt=PageTemplateFile('Products/ImageArchive/ChangeImageCollectionForm.zpt').__of__(self)
                    159:         return pt()
                    160: 
                    161:     def ChangeImageCollection(self,title,ImageStoragePath,ImageViewerPath,RESPONSE=None):
                    162:         """Change"""
                    163:         self.title=title
                    164:         self.ImageStoragePath=ImageStoragePath
                    165:         self.ImageViewerPath=ImageViewerPath
                    166: 
                    167:         if RESPONSE is not None:
                    168:             RESPONSE.redirect('manage_main')
                    169: 
                    170:     def show_selected_thumbs(self):
                    171:         #ids=[]
                    172:         
                    173:         return self.REQUEST.SESSION['filenames']
                    174: 
                    175:     def show_thumbs(self):
                    176:         ids=[]
                    177:         for entry in self.__dict__:
                    178:             #print entry
                    179:             if hasattr(getattr(self,entry),'thumb'):
                    180:                 ids.append(entry)
                    181:         #print ids
                    182:         return ids
                    183: 
                    184:     def thumblistSelected(self):
                    185:         """main template collection"""
                    186:         pt=PageTemplateFile('Products/ImageArchive/thumbselected.zpt').__of__(self)
                    187:         return pt()
                    188: 
                    189:     def thumblist(self):
                    190:         """main template collection"""
                    191:         pt=PageTemplateFile('Products/ImageArchive/thumbs.zpt').__of__(self)
                    192:         return pt()
                    193: 
                    194:     def navig_html(self):
                    195:         """navigation"""
                    196:         pt=PageTemplateFile('Products/ImageArchive/navigation.zpt').__of__(self)
                    197:         return pt()
                    198: 
                    199: 
                    200:     def index_html(self):
                    201:         """main template collection"""
                    202:         if self.REQUEST.has_key('filename'):
                    203:             filen=self.REQUEST['filename']
                    204:         else:
                    205:             filen=""
                    206:         self.REQUEST.SESSION['filename']=filen
                    207:         pt=PageTemplateFile('Products/ImageArchive/overview.zpt').__of__(self)
                    208:         return pt()
                    209:     
                    210: def manage_AddImageCollectionForm(self):
                    211:     """Nothing yet"""
                    212:     pt=PageTemplateFile('Products/ImageArchive/AddImageCollectionForm.zpt').__of__(self)
                    213:     return pt()
                    214:     
                    215: def manage_AddImageCollection(self,id,title,ImageStoragePath,ImageViewerPath,RESPONSE=None):
                    216:     """Add ImageCollection"""
                    217:     newObj=ImageCollection(id,title,ImageStoragePath,ImageViewerPath)
                    218:     self._setObject(id,newObj)
                    219:     
                    220:     if RESPONSE is not None:
                    221:         RESPONSE.redirect('manage_main')
                    222: 
                    223: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>