[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/service - interfacebrowse.pt:1.1 interfacedetail.pt:1.1 interfacemethoddetail.pt:1.1 __init__.py:1.21 configure.zcml:1.10

Suresh Babu Eddala sbabu at zeomega.com
Fri Mar 5 10:49:56 EST 2004


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

Modified Files:
	__init__.py configure.zcml 
Added Files:
	interfacebrowse.pt interfacedetail.pt interfacemethoddetail.pt 
Log Message:


interface service views moved to site manager.




=== Added File Zope3/src/zope/app/browser/services/service/interfacebrowse.pt ===
<html metal:use-macro="context/@@standard_macros/page">
<body>
<div metal:fill-slot="body">

  <h2 i18n:translate="">Interfaces registered with the Utility service</h2>
  
  <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:interfacedetail.html?id=${dict/id}"
         tal:content="dict/name">An interface name
        </a></td>  
      <td tal:content="dict/doc">Interface DocString</td>
    </tr>
    </tal:repeat>
  </table>  

</div>
</body>
</html>


=== Added File Zope3/src/zope/app/browser/services/service/interfacedetail.pt ===
<html metal:use-macro="context/@@standard_macros/page">
<body>
<div metal:fill-slot="body" tal:define="ignored view/setup">

  <h2 i18n:translate="">
    Interface
    <span tal:content="view/name" i18n:name="iface_name">name</span>
  </h2>

  <div tal:condition="view/doc">
    <h3 i18n:translate="">Documentation</h3>
    <div tal:content="view/doc">This is a doc string.</div>
  </div>

  <div tal:condition="view/methods">
    <h3 i18n:translate="class-methods">Methods</h3> 
      <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>
            <a href="/" 
               tal:attributes="href string:interfacemethoddetail.html?interface_id=${request/id}&method_id=${methoddict/method/__name__}">
               <strong><span tal:replace="string:${methoddict/method/__name__}"
                   >Method Name</span></strong><span 
                   tal:replace="string:${methoddict/method/getSignatureString}"
                   >Method Signature</span>
            </a>
          </td>
          <td tal:content="methoddict/title"></td>
        </tr>
        </tal:repeat>
      </table>  
  </div>

  <div tal:condition="view/schema">
    <h3 i18n:translate="schema-component">Schema</h3>
      <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">
    <h3 i18n:translate="">Registrations for 
      <span tal:content="service/name" i18n:name="service_name">Name</span> 
       service
    </h3>

  <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>
</body>
</html>


=== Added File Zope3/src/zope/app/browser/services/service/interfacemethoddetail.pt ===
<html metal:use-macro="context/@@standard_macros/page">
<body>
<div metal:fill-slot="body" tal:define="ignored view/setup">

  <h2 i18n:translate="">
    <span tal:replace="string:${view/iface/__name__}.${view/name}${view/method/getSignatureString}">Method Signature</span>
  </h2>

  <div tal:content="view/doc">This is a doc string.</div>

</div>
</body>
</html>


=== Zope3/src/zope/app/browser/services/service/__init__.py 1.20 => 1.21 ===
--- Zope3/src/zope/app/browser/services/service/__init__.py:1.20	Wed Mar  3 05:38:37 2004
+++ Zope3/src/zope/app/browser/services/service/__init__.py	Fri Mar  5 10:49:55 2004
@@ -17,7 +17,6 @@
 """
 
 from zope.proxy import removeAllProxies
-
 from zope.app import zapi
 from zope.app.browser.container.adding import Adding
 from zope.app.i18n import ZopeMessageIDFactory as _
@@ -33,6 +32,12 @@
 from zope.app.services.service import SiteManager
 from zope.app.component.nextservice import getNextServiceManager
 from zope.component.service import IGlobalServiceManager
+from zope.interface.interfaces import IMethod
+from zope.schema.interfaces import IField
+from zope.app.interfaces.services.interface import IInterfaceBasedRegistry
+from zope.app.component.interface import searchInterface
+from zope.app.component.interface import getInterface
+from zope.app.component.interface import provideInterface
 
 class ComponentAdding(Adding):
     """Adding subclass used for registerable components."""
@@ -485,3 +490,198 @@
         sm = SiteManager(bare)
         self.context.setSiteManager(sm)
         self.request.response.redirect("++etc++site/@@SelectedManagementView.html")
+
+
+class Interfaces:
+    """Interface service view
+
+    >>> from zope.interface import Interface
+    >>> from zope.app.content.interfaces import IContentType
+    >>> class DCInterface(Interface):
+    ...     '''DCInterfaceDoc
+    ...
+    ...     This is a multi-line doc string.
+    ...     '''
+    ... 
+    >>> class DummyInterface:
+    ...     def items(self):
+    ...         return [('DCInterface', DCInterface)]
+    ...
+    >>> provideInterface('', DCInterface, IContentType)
+    >>> from zope.publisher.browser import TestRequest
+    >>> request = TestRequest()
+    >>> interface_view = Interfaces(DummyInterface(), request)
+    >>> from pprint import PrettyPrinter
+    >>> pprint=PrettyPrinter(width=50).pprint
+    >>> pprint(interface_view.getInterfaces())
+    [{'doc': 'DCInterfaceDoc',
+      'id': 'zope.app.browser.services.service.DCInterface',
+      'name': 'DCInterface'}]
+        
+
+    """
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+    def getInterfaces(self):
+        L = [(iface.__name__, iface.__module__+'.'+iface.__name__,
+              getattr(iface, '__doc__', '').split('\n')[0].strip()
+              )
+             for iface in searchInterface(self.context)]
+        L.sort()
+        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.app.content.interfaces import IContentType
+    >>> from zope.i18n import MessageIDFactory
+    >>> from zope.interface.interfaces import IInterface
+    >>> _ = 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
+    ...
+    >>> IInterface.isImplementedBy(TestInterface)
+    True
+    >>> provideInterface('', TestInterface, IContentType)
+    >>> from zope.publisher.browser import TestRequest
+    >>> request = TestRequest()
+    >>> form = {'id': 'zope.app.browser.services.service.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):
+        try:
+            id = self.request["id"]
+        except KeyError:
+            raise zapi.UserError("Please click on an interface name to view"
+                  " details.")
+        
+        iface = getInterface(self.context, id)
+
+        from zope.proxy import getProxiedObject
+        self.iface = getProxiedObject(iface)
+        
+        self.name = self.iface.__name__
+        # XXX the doc string needs some formatting for presentation
+        # XXX self.doc = self.iface.__doc__
+        self.doc = getattr(self.iface, '__doc__', '')
+        self.methods = []
+        self.schema = []
+
+        for name in self.iface:
+            defn = self.iface[name]
+            if IMethod.isImplementedBy(defn):
+                title = defn.__doc__.split('\n')[0].strip()
+                self.methods.append({'method': defn, 'title': title})
+            elif IField.isImplementedBy(defn):
+                self.schema.append(defn)
+
+    def getServices(self):
+        """Return an iterable of service dicts
+
+        where the service dicts contains keys "name" and "registrations."
+        registrations is a list of IRegistrations.
+        """
+        sm = zapi.getServiceManager(self.context)
+        for name, iface in sm.getServiceDefinitions():
+            service = sm.queryService(name)
+            if service is None:
+                continue
+            registry = zapi.queryAdapter(service, IInterfaceBasedRegistry)
+            if registry is None:
+                continue
+            regs = list(registry.getRegistrationsForInterface(self.iface))
+            if regs:
+                yield {"name": name, "registrations": regs}
+            
+
+class MethodDetail:
+    """Interface Method Details
+
+    >>> from zope.interface import Interface
+    >>> from zope.i18n import MessageIDFactory
+    >>> _ = MessageIDFactory('zope')
+    >>> class TestInterface(Interface):
+    ...     '''Test Interface'''
+    ...     def testMethod():
+    ...         'Returns test name'
+    ...
+    >>> class TestClass:
+    ...     def getInterface(self, id=None):
+    ...         return TestInterface
+    ...
+    >>> provideInterface('', TestInterface)
+    >>> from zope.publisher.browser import TestRequest
+    >>> request = TestRequest()
+    >>> form = {
+    ... 'interface_id': 'zope.app.browser.services.service.TestInterface',
+    ... 'method_id': 'testMethod'}
+    >>> request.form = form
+    >>> imethod_details = MethodDetail(TestClass(), request)
+    >>> imethod_details.setup()
+    >>> imethod_details.name
+    'testMethod'
+    >>> imethod_details.doc
+    'Returns test name'
+    >>> imethod_details.iface.__name__
+    'TestInterface'
+    >>> imethod_details.method.__name__
+    'testMethod'
+
+    """
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+    
+    def setup(self):
+        try:
+            interface_id = self.request["interface_id"]
+        except KeyError:
+            raise zapi.UserError("Please click on a method name in the Detail"
+                                 " tab to view method details.")
+        try:
+            method_id = self.request["method_id"]
+        except KeyError:
+            raise zapi.UserError("Please click on a method name to view"
+                  " details.")
+        
+        iface = getInterface(self.context, interface_id)
+
+        from zope.proxy import getProxiedObject
+        self.iface = getProxiedObject(iface)
+
+        self.method = self.iface[method_id]
+        self.name = self.method.__name__
+        self.doc = self.method.__doc__
+


=== Zope3/src/zope/app/browser/services/service/configure.zcml 1.9 => 1.10 ===
--- Zope3/src/zope/app/browser/services/service/configure.zcml:1.9	Wed Mar  3 05:38:37 2004
+++ Zope3/src/zope/app/browser/services/service/configure.zcml	Fri Mar  5 10:49:55 2004
@@ -49,6 +49,7 @@
      template="tasks.pt"
      permission="zope.ManageServices" />
 
+
   <page
      for="zope.app.interfaces.services.service.ISiteManager"
      name="services.html"
@@ -63,6 +64,35 @@
      template="serviceactivation.pt"
      class=".ServiceActivation"
      permission="zope.ManageServices" />
+
+
+  <page
+      for="zope.app.interfaces.services.service.ISiteManager"
+      name="interfacebrowse.html"
+      template="interfacebrowse.pt"
+      class=".Interfaces"
+      permission="zope.ManageServices"
+      menu="zmi_views" title="Interface Browse" 
+      />
+  
+  <page
+      for="zope.app.interfaces.services.service.ISiteManager"
+      name="interfacedetail.html"
+      template="interfacedetail.pt"
+      class=".Detail"
+      permission="zope.ManageServices"
+      />
+
+  <page
+      for="zope.app.interfaces.services.service.ISiteManager"
+      name="interfacemethoddetail.html"
+      template="interfacemethoddetail.pt"
+      class=".MethodDetail"
+      permission="zope.ManageServices"
+      />
+
+
+
 
   <icon
       name="zmi_icon"




More information about the Zope3-Checkins mailing list