From 565d1a18c737021cde9e0faa7b5718ae04992972 Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Mon, 12 Apr 2010 16:22:00 +0530 Subject: [REF+IMP] caldav bzr revid: hmo@tinyerp.com-20100412105200-c3kvao81ypbh8l0g --- addons/document_webdav/webdav.py | 114 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 addons/document_webdav/webdav.py (limited to 'addons/document_webdav/webdav.py') diff --git a/addons/document_webdav/webdav.py b/addons/document_webdav/webdav.py new file mode 100644 index 00000000000..6e816c35e10 --- /dev/null +++ b/addons/document_webdav/webdav.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import xml.dom.minidom +domimpl = xml.dom.minidom.getDOMImplementation() +import urlparse +import urllib +from DAV import utils +from DAV.propfind import PROPFIND + + +super_mk_prop_response = PROPFIND.mk_prop_response +def mk_prop_response(self,uri,good_props,bad_props,doc): + """ make a new result element + + We differ between the good props and the bad ones for + each generating an extra -Node (for each error + one, that means). + + """ + re=doc.createElement("D:response") + # append namespaces to response + nsnum=0 + for nsname in self.namespaces: + re.setAttribute("xmlns:ns"+str(nsnum),nsname) + nsnum=nsnum+1 + + # write href information + uparts=urlparse.urlparse(uri) + fileloc=uparts[2] + href=doc.createElement("D:href") + huri=doc.createTextNode(uparts[0]+'://'+'/'.join(uparts[1:2]) + urllib.quote(fileloc)) + href.appendChild(huri) + re.appendChild(href) + + # write good properties + ps=doc.createElement("D:propstat") + if good_props: + re.appendChild(ps) + + gp=doc.createElement("D:prop") + for ns in good_props.keys(): + ns_prefix="ns"+str(self.namespaces.index(ns))+":" + for p,v in good_props[ns].items(): + if not v: + pass + pe=doc.createElement(ns_prefix+str(p)) + if hasattr(v, '__class__') and v.__class__.__name__ == 'Element': + pe.appendChild(v) + else: + if p=="resourcetype": + if v==1: + ve=doc.createElement("D:collection") + pe.appendChild(ve) + else: + ve=doc.createTextNode(tools.ustr(v)) + pe.appendChild(ve) + + gp.appendChild(pe) + + ps.appendChild(gp) + s=doc.createElement("D:status") + t=doc.createTextNode("HTTP/1.1 200 OK") + s.appendChild(t) + ps.appendChild(s) + re.appendChild(ps) + + # now write the errors! + if len(bad_props.items()): + + # write a propstat for each error code + for ecode in bad_props.keys(): + ps=doc.createElement("D:propstat") + re.appendChild(ps) + bp=doc.createElement("D:prop") + ps.appendChild(bp) + + for ns in bad_props[ecode].keys(): + ns_prefix="ns"+str(self.namespaces.index(ns))+":" + + for p in bad_props[ecode][ns]: + pe=doc.createElement(ns_prefix+str(p)) + bp.appendChild(pe) + + s=doc.createElement("D:status") + t=doc.createTextNode(utils.gen_estring(ecode)) + s.appendChild(t) + ps.appendChild(s) + re.appendChild(ps) + + # return the new response element + return re + + +PROPFIND.mk_prop_response = mk_prop_response + -- cgit v1.2.3 From 37a0b05a170d0fe454f27cfabe8689d0a08ae552 Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Mon, 12 Apr 2010 17:15:51 +0530 Subject: [REF] caldav bzr revid: hmo@tinyerp.com-20100412114551-pkrd135oxul8pw1u --- addons/document_webdav/webdav.py | 1 + 1 file changed, 1 insertion(+) (limited to 'addons/document_webdav/webdav.py') diff --git a/addons/document_webdav/webdav.py b/addons/document_webdav/webdav.py index 6e816c35e10..b69c21d62ee 100644 --- a/addons/document_webdav/webdav.py +++ b/addons/document_webdav/webdav.py @@ -25,6 +25,7 @@ import urlparse import urllib from DAV import utils from DAV.propfind import PROPFIND +import tools super_mk_prop_response = PROPFIND.mk_prop_response -- cgit v1.2.3