--- ECHO_content/ECHO_collection.py 2006/09/10 11:03:07 1.274 +++ ECHO_content/ECHO_collection.py 2006/10/18 14:42:33 1.275 @@ -18,8 +18,9 @@ except: import urlparse import string import tempfile +import zipfile import re -import os +import os,shutil import OFS.Image from types import * from OFS.Cache import Cacheable @@ -1921,6 +1922,83 @@ class ECHO_collection(CatalogAware, Fold path="/mpiwg/online/permanent/shipbuilding" + + def exportImportObjects_html(self,RESPONSE): + """ImportObject""" + pt=zptFile(self, 'zpt/exportImportObjects.zpt') + pt.content_type="text/html" + return pt() + + def importObjects_html(self,RESPONSE): + """ImportObject""" + pt=zptFile(self, 'zpt/importObjects.zpt') + pt.content_type="text/html" + return pt() + + def importObjects(self,zfile,RESPONSE=None,REQUEST=None): + """import object from file""" + + zf=zipfile.ZipFile(zfile,"r") + tmpdir=tempfile.mkdtemp() # create tempdir + ret=None + + for name in zf.namelist(): + fn=tempfile.mkstemp()[1] + tf=file(fn,"w") + x=zf.read(name) + tf.write(x) + tf.close() + try: + self._importObjectFromFile(fn,set_owner=1) + except: + if not ret: + ret="" + ret+="Cannot import: %s (Already existing?)
"%name + os.remove(fn) + + if ret: + return """%s"""%ret + if RESPONSE: + RESPONSE.redirect(self.absolute_url()) + + def exportObjects_html(self,RESPONSE): + """Export objects""" + + pt=zptFile(self, 'zpt/exportObjects.zpt') + pt.content_type="text/html" + return pt() + + def exportObjects(self,ids,RESPONSE=None): + """export objects with type id""" + if not (type(ids) is ListType): + ids=[ids] + + tmpdir=tempfile.mkdtemp() # create tempdir + objs=self.ZopeFind(self,obj_ids=ids) + tmpfile=tempfile.mkstemp()[1] + + zf=zipfile.ZipFile(tmpfile,"w") + for obj in objs: + + f = os.path.join(tmpdir, '%s.zexp' %obj[0]) + #print E.absolute_url() + + obj[1]._p_jar.exportFile(obj[1]._p_oid, f) + + zf.write(f,obj[0]) + + zf.close() + shutil.rmtree(tmpdir) + if RESPONSE: + RESPONSE.setHeader("Content-Type","application/octet-stream") + len=os.stat(tmpfile)[6] + RESPONSE.setHeader("Content-Length",len) + RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%"export.zip") + fh=file(tmpfile) + for x in fh.read(): + RESPONSE.write(x) + fh.close() + def getMDValueSimpleSearchField(self): """returns value for simple search""" return " ".join([self.title,self.description]) @@ -2494,6 +2572,7 @@ class ECHO_collection(CatalogAware, Fold {'label':'Localize','action':'localizeObjects'}, {'label':'Change Weights','action':'changeWeights'}, {'label':'Rerender Labels and Titles','action':'ECHO_rerenderLinksMDWarning'}, + {'label':'Export/Import Objects','action':'exportImportObjects_html'}, {'label':'Graphic Coords','action':'ECHO_graphicEntry'}, {'label':'create resources from XML','action':'createRessourcesFromXMLForm'}, {'label':'Set Startpage','action':'setStartpageFolderForm'}, @@ -2978,7 +3057,7 @@ class ECHO_root(Folder,Persistent,Implic {'label':'Copy MD for indexing and search','action':'copySearchFields'}, ) - + def copySearchFields(self,RESPONSE=None): """copys < metadatafields to the object""" resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1)