[Erp5-report] r12222 - /erp5/trunk/products/ERP5/Tool/ContributionTool.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jan 23 13:09:48 CET 2007


Author: jp
Date: Tue Jan 23 13:09:46 2007
New Revision: 12222

URL: http://svn.erp5.org?rev=12222&view=rev
Log:
Version fixed by JPS.

Modified:
    erp5/trunk/products/ERP5/Tool/ContributionTool.py

Modified: erp5/trunk/products/ERP5/Tool/ContributionTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Tool/ContributionTool.py?rev=12222&r1=12221&r2=12222&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/ContributionTool.py (original)
+++ erp5/trunk/products/ERP5/Tool/ContributionTool.py Tue Jan 23 13:09:46 2007
@@ -145,15 +145,11 @@
     # Try to find the file_name
     file = kw.get('file', None)
     if file is not None:
-      try:
-        file_name = file.filename
-      except AttributeError: # file can be raw data
-        file_name = kw.get('file_name')
+      file_name = file.filename
+      # we store it as source_reference
+      kw['source_reference'] = file_name
     else:
       file_name = None
-    if file_name is not None:
-      # we store it as source_reference
-      kw['source_reference'] = file_name
 
     # If the portal_type was provided, we can go faster
     if portal_type is not None and portal_type != '':
@@ -174,23 +170,32 @@
     # with PUT_factory
     ob = self.PUT_factory( file_name, None, None )
 
+    # Raise an error if we could not guess the portal type
+    # XXX Maybe we should try to pass the typ param
+    if ob is None:
+      raise ValueError, "Could not determine the document type"
+
     # Then put the file inside ourselves for a short while
-    #BaseTool._setObject(self, name, ob)
-    #document = self[name]
-    
+    BaseTool._setObject(self, file_name, ob)
+    document = self[file_name]
+
+    # Then edit the document contents (so that upload can happen)
+    document._edit(**kw)
+
     # Remove the object from ourselves
-    #self._delObject(name, ob)
-
-    # Move it to where it belongs
+    BaseTool._delObject(self, file_name)
+
+    # Move the document to where it belongs
     if not discover_metadata: setattr(self, NO_DISCOVER_METADATA_KEY, 1)
     setattr(ob, USER_NAME_KEY, user_login)
-    #document = self._setObject(name, ob)
-
-    # Reindex it and return it
-    # because PUT_factory unwraps the object, we have to get it from volatile, grrr...
-    document = getattr(self, TEMP_NEW_OBJECT_KEY)[0]
-    # Then edit the document contents (so that upload can happen)
-    #document._edit(**kw)
+    document = self._setObject(file_name, ob)
+
+    # Time to empty the cache
+    if hasattr(self, '_v_document_cache'):
+      if self._v_document_cache.has_key(file_name):
+        del self._v_document_cache[file_name]
+
+    # Reindex it and return the document
     document.immediateReindexObject()
     return document
 
@@ -233,7 +238,6 @@
         pass
     return property_dict
 
-
   # WebDAV virtual folder support
   def _setObject(self, name, ob, user_login=None):
     """
@@ -274,12 +278,13 @@
 
     # We can now discover metadata unless NO_DISCOVER_METADATA_KEY was set on ob
     document = module[new_id]
-    # store as volatile to be able to retrieve in a while
-    # keep name (to doublecheck this is the one)
-    # because PUT_factory will eventually call it by file name
-    setattr(self, TEMP_NEW_OBJECT_KEY, (document, name))
     user_login = getattr(self, USER_NAME_KEY, None)
-    if not getattr(ob, NO_DISCOVER_METADATA_KEY, 0): document.discoverMetadata(file_name=name, user_login=user_login)
+    #if not getattr(ob, NO_DISCOVER_METADATA_KEY, 0): document.discoverMetadata(file_name=name, user_login=user_login)
+
+    # Keep the document close to us
+    if not hasattr(self, '_v_document_cache'):
+      self._v_document_cache = {}
+    self._v_document_cache[name] = document.getRelativeUrl()
 
     # Return document to newContent method
     return document
@@ -289,22 +294,31 @@
     Check for volatile temp object info first
     and try to find it
     """
-    ob, new_id = getattr(self, TEMP_NEW_OBJECT_KEY, (None, None))
-    if ob is not None:
-      if new_id == id:
-        return ob
-    return BaseTool._getOb(self, id, default)
+    if hasattr(self, '_v_document_cache'):
+      document_url = self._v_document_cache.get(id, None)
+      if document_url is not None:
+        return self.getPortalObject().unrestrictedTraverse(document_url)
+
+    if default is _marker:
+      return BaseTool._getOb(self, id)
+    else:
+      return BaseTool._getOb(self, id, default=default)
 
   def _delOb(self, id):
     """
     We don't need to delete, since we never set here
     """
-    pass
-
+    if hasattr(self, '_v_document_cache'):
+      document_url = self._v_document_cache.get(id, None)
+      if document_url is not None:
+        document = self.getPortalObject().unrestrictedTraverse(document_url)
+        if document is not None:
+          document.getParentValue()._delOb(document.getId())
+          del self._v_document_cache[id]
+          return
+
+    return BaseTool._delOb(self, id)
 
 InitializeClass(ContributionTool)
 
-
-
-
 # vim: filetype=python syntax=python shiftwidth=2 




More information about the Erp5-report mailing list