[Erp5-report] r18359 - /erp5/trunk/products/ERP5/Tool/ContributionTool.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Dec 17 15:29:36 CET 2007
Author: yusei
Date: Mon Dec 17 15:29:36 2007
New Revision: 18359
URL: http://svn.erp5.org?rev=18359&view=rev
Log:
Use new generated id if filename is invalid.
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=18359&r1=18358&r2=18359&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Tool/ContributionTool.py (original)
+++ erp5/trunk/products/ERP5/Tool/ContributionTool.py Mon Dec 17 15:29:36 2007
@@ -43,6 +43,7 @@
from zLOG import LOG
from DateTime import DateTime
from Acquisition import aq_base
+from zExceptions import BadRequest
# Install openers
import ContributionOpener
@@ -299,18 +300,29 @@
# with PUT_factory - we provide the mime_type as
# parameter
# LOG('new content', 0, "%s -- %s" % (file_name, mime_type))
+
+ try:
+ self._checkId(file_name)
+ except BadRequest:
+ extension = ''
+ if '.' in file_name:
+ extension = '.%s' % file_name.split('.')[-1]
+ file_name = '%s%s' % (self.generateNewId(), extension)
+
ob = self.PUT_factory(file_name, mime_type, None)
# Raise an error if we could not guess the portal type
if ob is None:
raise ValueError, "Could not determine the document type"
+ object_id = ob.getId()
+
# Prevent any reindexing operations
ob.isIndexable = 0
# Then put the file inside ourselves for a short while
- BaseTool._setObject(self, file_name, ob)
- document = BaseTool._getOb(self, file_name)
+ BaseTool._setObject(self, object_id, ob)
+ document = BaseTool._getOb(self, object_id)
try:
# Then edit the document contents (so that upload can happen)
@@ -319,15 +331,15 @@
document.fromURL(url)
finally:
# Remove the object from ourselves
- BaseTool._delObject(self, file_name)
+ BaseTool._delObject(self, object_id)
# Move the document to where it belongs
if container_path is not None:
container = self.getPortalObject().restrictedTraverse(container_path)
- document = self._setObject(file_name, ob, user_login=user_login, id=id,
+ document = self._setObject(object_id, ob, user_login=user_login, id=id,
container=container, discover_metadata=discover_metadata,
)
- document = self._getOb(file_name) # Call _getOb to purge cache
+ document = self._getOb(object_id) # Call _getOb to purge cache
# Notify workflows
#document.notifyWorkflowCreated()
More information about the Erp5-report
mailing list