Commit 87224116 authored by Nicolas Delaby's avatar Nicolas Delaby

Guess portal_type only once

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24478 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 72af3bd9
...@@ -202,35 +202,27 @@ class ContributionTool(BaseTool): ...@@ -202,35 +202,27 @@ class ContributionTool(BaseTool):
if file is None: if file is None:
raise ValueError, "could not determine portal type" raise ValueError, "could not determine portal type"
# So we will simulate WebDAV to get an empty object
# with PUT_factory - we provide the mime_type as
# parameter
# LOG('new content', 0, "%s -- %s" % (file_name, mime_type))
# #
# Check if same file is already exists. if it exists, then update it. # Check if same file is already exists. if it exists, then update it.
# #
if portal_type is None: if portal_type is None:
registry = getToolByName(self, 'portal_contribution_registry', None) portal_type = self._guessPortalType(file_name, mime_type, data)
if registry is not None: property_dict = self.getMatchedFileNamePatternDict(file_name)
portal_type = registry.findPortalTypeName(file_name, None, data) reference = property_dict.get('reference', None)
property_dict = self.getMatchedFileNamePatternDict(file_name) version = property_dict.get('version', None)
reference = property_dict.get('reference', None) language = property_dict.get('language', None)
version = property_dict.get('version', None) if portal_type and reference and version and language:
language = property_dict.get('language', None) portal_catalog = getToolByName(self, 'portal_catalog')
if portal_type and reference and version and language: document = portal_catalog.getResultValue(portal_type=portal_type,
portal_catalog = getToolByName(self, 'portal_catalog') reference=reference,
document = portal_catalog.getResultValue(portal_type=portal_type, version=version,
reference=reference, language=language)
version=version, if document is not None:
language=language) # document is already uploaded. So overrides file.
if document is not None: if not _checkPermission(Permissions.ModifyPortalContent, document):
# document is already uploaded. So overrides file. raise Unauthorized, "[DMS] You are not allowed to update the existing document which has the same coordinates (id %s)" % document.getId()
if not _checkPermission(Permissions.ModifyPortalContent, document): document.edit(file=kw['file'])
raise Unauthorized, "[DMS] You are not allowed to update the existing document which has the same coordinates (id %s)" % document.getId() return document
document.edit(file=kw['file'])
return document
# #
# Strong possibility of a new file. # Strong possibility of a new file.
...@@ -243,10 +235,6 @@ class ContributionTool(BaseTool): ...@@ -243,10 +235,6 @@ class ContributionTool(BaseTool):
extension = '.%s' % file_name.split('.')[-1] extension = '.%s' % file_name.split('.')[-1]
file_name = '%s%s' % (self.generateNewId(), extension) file_name = '%s%s' % (self.generateNewId(), extension)
# Try to guess the portal if it is not passed as parameter
if portal_type is None:
portal_type = self._guessPortalType(file_name, mime_type, data)
# Then put the file inside ourselves for a short while # Then put the file inside ourselves for a short while
if container_path is not None: if container_path is not None:
container = self.getPortalObject().restrictedTraverse(container_path) container = self.getPortalObject().restrictedTraverse(container_path)
......
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