From f4bc8371430aa5f0fec2a1d52fda558e6ba0e3d0 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 12 Oct 2010 13:40:29 +0300 Subject: [PATCH] Doc webdav: enhance the property notation structure When DAV-aware nodes want to return properties, they might need to have xml attributes or single instances of sub-elements. Example: return ('aprop', 'D:', ('foo', 'D:', None, { 'name': 'bar'})) will result in xml: bzr revid: p_christ@hol.gr-20101012104029-gq6hhjki4i52n8qh --- addons/document_webdav/webdav.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/document_webdav/webdav.py b/addons/document_webdav/webdav.py index 6b24198e320..86fd8cd9e71 100644 --- a/addons/document_webdav/webdav.py +++ b/addons/document_webdav/webdav.py @@ -67,6 +67,8 @@ def mk_prop_response(self, uri, good_props, bad_props, doc): string: text node tuple ('elem', 'ns') for empty sub-node tuple ('elem', 'ns', sub-elems) for sub-node with elements + tuple ('elem', 'ns', sub-elems, {attrs}) for sub-node with + optional elements and attributes list, of above tuples """ if ns == 'DAV:': @@ -108,14 +110,18 @@ def mk_prop_response(self, uri, good_props, bad_props, doc): ve=doc.createElement(ns_prefix+v[0]) if need_ns: ve.setAttribute("xmlns:ns"+str(nsnum), v[1]) - if len(v) > 2: - if isinstance(v[2], list): + if len(v) > 2 and v[2] is not None: + if isinstance(v[2], (list, tuple)): # support nested elements like: # ( 'elem', 'ns:', [('sub-elem1', 'ns1'), ...] _prop_elem_child(ve, v[1], v[2], ns_prefix) else: vt =doc.createTextNode(tools.ustr(v[2])) ve.appendChild(vt) + if len(v) > 3 and v[3]: + assert isinstance(v[3], dict) + for ak, av in v[3].items(): + ve.setAttribute(ak, av) pnode.appendChild(ve) else: ve=doc.createTextNode(tools.ustr(v))