X-Git-Url: https://scm.cri.mines-paristech.fr/git/Plinn.git/blobdiff_plain/99afe0ce8700bf835ff7bbedf77bb46e58f996d8..06261d4b9b1c430f52d16d789583212919aa2e96:/File.py?ds=sidebyside diff --git a/File.py b/File.py index 99c403a..22a1101 100755 --- a/File.py +++ b/File.py @@ -30,22 +30,55 @@ from AccessControl import ClassSecurityInfo import OFS from zope.component.factory import Factory -from Products.CMFDefault.File import File as BaseFile +from Products.CMFDefault.File import File as CMFFile +from Products.Photo.blobbases import File as BlobFile +from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl from Products.CMFCore.permissions import View, ModifyPortalContent from Products.CMFCore.utils import getToolByName from hexagonit.swfheader import parse as parseswf -class File(BaseFile) : +class File(BlobFile, CMFFile) : +#class File(CMFFile) : """ file class with portal_transforms support """ security = ClassSecurityInfo() - _properties = BaseFile._properties + ({'id':'orig_name', 'type':'string', 'mode':'w', 'label':"Original Name"},) + _properties = CMFFile._properties + ({'id':'orig_name', 'type':'string', 'mode':'w', 'label':"Original Name"},) orig_name = '' + def __init__( self + , id + , title='' + , file='' + , content_type='' + , precondition='' + , subject=() + , description='' + , contributors=() + , effective_date=None + , expiration_date=None + , format=None + , language='en-US' + , rights='' + ): + BlobFile.__init__(self, id, title, file, content_type=content_type, precondition=precondition) + self._setId(id) + #delattr(self, '__name__') + # + # If no file format has been passed in, rely on what OFS.Image.File + # detected. Unlike Images, which have code to try and pick the content + # type out of the binary data, File objects only provide the correct + # type if a "hint" in the form of a filename extension is given. + if format is None: + format = self.content_type + + DefaultDublinCoreImpl.__init__( self, title, subject, description + , contributors, effective_date, expiration_date + , format, language, rights ) + def __getattr__(self, name) : - try : return BaseFile.__getattr__(self, name) + try : return CMFFile.__getattr__(self, name) except : selfAttrs = self.__dict__ if selfAttrs.has_key('_v_transform_cache') : @@ -54,10 +87,10 @@ class File(BaseFile) : if cacheTuple : cacheData = cacheTuple[1] - subObDict = cacheData.getSubObjects() - if subObDict.has_key(name) : - fileOb = OFS.Image.File(name, name, subObDict[name]) - return fileOb + subObDict = cacheData.getSubObjects() + if subObDict.has_key(name) : + fileOb = OFS.Image.File(name, name, subObDict[name]) + return fileOb raise AttributeError, name @@ -68,7 +101,6 @@ class File(BaseFile) : if orig_name : self.orig_name = orig_name - print self.absolute_url(), self.Format() if self.Format() == 'application/x-shockwave-flash' : if file : try : @@ -92,7 +124,7 @@ class File(BaseFile) : orig_name = OFS.Image.cookId('', '', file)[0] if orig_name : self.orig_name = orig_name - BaseFile.edit(self, precondition=precondition, file=file) + CMFFile.edit(self, precondition=precondition, file=file) if hasattr(self, '_v_transform_cache') : del self._v_transform_cache @@ -100,15 +132,18 @@ class File(BaseFile) : security.declareProtected(View, 'SearchableText') def SearchableText(self) : """ Return full text""" - baseSearchableText = BaseFile.SearchableText(self) + baseSearchableText = CMFFile.SearchableText(self) transformTool = getToolByName(self, 'portal_transforms', default=None) if transformTool is None : return baseSearchableText else : + f = self.bdata.open() + orig = f.read() datastream_text = transformTool.convertTo('text/plain', - str(self.data), + orig, mimetype = self.content_type ) + f.close() full_text = '' if datastream_text is not None : full_text = datastream_text.getData() @@ -123,12 +158,14 @@ class File(BaseFile) : return '' else : filename = self.getId().replace(' ', '_') + f = self.bdata.open() + orig = f.read() datastream = transformTool.convertTo('text/html', - str(self.data), + orig, object=self, mimetype = self.content_type, filename = filename) - + f.close() if datastream is not None : return datastream.getData() else : return '' @@ -156,10 +193,12 @@ class File(BaseFile) : """ regTool = getToolByName(self, 'mimetypes_registry', default=None) if regTool : - mime = regTool(str(self.data), mimetype=self.content_type)[2] + f = self.bdata.open() + mime = regTool(f, mimetype=self.content_type)[2] + f.close() return mime.icon_path else : - return BaseFile.getIcon(self, relative_to_portal=relative_to_portal) + return CMFFile.getIcon(self, relative_to_portal=relative_to_portal) InitializeClass(File)