From 5f6a18dc39f7a283f77a2c9063c52c1f4777b7b4 Mon Sep 17 00:00:00 2001 From: Jean-Paul Smets <jp@nexedi.com> Date: Sat, 17 Mar 2007 10:04:57 +0000 Subject: [PATCH] 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 --- product/ERP5/Tool/ContributionTool.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/product/ERP5/Tool/ContributionTool.py b/product/ERP5/Tool/ContributionTool.py index a3891ca74c..b838cb4f72 100644 --- a/product/ERP5/Tool/ContributionTool.py +++ b/product/ERP5/Tool/ContributionTool.py @@ -163,9 +163,15 @@ class ContributionTool(BaseTool): file = cStringIO.StringIO() file.write(data) file.seek(0) + kw['file'] = file + del kw['data'] + del kw['file_name'] else: # 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] if hasattr(file, 'headers'): headers = file.headers @@ -189,7 +195,7 @@ class ContributionTool(BaseTool): 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 + # with PUT_factory - we provid<e the mime_type as # parameter ob = self.PUT_factory( file_name, mime_type, None ) @@ -202,7 +208,9 @@ class ContributionTool(BaseTool): document = BaseTool._getOb(self, file_name) # Then edit the document contents (so that upload can happen) + kw.setdefault('source_reference', file_name) document._edit(**kw) + if url: document.fromURL(url) # Remove the object from ourselves BaseTool._delObject(self, file_name) -- 2.30.9