[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/interface - tests.py:1.1 __init__.py:1.7 browse.pt:1.4 detail.pt:1.9

The Unidentified User cvs-admin at zope.org
Tue Dec 9 08:20:49 EST 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/services/interface
In directory cvs.zope.org:/tmp/cvs-serv14869/app/browser/services/interface

Modified Files:
	__init__.py browse.pt detail.pt 
Added Files:
	tests.py 
Log Message:
Added new look to interface service browser and details views.


=== Added File Zope3/src/zope/app/browser/services/interface/tests.py ===
import unittest, doctest

def test_suite():
    return unittest.TestSuite((
        doctest.DocTestSuite('zope.app.browser.services.interface'),
        ))

if __name__ == '__main__':
    unittest.main()


=== Zope3/src/zope/app/browser/services/interface/__init__.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/services/interface/__init__.py:1.6	Tue Nov  4 22:08:23 2003
+++ Zope3/src/zope/app/browser/services/interface/__init__.py	Tue Dec  9 08:20:18 2003
@@ -16,20 +16,88 @@
 from zope.interface.interfaces import IMethod
 from zope.schema.interfaces import IField
 from zope.app.interfaces.services.interface import IInterfaceBasedRegistry
-
 from zope.app import zapi
 
 class Interfaces:
+    """Interface service view
+
+    >>> class DCInterface:
+    ...     '''DCInterfaceDoc
+    ...
+    ...     This is a multi-line doc string.
+    ...     '''
+    ... 
+    >>> class DummyInterface:
+    ...     def items(self):
+    ...         return [('DCInterface', DCInterface)]
+    ...
+    >>> from zope.publisher.browser import TestRequest
+    >>> request = TestRequest()
+    >>> interface_view = Interfaces(DummyInterface(), request)
+    >>> interface_view.getInterfaces()
+    [{'doc': 'DCInterfaceDoc', 'id': 'DCInterface', 'name': 'DCInterface'}]
+    
+    
+    """
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
 
     def getInterfaces(self):
-        L = [(iface.getName(), id) for id, iface in self.context.items()]
+        L = [(iface.__name__, id, iface.__doc__.split('\n')[0].strip())
+             for id, iface in self.context.items()]
         L.sort()
-        return [{"id": id, "name": name} for name, id in L]
+        return [{"id": id, "name": name, "doc": doc} for name, id, doc in L]
 
 class Detail:
-
+    """Interface Details
+    
+    >>> from zope.schema import TextLine
+    >>> from zope.interface import Interface
+    >>> from zope.i18n import MessageIDFactory
+    >>> _ = MessageIDFactory('zope')
+    >>> class TestInterface(Interface):
+    ...     '''Test Interface'''
+    ...     test_field = TextLine(title = _(u'Test Name'))
+    ...     def testMethod():
+    ...         'Returns test name'
+    ...
+    >>> class TestClass:
+    ...     def getInterface(self, id=None):
+    ...         return TestInterface
+    ...
+    >>> from zope.publisher.browser import TestRequest
+    >>> request = TestRequest()
+    >>> form = {'id': 'TestInterface'}
+    >>> request.form = form
+    >>> interface_details = Detail(TestClass(), request)
+    >>> interface_details.setup()
+    >>> interface_details.name
+    'TestInterface'
+    >>> interface_details.doc
+    'Test Interface'
+    >>> interface_details.iface.__name__
+    'TestInterface'
+    >>> [method['method'].__name__ for method in
+    ...     interface_details.methods]
+    ['testMethod']
+    >>> [field.__name__ for field in interface_details.schema]
+    ['test_field']
+
+    
+    """
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+    
     def setup(self):
-        id = self.request["id"]
+        try:
+            id = self.request["id"]
+        except KeyError:
+            raise zapi.UserError("Please click on an interface name to view"
+                  " details.")
         iface = self.context.getInterface(id)
 
         from zope.proxy import getProxiedObject
@@ -45,7 +113,8 @@
         for name in self.iface:
             defn = self.iface[name]
             if IMethod.isImplementedBy(defn):
-                self.methods.append(defn)
+                title = defn.__doc__.split('\n')[0].strip()
+                self.methods.append({'method': defn, 'title': title})
             elif IField.isImplementedBy(defn):
                 self.schema.append(defn)
 


=== Zope3/src/zope/app/browser/services/interface/browse.pt 1.3 => 1.4 ===
--- Zope3/src/zope/app/browser/services/interface/browse.pt:1.3	Thu Aug  7 13:41:19 2003
+++ Zope3/src/zope/app/browser/services/interface/browse.pt	Tue Dec  9 08:20:18 2003
@@ -3,15 +3,25 @@
 <div metal:fill-slot="body">
 
   <h2 i18n:translate="">Interfaces registered with the interface service</h2>
-
-  <ul>
-    <li tal:repeat="dict view/getInterfaces">
-      <a href="/" 
+  
+  <table class="listingdescription" summary="Interfaces Listing"
+      cellspacing="0">
+    <thead>
+      <th>Interface Name</th>
+      <th>Title</th>
+    </thead>
+    <tal:repeat tal:repeat="dict view/getInterfaces">
+    <tr tal:define="oddrow repeat/dict/odd;"
+        tal:attributes="class python:oddrow and 'even' or 'odd'">
+      <td>
+        <a href="/" 
          tal:attributes="href string:detail.html?id=${dict/id}"
          tal:content="dict/name">An interface name
-      </a>
-    </li>
-  </ul>
+        </a></td>  
+      <td tal:content="dict/doc">Interface DocString</td>
+    </tr>
+    </tal:repeat>
+  </table>  
 
 </div>
 </body>


=== Zope3/src/zope/app/browser/services/interface/detail.pt 1.8 => 1.9 ===
--- Zope3/src/zope/app/browser/services/interface/detail.pt:1.8	Wed Aug 20 14:21:08 2003
+++ Zope3/src/zope/app/browser/services/interface/detail.pt	Tue Dec  9 08:20:18 2003
@@ -14,18 +14,55 @@
 
   <div tal:condition="view/methods">
     <h3 i18n:translate="class-methods">Methods</h3> 
-    <ul>
-      <li tal:repeat="method view/methods"
-          tal:content="method/__name__">Method name</li>
-    </ul>
+      <table class="listingdescription" summary="Method Listing"
+          cellspacing="0">
+        <thead>
+          <th>Method Signature</th>
+          <th>Description</th>
+        </thead>    
+        <tal:repeat repeat="methoddict view/methods">
+        <tr tal:define="oddrow repeat/methoddict/odd;"
+            tal:attributes="class python:oddrow and 'even' or 'odd'">
+          <td>
+            <strong>
+              <span tal:replace="methoddict/method/__name__" /></strong><span 
+                  tal:replace="methoddict/method/getSignatureString">
+              Info
+            </span>
+          </td>
+          <td tal:content="methoddict/title"></td>
+        </tr>
+        </tal:repeat>
+      </table>  
   </div>
 
   <div tal:condition="view/schema">
     <h3 i18n:translate="schema-component">Schema</h3>
-    <ul>
-      <li tal:repeat="field view/schema"
-          tal:content="field/__name__">Field name</li>
-    </ul>
+      <table class="listingdescription" summary="Schema Listing"
+          cellspacing="0">
+        <thead>
+          <th>Field Name</th>
+          <th>Type</th>
+          <th>Description</th>
+        </thead>    
+        <tal:repeat repeat="field view/schema">
+        <tal:define define="oddrow repeat/field/odd;
+                            class python:oddrow and 'even' or 'odd'">
+        <tr tal:attributes="class class">
+          <td nowrap="nowrap">
+            <strong>
+              <span tal:replace="field/__name__" />
+              <span tal:condition="field/required"
+                  tal:replace="string:*">Required?</span>
+            </strong>
+          </td>  
+          <td tal:content="field/__class__/__name__"></td>  
+          <td tal:content="field/description"></td>
+        </tr>
+        </tal:define>
+        </tal:repeat>
+      </table>  
+      <p>* indicates required fields.</p>
   </div>
 
   <div tal:repeat="service view/getServices">
@@ -34,13 +71,23 @@
        service
     </h3>
 
-    <ul>
-      <li tal:repeat="reg service/registrations">
-        <em tal:content="reg/status">status</em>
-        <strong tal:content="reg/usageSummary">usage</strong><br />
-        <span tal:content="reg/implementationSummary">impl</span>
-      </li>
-    </ul>
+  <table class="listingdescription" summary="Registration Listing"
+      cellspacing="0">
+    <thead>
+      <th>Status</th>
+      <th>Usage Summary</th>
+      <th>Implementation Summary</th>
+    </thead>
+    <tal:repeat repeat="reg service/registrations">
+      <tr tal:define="oddrow repeat/reg/odd"
+          tal:attributes="class python:oddrow and 'even' or 'odd'">
+        <td tal:content="reg/status">Status</td>
+        <td tal:content="reg/usageSummary">Usage Summary</td>
+        <td tal:content="reg/implementationSummary">Implementation</td>
+      </tr>
+    </tal:repeat>
+  </table>
+
   </div>
 
 </div>




More information about the Zope3-Checkins mailing list