Commit 21295982 authored by Nicolas Delaby's avatar Nicolas Delaby

Remove method inspection and fallback to standard API

  * The purpose of this special argument set_filename__ was
to avoid overloading the filename provided by the user in by File._edit
  * Small typo refactoring
Reviewed by Jerome


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32051 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4c7a088d
...@@ -103,18 +103,17 @@ class File(Document, CMFFile, CachedConvertableMixin): ...@@ -103,18 +103,17 @@ class File(Document, CMFFile, CachedConvertableMixin):
### Special edit method ### Special edit method
security.declarePrivate( '_edit' ) security.declarePrivate( '_edit' )
def _edit(self, set_filename__=1, **kw): def _edit(self, **kw):
"""\ """
This is used to edit files This is used to edit files
""" """
if kw.has_key('file'): if kw.has_key('file'):
file = kw.get('file') file = kw.get('file')
precondition = kw.get('precondition') precondition = kw.get('precondition')
if set_filename__:
filename = getattr(file, 'filename', None) filename = getattr(file, 'filename', None)
# if file field is empty(no file is uploaded), # if file field is empty(no file is uploaded),
# filename is empty string. # filename is empty string.
if filename not in (None, ''): if filename:
self._setSourceReference(filename) self._setSourceReference(filename)
if self._isNotEmpty(file): if self._isNotEmpty(file):
self._setFile(file, precondition=precondition) self._setFile(file, precondition=precondition)
......
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2007 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -32,7 +33,6 @@ import string ...@@ -32,7 +33,6 @@ import string
import socket import socket
import md5 import md5
import urllib2, urllib import urllib2, urllib
import inspect
from AccessControl import ClassSecurityInfo, getSecurityManager from AccessControl import ClassSecurityInfo, getSecurityManager
from Products.ERP5Type.Globals import InitializeClass, DTMLFile from Products.ERP5Type.Globals import InitializeClass, DTMLFile
...@@ -128,10 +128,14 @@ class ContributionTool(BaseTool): ...@@ -128,10 +128,14 @@ class ContributionTool(BaseTool):
We always generate ID. So, we must prevent using the one We always generate ID. So, we must prevent using the one
which we were provided. which we were provided.
""" """
if file_name is not None: kw['file_name'] = file_name user_filename = file_name # store original filename
if data is not None: kw['data'] = data # This is only used to make sure if file_name is not None:
kw['file_name'] = file_name
if data is not None:
# This is only used to make sure
# we can pass file as parameter to ZPublisher # we can pass file as parameter to ZPublisher
# whenever we ingest email # whenever we ingest email
kw['data'] = data
# Temp objects use the standard newContent from Folder # Temp objects use the standard newContent from Folder
if temp_object: if temp_object:
# For temp_object creation, use the standard method # For temp_object creation, use the standard method
...@@ -240,12 +244,13 @@ class ContributionTool(BaseTool): ...@@ -240,12 +244,13 @@ class ContributionTool(BaseTool):
kw.update(modified_kw) kw.update(modified_kw)
# Then edit the document contents (so that upload can happen) # Then edit the document contents (so that upload can happen)
if 'set_filename__' in inspect.getargspec(document._edit)[0]:
# Only a few classes supports set_filename__.
document._edit(set_filename__=0, **kw)
document.guessMimeType(fname=file_name)
else:
document._edit(**kw) document._edit(**kw)
if getattr(document, 'guessMimeType', None) is not None:
# For File force to setup the mime_type
document.guessMimeType(fname=file_name)
if user_filename:
# Restore the Original filename pass by the user
document.setSourceReference(user_filename)
if url: if url:
document.fromURL(url) document.fromURL(url)
......
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