From 03f75208897d62309bfc8664b5d2cadb68e07295 Mon Sep 17 00:00:00 2001
From: Yoshinori Okuji <yo@nexedi.com>
Date: Mon, 20 Dec 2004 14:15:58 +0000
Subject: [PATCH] (alex) jp added the importFile function that allows to import
 a business template.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2055 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Tool/TemplateTool.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/product/ERP5/Tool/TemplateTool.py b/product/ERP5/Tool/TemplateTool.py
index be59849e49..714313807f 100755
--- a/product/ERP5/Tool/TemplateTool.py
+++ b/product/ERP5/Tool/TemplateTool.py
@@ -176,7 +176,6 @@ class TemplateTool (BaseTool):
       """
       from urllib import urlretrieve
       file, headers = urlretrieve(url)
-      if id is None: id = self.generateNewId()
       self._importObjectFromFile(file, id=id)
       bt = self[id]
       bt.id = id # Make sure id is consistent
@@ -187,4 +186,24 @@ class TemplateTool (BaseTool):
         REQUEST.RESPONSE.redirect("%s?portal_status_message=Business+Template+Downloaded+Successfully"
                            % self.absolute_url())
 
+    def importFile(self, file, id=None, REQUEST=None):
+      """
+        Update an existing template
+      """
+      from tempfile import mkstemp
+      tempid, temppath = mkstemp()
+      tempfile = open(temppath, 'w')
+      tempfile.write(file)
+      tempfile.close()
+      self._importObjectFromFile(temppath, id=id)
+      os.remove(temppath)
+      bt = self[id]
+      bt.id = id # Make sure id is consistent
+      #LOG('Template Tool', 0, 'Indexing %r, isIndexable = %r' % (bt, bt.isIndexable))
+      bt.immediateReindexObject()
+
+      if REQUEST is not None:
+        REQUEST.RESPONSE.redirect("%s?portal_status_message=Business+Template+Downloaded+Successfully"
+                           % self.absolute_url())
+
 InitializeClass(TemplateTool)
-- 
2.30.9