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

Support of url parameter in order to download a document from a URL. Set...

Support of url parameter in order to download a document from a URL. Set source reference directly here rather than in all Document classes.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13464 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 96ad6077
...@@ -163,9 +163,15 @@ class ContributionTool(BaseTool): ...@@ -163,9 +163,15 @@ class ContributionTool(BaseTool):
file = cStringIO.StringIO() file = cStringIO.StringIO()
file.write(data) file.write(data)
file.seek(0) file.seek(0)
kw['file'] = file
del kw['data']
del kw['file_name']
else: else:
# build a new file from the url # build a new file from the url
file = urllib2.urlopen(url) data = urllib2.urlopen(url).read()
file = cStringIO.StringIO()
file.write(data)
file.seek(0)
file_name = url.split('/')[-1] file_name = url.split('/')[-1]
if hasattr(file, 'headers'): if hasattr(file, 'headers'):
headers = file.headers headers = file.headers
...@@ -189,7 +195,7 @@ class ContributionTool(BaseTool): ...@@ -189,7 +195,7 @@ class ContributionTool(BaseTool):
raise ValueError, "could not determine portal type" raise ValueError, "could not determine portal type"
# So we will simulate WebDAV to get an empty object # So we will simulate WebDAV to get an empty object
# with PUT_factory - we provide the mime_type as # with PUT_factory - we provid<e the mime_type as
# parameter # parameter
ob = self.PUT_factory( file_name, mime_type, None ) ob = self.PUT_factory( file_name, mime_type, None )
...@@ -202,7 +208,9 @@ class ContributionTool(BaseTool): ...@@ -202,7 +208,9 @@ class ContributionTool(BaseTool):
document = BaseTool._getOb(self, file_name) document = BaseTool._getOb(self, file_name)
# Then edit the document contents (so that upload can happen) # Then edit the document contents (so that upload can happen)
kw.setdefault('source_reference', file_name)
document._edit(**kw) document._edit(**kw)
if url: document.fromURL(url)
# Remove the object from ourselves # Remove the object from ourselves
BaseTool._delObject(self, file_name) BaseTool._delObject(self, file_name)
......
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