Commit 5ed85dbc authored by Jean-Paul Smets's avatar Jean-Paul Smets

Version fixed by JPS.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12222 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6a0b50bd
...@@ -145,15 +145,11 @@ class ContributionTool(BaseTool): ...@@ -145,15 +145,11 @@ class ContributionTool(BaseTool):
# Try to find the file_name # Try to find the file_name
file = kw.get('file', None) file = kw.get('file', None)
if file is not None: if file is not None:
try: file_name = file.filename
file_name = file.filename
except AttributeError: # file can be raw data
file_name = kw.get('file_name')
else:
file_name = None
if file_name is not None:
# we store it as source_reference # we store it as source_reference
kw['source_reference'] = file_name kw['source_reference'] = file_name
else:
file_name = None
# If the portal_type was provided, we can go faster # If the portal_type was provided, we can go faster
if portal_type is not None and portal_type != '': if portal_type is not None and portal_type != '':
...@@ -174,23 +170,32 @@ class ContributionTool(BaseTool): ...@@ -174,23 +170,32 @@ class ContributionTool(BaseTool):
# with PUT_factory # with PUT_factory
ob = self.PUT_factory( file_name, None, None ) 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 # Then put the file inside ourselves for a short while
#BaseTool._setObject(self, name, ob) BaseTool._setObject(self, file_name, ob)
#document = self[name] document = self[file_name]
# Then edit the document contents (so that upload can happen)
document._edit(**kw)
# Remove the object from ourselves # Remove the object from ourselves
#self._delObject(name, ob) BaseTool._delObject(self, file_name)
# Move it to where it belongs # Move the document to where it belongs
if not discover_metadata: setattr(self, NO_DISCOVER_METADATA_KEY, 1) if not discover_metadata: setattr(self, NO_DISCOVER_METADATA_KEY, 1)
setattr(ob, USER_NAME_KEY, user_login) setattr(ob, USER_NAME_KEY, user_login)
#document = self._setObject(name, ob) document = self._setObject(file_name, ob)
# Reindex it and return it # Time to empty the cache
# because PUT_factory unwraps the object, we have to get it from volatile, grrr... if hasattr(self, '_v_document_cache'):
document = getattr(self, TEMP_NEW_OBJECT_KEY)[0] if self._v_document_cache.has_key(file_name):
# Then edit the document contents (so that upload can happen) del self._v_document_cache[file_name]
#document._edit(**kw)
# Reindex it and return the document
document.immediateReindexObject() document.immediateReindexObject()
return document return document
...@@ -233,7 +238,6 @@ class ContributionTool(BaseTool): ...@@ -233,7 +238,6 @@ class ContributionTool(BaseTool):
pass pass
return property_dict return property_dict
# WebDAV virtual folder support # WebDAV virtual folder support
def _setObject(self, name, ob, user_login=None): def _setObject(self, name, ob, user_login=None):
""" """
...@@ -274,12 +278,13 @@ class ContributionTool(BaseTool): ...@@ -274,12 +278,13 @@ class ContributionTool(BaseTool):
# We can now discover metadata unless NO_DISCOVER_METADATA_KEY was set on ob # We can now discover metadata unless NO_DISCOVER_METADATA_KEY was set on ob
document = module[new_id] 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) 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 to newContent method
return document return document
...@@ -289,22 +294,31 @@ class ContributionTool(BaseTool): ...@@ -289,22 +294,31 @@ class ContributionTool(BaseTool):
Check for volatile temp object info first Check for volatile temp object info first
and try to find it and try to find it
""" """
ob, new_id = getattr(self, TEMP_NEW_OBJECT_KEY, (None, None)) if hasattr(self, '_v_document_cache'):
if ob is not None: document_url = self._v_document_cache.get(id, None)
if new_id == id: if document_url is not None:
return ob return self.getPortalObject().unrestrictedTraverse(document_url)
return BaseTool._getOb(self, id, default)
if default is _marker:
return BaseTool._getOb(self, id)
else:
return BaseTool._getOb(self, id, default=default)
def _delOb(self, id): def _delOb(self, id):
""" """
We don't need to delete, since we never set here 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) InitializeClass(ContributionTool)
# vim: filetype=python syntax=python shiftwidth=2 # vim: filetype=python syntax=python shiftwidth=2
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment