Hi Florent, Jose, 

I am also looking at this file for a while and found that it always creates
files, even if you upload images, a zope file object is created.

This is the corresponding patch, to the createFile.py of cps 3.4.3, without
jose's patch:

============
--- ../Products-CPS-platform-3.4.3/CPSDocument/createFile.py  2007-04-10
10:52:10.000000000 +0200
+++ createFile.py 2007-04-12 14:07:08.000000000 +0200
@@ -25,7 +25,7 @@
 from logging import getLogger

 from Products.CMFCore.utils import getToolByName
-from OFS.Image import File
+from OFS.Image import File, Image
 from AccessControl import ModuleSecurityInfo
 from zipfile import ZipFile, BadZipfile
 from StringIO import StringIO
@@ -107,7 +107,10 @@

         # create file to attach to document
         data = zipfile.read(path)
-        file_to_attach = File(path_filename, path_filename, data)
+        if ptype in ['Image']:
+            file_to_attach = Image(path_filename, path_filename, data)
+        else:
+            file_to_attach = File(path_filename, path_filename, data)
         if mimetype and file_to_attach.content_type != mimetype:
             logger.debug('Fixing mimetype from %s to %s',
                          file_to_attach.content_type, mimetype)
==========

Cheers, Michael

-----------------------------
Michael Schulz

in medias res GmbH
In den Weihermatten 66
D-79108 Freiburg
+49 761 5569595




Florent Guillaume wrote:
> 
> Hi Jose,
> 
> Please put this in a Trac ticket for better followups.
> Also please use "diff -u createFile.py.original createFile.py" (or  
> just svn diff if you work from svn) to create an easy-to-read patch.
> 
> Thanks,
> Florent
> 
> On 15 Mar 2007, at 13:08, Jose Jiménez López wrote:
> 
>> Hello everybody,
>>
>> recently i needed to create a new portal type that uploads a zip  
>> file, and recreates the same file and directories structure.
>>
>> In order to do this, i have patched the module CPSDocument.createFile
>>
>> I think that it can interest to somebody.
>>
>> Here is the code that i have modified:
>>
>>     # browsing the ZIP file
>>     for info in infolist:
>>         path = info.filename
>>         list = path.split('/')
>>         if list[len(list) - 1] == '':
>>             list = list[0:len(list)-1]
>>
>>         path_filename = list[len(list)-1]
>>
>>         #if is a directory
>>         if path[-1] == '/':
>>             ptype = 'Workspace'
>>             field_name = 'file'
>>             isFolder = True
>>         else:
>>             mimetype = registry.lookupExtension(path_filename.lower 
>> ()).normalized()
>>             isFolder = False
>>
>>         if not isFolder:
>>             if mimetype.startswith('image/'):
>>                 ptype = 'Image'
>>                 field_name = 'preview'
>>             else:
>>                 ptype = 'File'
>>                 field_name = 'file'
>>
>>         if check_allowed_content_types and ptype not in  
>> allowed_content_types:
>>             continue
>>         try:
>>             container = context
>>             if len(list) > 1:
>>                 for folder in list[0:len(list) - 1]:
>>                     container = container[folder]
>>             file_id = context.portal_workflow.invokeFactoryFor(
>>                 container, ptype, path_filename)
>>         except BadRequest:
>>             logger.info('File %s already exists', path_filename)
>>             return 0
>>
>>         file_proxy = getattr(container, file_id)
>>         file_doc = file_proxy.getEditableContent()
>>
>>         if not isFolder:
>>             # create file to attach to document
>>             data = zipfile.read(path)
>>             file_to_attach = File(path_filename, path_filename, data)
>>             if mimetype and file_to_attach.content_type != mimetype:
>>                 logger.debug('Fixing mimetype from %s to %s',
>>                              file_to_attach.content_type, mimetype)
>>                 file_to_attach.manage_changeProperties 
>> (content_type=mimetype)
>>
>>             doc_def = {
>>                 'Title': path_filename,
>>                 'Description': 'Imported File (original archive: % 
>> s)' % filename,
>>                 field_name: file_to_attach,
>>             }
>>         else:
>>             doc_def = {
>>                 'Title': path_filename,
>>                 'Description': 'Imported File (original archive: % 
>> s)' % filename,
>>             }
>>
>>         file_doc.edit(doc_def, proxy=file_proxy)
>>
>>     return 1
>>
>>
>> Jose Jiménez López
>> Becario de Sistemas
>> FUNDACIÓN IAVANTE
>> [EMAIL PROTECTED]
>> Tel. 958 00 22 63
>>
>>
>>
>> Este correo electrónico y, en su caso, cualquier fichero anexo,  
>> contiene información confidencial exclusivamente dirigida a su(s)  
>> destinatario(s). Toda copia o divulgación deberá ser autorizada por  
>> IAVANTE.
>>
>> This e-mail and any attachments are confidential and exclusively  
>> directed to its adressee(s). Any copy or distribution will have to  
>> be authorized by IAVANTE.
>>
>>
>>
>> _______________________________________________
>> cps-devel mailing list
>> http://lists.nuxeo.com/mailman/listinfo/cps-devel
> 
> -- 
> Florent Guillaume, Director of R&D, Nuxeo
> Open Source Enterprise Content Management (ECM)
> http://www.nuxeo.com   http://www.nuxeo.org   +33 1 40 33 79 87
> 
> 
> 
> _______________________________________________
> cps-devel mailing list
> http://lists.nuxeo.com/mailman/listinfo/cps-devel
> 
> 

-- 
View this message in context: 
http://www.nabble.com/possible-improvement-for-CPSDocument.createFile-tf3407946.html#a9960719
Sent from the cps-devel mailing list archive at Nabble.com.

_______________________________________________
cps-devel mailing list
http://lists.nuxeo.com/mailman/listinfo/cps-devel

Reply via email to