Commit c1319e3b authored by Yusei Tahara's avatar Yusei Tahara

Use new generated id if filename is invalid.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18359 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c34f9bff
...@@ -43,6 +43,7 @@ from Products.ERP5.Document.Url import no_crawl_protocol_list, no_host_protocol_ ...@@ -43,6 +43,7 @@ from Products.ERP5.Document.Url import no_crawl_protocol_list, no_host_protocol_
from zLOG import LOG from zLOG import LOG
from DateTime import DateTime from DateTime import DateTime
from Acquisition import aq_base from Acquisition import aq_base
from zExceptions import BadRequest
# Install openers # Install openers
import ContributionOpener import ContributionOpener
...@@ -299,18 +300,29 @@ class ContributionTool(BaseTool): ...@@ -299,18 +300,29 @@ class ContributionTool(BaseTool):
# with PUT_factory - we provide the mime_type as # with PUT_factory - we provide the mime_type as
# parameter # parameter
# LOG('new content', 0, "%s -- %s" % (file_name, mime_type)) # 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) ob = self.PUT_factory(file_name, mime_type, None)
# Raise an error if we could not guess the portal type # Raise an error if we could not guess the portal type
if ob is None: if ob is None:
raise ValueError, "Could not determine the document type" raise ValueError, "Could not determine the document type"
object_id = ob.getId()
# Prevent any reindexing operations # Prevent any reindexing operations
ob.isIndexable = 0 ob.isIndexable = 0
# Then put the file inside ourselves for a short while # Then put the file inside ourselves for a short while
BaseTool._setObject(self, file_name, ob) BaseTool._setObject(self, object_id, ob)
document = BaseTool._getOb(self, file_name) document = BaseTool._getOb(self, object_id)
try: try:
# Then edit the document contents (so that upload can happen) # Then edit the document contents (so that upload can happen)
...@@ -319,15 +331,15 @@ class ContributionTool(BaseTool): ...@@ -319,15 +331,15 @@ class ContributionTool(BaseTool):
document.fromURL(url) document.fromURL(url)
finally: finally:
# Remove the object from ourselves # Remove the object from ourselves
BaseTool._delObject(self, file_name) BaseTool._delObject(self, object_id)
# Move the document to where it belongs # Move the document to where it belongs
if container_path is not None: if container_path is not None:
container = self.getPortalObject().restrictedTraverse(container_path) 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, 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 # Notify workflows
#document.notifyWorkflowCreated() #document.notifyWorkflowCreated()
......
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