From 9dbe6501096ef5fe4d85618a7d65d9b791e7f29e Mon Sep 17 00:00:00 2001
From: Sebastien Robin <seb@nexedi.com>
Date: Tue, 16 Dec 2003 19:02:10 +0000
Subject: [PATCH] patched DA.PUT so that we can edit zsql method with webdav

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@112 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/ZopePatch.py | 47 +++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/product/ERP5Type/ZopePatch.py b/product/ERP5Type/ZopePatch.py
index b23daac3bf..d843768854 100755
--- a/product/ERP5Type/ZopePatch.py
+++ b/product/ERP5Type/ZopePatch.py
@@ -145,8 +145,13 @@ PropertyManager.propdict = ERP5PropertyManager.propdict
 
 ##############################################################################
 # XML content of zsql methods
+import re
+try: from IOBTree import Bucket
+except: Bucket=lambda:{}
+from Shared.DC.ZRDB.Aqueduct import decodestring, parse
 from Shared.DC.ZRDB.DA import DA
 
+
 class PatchedDA(DA):
 
     def fromFile(self, filename):
@@ -209,9 +214,51 @@ class_file:%s
          self.class_name_, self.class_file_,
          self.arguments_src, self.src)
 
+    # This function doesn't take care about properties by default
+    def PUT(self, REQUEST, RESPONSE):
+        """Handle put requests"""
+        self.dav__init(REQUEST, RESPONSE)
+        self.dav__simpleifhandler(REQUEST, RESPONSE, refresh=1)
+        body = REQUEST.get('BODY', '')
+        m = re.match('\s*<dtml-comment>(.*)</dtml-comment>\s*\n', body, re.I | re.S)
+        if m:
+            property_src = m.group(1)
+            parameters = {}
+            for line in property_src.split('\n'):
+              pair = line.split(':',1)
+              if len(pair)!=2:
+                continue
+              parameters[pair[0].strip().lower()]=pair[1].strip()
+            # check for required and optional parameters
+            max_rows = parameters.get('max_rows',1000)
+            max_cache = parameters.get('max_cache',100)
+            cache_time = parameters.get('cache_time',0)
+            class_name = parameters.get('class_name','')
+            class_file = parameters.get('class_file','')
+            title = parameters.get('title','')
+            connection_id = parameters.get('connection_id','')
+            self.manage_advanced(max_rows, max_cache, cache_time, class_name, class_file)
+            self.title = str(title)
+            self.connection_id = str(connection_id)
+        body = body[m.end():]
+        m = re.match('\s*<params>(.*)</params>\s*\n', body, re.I | re.S)
+        if m:
+            self.arguments_src = m.group(1)
+            self._arg=parse(self.arguments_src)
+            body = body[m.end():]
+        template = body
+        self.src = template
+        self.template=t=self.template_class(template)
+        t.cook()
+        self._v_cache={}, Bucket()
+        RESPONSE.setStatus(204)
+        return RESPONSE
+
+
 DA.fromFile = PatchedDA.fromFile
 DA.fromText = PatchedDA.fromText
 DA.manage_FTPget = PatchedDA.manage_FTPget
+DA.PUT = PatchedDA.PUT
 
 ##############################################################################
 # Optimized rendering of global actions (cache)
-- 
2.30.9