From c91aad38abe1fc64a597d0c1b4ea1d8eeb0b7b39 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Thu, 15 Mar 2007 23:27:30 +0000
Subject: [PATCH] Overload edit to support file upload.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13442 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/TextDocument.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/product/ERP5/Document/TextDocument.py b/product/ERP5/Document/TextDocument.py
index a24f85e854..d88151b87b 100644
--- a/product/ERP5/Document/TextDocument.py
+++ b/product/ERP5/Document/TextDocument.py
@@ -28,6 +28,7 @@
 
 from AccessControl import ClassSecurityInfo
 
+from Products.CMFCore.WorkflowCore import WorkflowMethod
 from Products.CMFCore.utils import getToolByName
 from Products.CMFCore.utils import _setCacheHeaders
 from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
@@ -87,6 +88,24 @@ class TextDocument(Document, TextContent):
     security.declareProtected(Permissions.View, 'manage_FTPget')
     manage_FTPget = TextContent.manage_FTPget
 
+    # File handling
+    security.declarePrivate( '_edit' )
+    def _edit(self, **kw):
+      """\
+        This is used to edit files which contain HTML content.
+      """
+      if kw.has_key('file'):
+        file = kw.get('file')
+        text_content = file.read()
+        headers, body, format = self.handleText(text=text_content)
+        kw.setdefault('text_format', format)
+        kw.setdefault('text_content', text_content)
+        del kw['file']
+      Document._edit(self, **kw)
+
+    security.declareProtected( Permissions.ModifyPortalContent, 'edit' )
+    edit = WorkflowMethod( _edit )
+    
     # Default Display
     security.declareProtected(Permissions.View, 'index_html')
     def index_html(self, REQUEST, RESPONSE, format=None, **kw):
-- 
2.30.9