[Zope3-checkins] SVN: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/ Move the opaque property rendering out to the opaque property adapter; this

Martijn Pieters mj at zopatista.com
Mon Oct 11 05:36:56 EDT 2004


Log message for revision 27944:
  Move the opaque property rendering out to the opaque property adapter; this
  becomes more important when we start to deal with complex properties later on.
  


Changed:
  U   Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py
  U   Zope3/branches/isarsprint-dav-work/src/zope/app/dav/propfind.py


-=-
Modified: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py	2004-10-11 09:16:54 UTC (rev 27943)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py	2004-10-11 09:36:55 UTC (rev 27944)
@@ -80,3 +80,14 @@
     def __delitem__(self, key):
         del self._mapping[key]
         self._changed()
+        
+    # Convenience methods; storing and retrieving properties through WebDAV
+    def renderProperty(self, ns, nsprefix, prop, propel):
+        """Render a property as DOM elements"""
+        value = self.get(ns, {}).get(prop)
+        if value is None:
+            return
+        el = propel.ownerDocument.createElement('%s' % prop)
+        el.setAttribute('xmlns', nsprefix)
+        el.appendChild(el.ownerDocument.createTextNode(value[1]))
+        propel.appendChild(el)

Modified: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/propfind.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/propfind.py	2004-10-11 09:16:54 UTC (rev 27943)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/propfind.py	2004-10-11 09:36:55 UTC (rev 27944)
@@ -112,36 +112,31 @@
                     count += 1
                     prop.setAttribute('xmlns:%s' % attr_name, ns)
                 iface = _props[ns]['iface']
-                initial = {}
 
-                if iface:
-                    # The registered namespace case
-                    adapter = iface(self.context, None)
-                    for name in avail.get(ns):
-                        value = getattr(adapter, name, None)
-                        if value is not None:
-                            initial[name] = value
-                    setUpWidgets(self, iface, IDAVWidget,
-                        ignoreStickyValues=True, initial=initial, 
-                        names=avail.get(ns))
-                else:
-                    # The opaque properties case
+                if not iface:
+                    # The opaque properties case, hand it off
                     oprops = IDAVOpaqueNamespaces(self.context, {})
                     for name in avail.get(ns):
-                        value = oprops.get(ns, {}).get(name)
-                        if value is not None:
-                            initial[name] = value[1]
+                        oprops.renderProperty(ns, attr_name, name, prop)
+                    continue
+                
+                # The registered namespace case
+                initial = {}
+                adapter = iface(self.context, None)
+                for name in avail.get(ns):
+                    value = getattr(adapter, name, None)
+                    if value is not None:
+                        initial[name] = value
+                setUpWidgets(self, iface, IDAVWidget,
+                    ignoreStickyValues=True, initial=initial, 
+                    names=avail.get(ns))
                             
                 for p in avail.get(ns):
                     el = response.createElement('%s' % p )
                     if ns is not None and ns != self.default_ns:
                         el.setAttribute('xmlns', attr_name)
                     prop.appendChild(el)
-                    if iface:
-                        # A registered namespace property
-                        value = getattr(self, p+'_widget')()
-                    else:
-                        value = initial[p]
+                    value = getattr(self, p+'_widget')()
                         
                     if isinstance(value, (unicode, str)):
                         # Get the widget value here



More information about the Zope3-Checkins mailing list