[Erp5-report] r29068 - in /erp5/trunk/products/ERP5Type/Accessor: AcquiredProperty.py Base.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Sep 16 13:41:29 CEST 2009
Author: jerome
Date: Wed Sep 16 13:41:25 2009
New Revision: 29068
URL: http://svn.erp5.org?rev=29068&view=rev
Log:
Don't create subobject when provided FileUpload is empty
Modified:
erp5/trunk/products/ERP5Type/Accessor/AcquiredProperty.py
erp5/trunk/products/ERP5Type/Accessor/Base.py
Modified: erp5/trunk/products/ERP5Type/Accessor/AcquiredProperty.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Accessor/AcquiredProperty.py?rev=29068&r1=29067&r2=29068&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Accessor/AcquiredProperty.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Accessor/AcquiredProperty.py [utf8] Wed Sep 16 13:41:25 2009
@@ -26,7 +26,8 @@
#
##############################################################################
-
+from Acquisition import aq_base
+from ZPublisher.HTTPRequest import FileUpload
from Base import func_code, type_definition, list_types, ATTRIBUTE_PREFIX, Getter as BaseGetter, Setter as BaseSetter
from Products.ERP5Type.PsycoWrapper import psyco
from zLOG import LOG
@@ -161,6 +162,18 @@
assertAttributePortalType(instance, self._storage_id, self._portal_type)
o = instance._getOb(self._storage_id, None)
if o is None:
+ if self._acquired_property == 'file':
+ if isinstance(value, FileUpload) or \
+ getattr(aq_base(value), 'tell', None) is not None:
+ # When editing through the web interface, we are always provided a
+ # FileUpload, and when no file has been specified, the file is empty.
+ # In the case of empty file, we should not create the sub document.
+ value.seek(0, 2)
+ is_empty_file = not value.tell()
+ value.seek(0)
+ if is_empty_file:
+ return ()
+
o = instance.newContent(id=self._storage_id,
portal_type=self._portal_type[0])
o._setProperty(self._acquired_property, value, *args, **kw)
Modified: erp5/trunk/products/ERP5Type/Accessor/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Accessor/Base.py?rev=29068&r1=29067&r2=29068&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Accessor/Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Accessor/Base.py [utf8] Wed Sep 16 13:41:25 2009
@@ -75,20 +75,28 @@
elif self._property_type == 'content':
# A file object should be provided
file_upload = args[0]
- if isinstance(file_upload, FileUpload):
- if file_upload:
- try:
- o = getattr(instance, self._storage_id)
- except AttributeError:
+ if isinstance(file_upload, FileUpload) or \
+ getattr(aq_base(value), 'tell', None) is not None:
+ # When editing through the web interface, we are always provided a
+ # FileUpload, and when no file has been specified, the file is empty.
+ # In the case of empty file, we should not create the sub document.
+ # But, i don't think this code is actually used ...
+ file_upload.seek(0, 2)
+ is_empty_file = not file_upload.tell()
+ file_upload.seek(0)
+
+ if not is_empty_file:
+ content_document = instance._getOb(self._storage_id, None)
+ if content_document is None:
# We create a default type
- o = instance.PUT_factory(self._storage_id,
+ content_document = instance.PUT_factory(self._storage_id,
file_upload.headers.get('content-type', None), file_upload)
- instance._setObject(self._storage_id, o)
- o = getattr(instance, self._storage_id)
- o.manage_upload(file = file_upload)
- modified_object_list = [o]
- else:
- LOG('ERP5Type WARNING', 0, '%s is not an instance of FileUpload'
+ instance._setObject(self._storage_id, content_document)
+ content_document = getattr(instance, self._storage_id)
+ content_document.manage_upload(file = file_upload)
+ modified_object_list = [content_document]
+ else:
+ LOG('ERP5Type WARNING', 0, '%s is not a file like object'
% str(file_upload))
else:
setattr(instance, self._storage_id, self._cast(args[0]))
More information about the Erp5-report
mailing list