Ejemplo n.º 1
0
 def __call__(self, instance, value, *args, **kw):
     # We return the first available object in the list
     o = None
     available_id = None
     modified_object_list = ()
     for k in self._storage_id_list:
         o = instance._getOb(k, None)
         if o is None: available_id = k
         if o is not None and o.portal_type in self._portal_type:
             o._setProperty(self._acquired_property, value, *args, **kw)
             modified_object_list = (o, )
     if o is None and available_id is not None:
         from Products.ERP5Type.Utils import assertAttributePortalType
         assertAttributePortalType(instance, available_id,
                                   self._portal_type)
         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=available_id,
                                 portal_type=self._portal_type[0])
         o._setProperty(self._acquired_property, value, *args, **kw)
         modified_object_list = (o, )
     return modified_object_list
Ejemplo n.º 2
0
 def __call__(self, instance, value, *args, **kw):
   # We return the first available object in the list
   o = None
   available_id = None
   modified_object_list = ()
   for k in self._storage_id_list:
     o = instance._getOb(k, None)
     if o is None: available_id = k
     if o is not None and o.portal_type in self._portal_type:
       o._setProperty(self._acquired_property, value, *args, **kw)
       modified_object_list = (o, )
   if o is None and available_id is not None:
     from Products.ERP5Type.Utils import assertAttributePortalType
     assertAttributePortalType(instance, available_id, self._portal_type)
     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=available_id,
                             portal_type=self._portal_type[0])
     o._setProperty(self._acquired_property, value, *args, **kw)
     modified_object_list = (o, )
   return modified_object_list
Ejemplo n.º 3
0
 def __call__(self, instance, *args, **kw):
   # We return the first available object in the list
   o = None
   available_id = None
   modified_object_list = ()
   for k in self._storage_id_list:
     o = instance._getOb(k, None)
     if o is None: available_id = k
     if o is not None and o.portal_type in self._portal_type:
       o._setProperty(self._acquired_property, *args, **kw)
       modified_object_list = (o, )
   if o is None and available_id is not None:
     from Products.ERP5Type.Utils import assertAttributePortalType
     assertAttributePortalType(instance, available_id, self._portal_type)
     o = instance.newContent(id=available_id,
                             portal_type=self._portal_type[0])
     o._setProperty(self._acquired_property, *args, **kw)
     modified_object_list = (o, )
   return modified_object_list