[Zope-CVS] CVS: Packages/Moztop/moztopsupport/dav - configure.zcml:1.4 propfind.py:1.4 views.py:1.2

Sidnei da Silva sidnei@x3ng.com.br
Mon, 24 Mar 2003 16:12:01 -0500


Update of /cvs-repository/Packages/Moztop/moztopsupport/dav
In directory cvs.zope.org:/tmp/cvs-serv6224/dav

Modified Files:
	configure.zcml propfind.py views.py 
Log Message:
iirc. its my impression or the code got even uglier? im trying to make progress while working around a possible misconfiguration on zope3, that doenst allows me to get a absolute_url view for a RootFolder

=== Packages/Moztop/moztopsupport/dav/configure.zcml 1.3 => 1.4 ===
--- Packages/Moztop/moztopsupport/dav/configure.zcml:1.3	Mon Mar 24 11:15:37 2003
+++ Packages/Moztop/moztopsupport/dav/configure.zcml	Mon Mar 24 16:12:00 2003
@@ -16,4 +16,25 @@
     permission="zope.ManageContent"
     />
 
+  <browser:page
+    for="*"
+    name="DAVdisplayname"
+    class=".views.DAVDisplayName"
+    permission="zope.Public"
+    />
+
+  <browser:page
+    for="*"
+    name="DAVcreationdate"
+    class=".views.DAVCreationDate"
+    permission="zope.Public"
+    />
+
+  <browser:page
+    for="*"
+    name="DAVresourcetype"
+    class=".views.DAVResourceType"
+    permission="zope.Public"
+    />
+
 </zopeConfigure>


=== Packages/Moztop/moztopsupport/dav/propfind.py 1.3 => 1.4 ===
--- Packages/Moztop/moztopsupport/dav/propfind.py:1.3	Mon Mar 24 11:15:37 2003
+++ Packages/Moztop/moztopsupport/dav/propfind.py	Mon Mar 24 16:12:00 2003
@@ -16,10 +16,12 @@
 __metaclass__ = type
 
 from xml.dom import minidom
-from zope.component import getAdapter, getView
+from zope.component import getAdapter, getView, queryView
 
 from moztopsupport.dav.interfaces import IDAVSource
 
+_avail_props = ['displayname', 'creationdate', 'resourcetype']
+
 class PROPFIND:
     """PROPFIND handler for all objects
     """
@@ -41,31 +43,58 @@
         hostname = request.getHeader('hostname', '')
         data = request.bodyFile
         response = ''
+        body = ''
 
         if content_type.lower() not in ['text/xml', 'application/xml']:
             request.response.setStatus(400)
-            return ''
+            return body
 
         depth = request.getHeader('depth', 'infinity')
         
         if depth.lower() not in ['0', '1', 'infinity']:
             request.response.setStatus(400)
-            return ''
+            return body
 
         self.setDepth(depth)
 
         xmldoc = minidom.parse(data)
-        source = xmldoc.getElementsByTagName('D:source')
-        if source:
-            response = str(getView(self.context, 'DAVsource', self.request))
-
+        source = xmldoc.getElementsByTagName('prop')
+        if not source:
+            # possibly allprop
+            body = self._buildBody(self._buildProps(_avail_props))
+            request.response.setStatus(207)
+            request.response.setBody(body)
+            return body
+
+        source = source[0]
+        childs = [e for e in source.childNodes
+                  if e.nodeType == e.ELEMENT_NODE]
+        not_avail = []
+        for node in childs:
+            tagname = node.tagName
+            view = queryView(self.context, 'DAV%s' % tagname, self.request, None)
+            if view is None:
+                not_avail.append(tagname)
+            else:
+                response += str(view)
+
+        if response:
+            response = self._buildOk(response)
+
+        if not_avail:
+            response += self._buildNotAvail(not_avail)
+            
         body = self._buildBody(response)
         request.response.setBody(body)
+            
         request.response.setStatus(207)
-        return ''
+        return body
 
     def _buildBody(self, response):
-        resource_url = str(getView(self.context, 'absolute_url', self.request))
+        try:
+            resource_url = str(getView(self.context, 'absolute_url', self.request))
+        except:
+            resource_url = 'foo'
         return self._xml % ({'resource_url':resource_url,
                              'response':response})
 
@@ -73,10 +102,35 @@
         <D:multistatus xmlns:D="DAV:">
           <D:response>
             <D:href>%(resource_url)s</D:href>
-            <D:propstat>
-            <D:prop>%(response)s</D:prop>
-            <D:status>HTTP/1.1 200 OK</D:status>
-            </D:propstat>
+            %(response)s
          </D:response>
        </D:multistatus>
     '''
+
+    def _buildProps(self, props):
+        result = ''
+        for p in props:
+            result += '<D:%s />' % p
+        return result
+
+    def _buildOK(self, response):
+        return self._ok_xml % {'response':response}
+
+    _ok_xml = '''<D:propstat>
+    <D:prop>%(response)s</D:prop>
+    <D:status>HTTP/1.1 200 OK</D:status>
+    </D:propstat>'''
+
+    def _buildNotAvail(self, props):
+        props = self._buildProps(props)
+        return self._not_avail_xml % {'props':props}
+
+    _not_avail_xml = '''<D:propstat>
+        <D:prop>
+        %(props)s
+        </D:prop>
+        <D:status>HTTP/1.1 403 Forbidden</D:status>
+        <D:responsedescription> The user does not have access to this resource.
+        </D:responsedescription>
+        </D:propstat>
+        '''


=== Packages/Moztop/moztopsupport/dav/views.py 1.1 => 1.2 ===
--- Packages/Moztop/moztopsupport/dav/views.py:1.1	Mon Mar 24 10:38:23 2003
+++ Packages/Moztop/moztopsupport/dav/views.py	Mon Mar 24 16:12:00 2003
@@ -1,7 +1,10 @@
+from zope.component import getView, getAdapter
+from zope.app.interfaces.traversing import IObjectName
+from zope.app.interfaces.dublincore import IDCTimes
+from zope.app.interfaces.container import IReadContainer
 from zope.publisher.browser import BrowserView
-from zope.component import getView
 
-from moztopsupport.dav.interfaces import IDAVSource
+from moztopsupport.dav.interfaces import IDAVSource, IDAVDisplayName, IDAVCreationDate
 
 class ZPTDAVSource(BrowserView):
 
@@ -22,4 +25,54 @@
        <D:dst>%(source_url)s</D:dst>
       </D:link>
     </D:source>
+    '''
+
+class DAVDisplayName(BrowserView):
+
+    __implements__ = IDAVDisplayName
+
+    def __str__(self):
+        value = getAdapter(self.context, IObjectName)()
+        return self._xml % {'value':value}
+
+    __call__ = __str__
+    
+    _xml = '''
+    <D:displayname>
+      %(value)s
+    </D:displayname>
+    '''
+
+class DAVCreationDate(BrowserView):
+
+    __implements__ = IDAVCreationDate
+
+    def __str__(self):
+        value = getAdapter(self.context, IDCTimes).created
+        return self._xml % {'value':value}
+
+    __call__ = __str__
+    
+    _xml = '''
+    <D:creationdate>
+      %(value)s
+    </D:creationdate>
+    '''
+
+class DAVResourceType(BrowserView):
+
+    def __str__(self):
+        value = queryAdapter(self.context, IReadContainer)
+        if value is not None:
+            value = '<D:collection />'
+        else:
+            value = ''
+        return self._xml % {'value':value}
+
+    __call__ = __str__
+    
+    _xml = '''
+    <D:resourcetype>
+      %(value)s
+    </D:resourcetype>
     '''