[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/apidoc/ Show the field *class* instead of the *interface* of a property in an

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Jul 18 17:56:37 EDT 2004


Log message for revision 26614:
  Show the field *class* instead of the *interface* of a property in an
  interface. This is more instructive and appropriate, especially since
  all fields get their docs from the interface.
  


Changed:
  U   Zope3/trunk/src/zope/app/apidoc/ifacemodule/browser.py
  U   Zope3/trunk/src/zope/app/apidoc/ifacemodule/index.pt
  U   Zope3/trunk/src/zope/app/apidoc/zcmlmodule/index.pt


-=-
Modified: Zope3/trunk/src/zope/app/apidoc/ifacemodule/browser.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/ifacemodule/browser.py	2004-07-18 21:50:40 UTC (rev 26613)
+++ Zope3/trunk/src/zope/app/apidoc/ifacemodule/browser.py	2004-07-18 21:56:36 UTC (rev 26614)
@@ -140,6 +140,45 @@
     return {'name': ifaces[0].getName(), 'id': getPythonPath(ifaces[0])}
 
 
+def _getFieldClass(field):
+    """Return PT-friendly dict about the field's class.
+
+    Examples::
+
+      >>> from zope.app.apidoc.tests import pprint
+      >>> from zope.interface import implements, Interface
+      
+      >>> class IField(Interface):
+      ...     pass
+      >>> class ISpecialField(IField):
+      ...     pass
+      >>> class Field(object):
+      ...     implements(IField)
+      >>> class SpecialField(object):
+      ...     implements(ISpecialField)
+      >>> class ExtraField(SpecialField):
+      ...     pass
+
+      >>> info = _getFieldClass(Field())
+      >>> pprint(info)
+      [('name', 'Field'),
+       ('path', 'zope/app/apidoc/ifacemodule/browser/Field')]
+
+      >>> info = _getFieldClass(SpecialField())
+      >>> pprint(info)
+      [('name', 'SpecialField'),
+       ('path', 'zope/app/apidoc/ifacemodule/browser/SpecialField')]
+
+      >>> info = _getFieldClass(ExtraField())
+      >>> pprint(info)
+      [('name', 'ExtraField'),
+       ('path', 'zope/app/apidoc/ifacemodule/browser/ExtraField')]
+    """
+    class_ = removeAllProxies(field).__class__
+    return {'name': class_.__name__,
+            'path': getPythonPath(class_).replace('.', '/')}
+
+
 def _getRequired(field):
     """Return a string representation of whether the field is required.
 
@@ -199,7 +238,10 @@
           >>> details.getDoc()[:34]
           '<h1>This is the Foo interface</h1>'
         """
-        return renderText(self.context.__doc__, self.context.__module__)
+        # We must remove all proxies here, so that we get the context's
+        # __module__ attribute and not the proxy's. 
+        return renderText(self.context.__doc__,
+                          removeAllProxies(self.context).__module__)
 
     def getBases(self):
         """Get all bases of this class
@@ -293,11 +335,11 @@
         return [{'name': method.getName(),
                  'signature': method.getSignatureString(),
                  'doc': renderText(method.getDoc() or '',
-                                   self.context.__module__)}
+                                   removeAllProxies(self.context).__module__)}
                 for method in _get(self.context, IMethod).values()]
             
     def getFields(self):
-        """Return a list of fields in the order they were specified.
+        r"""Return a list of fields in the order they were specified.
 
         Example::
 
@@ -307,15 +349,21 @@
 
           >>> fields = details.getFields()
           >>> pprint(fields)
-          [[('default', "u'Foo'"),
-            ('description', u'Title'),
+          [[('class',
+             [('name', 'TextLine'),
+              ('path', 'zope/schema/_bootstrapfields/TextLine')]),
+            ('default', "u'Foo'"),
+            ('description', '<p>Title</p>\n'),
             ('iface',
              [('id', 'zope.schema.interfaces.ITextLine'),
               ('name', 'ITextLine')]),
             ('name', 'title'),
             ('required', u'required')],
-           [('default', "u'Foo.'"),
-            ('description', u'Desc'),
+           [('class',
+             [('name', 'Text'),
+              ('path', 'zope/schema/_bootstrapfields/Text')]),
+            ('default', "u'Foo.'"),
+            ('description', '<p>Desc</p>\n'),
             ('iface',
              [('id', 'zope.schema.interfaces.IText'), ('name', 'IText')]),
             ('name', 'description'),
@@ -324,10 +372,12 @@
         fields = map(lambda x: x[1], _getInOrder(self.context, IField))
         return [{'name': field.getName(),
                  'iface': _getFieldInterface(field),
+                 'class': _getFieldClass(field),
                  'required': _getRequired(field),
                  'default': repr(field.default),
-                 'description': field.description
-                 }
+                 'description': renderText(
+                     field.description or '',
+                     removeAllProxies(self.context).__module__)}
                 for field in fields]
 
     def getRequiredAdapters(self):
@@ -361,7 +411,8 @@
         adapters = []
         for reg in service.registrations():
             # Only grab the adapters for which this interface is required
-            if reg.required and reg.required[0] is not None and iface not in reg.required:
+            if reg.required and reg.required[0] is not None and \
+                   iface not in reg.required:
                 continue
             factory = _getRealFactory(reg.value)
             path = getPythonPath(factory)

Modified: Zope3/trunk/src/zope/app/apidoc/ifacemodule/index.pt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/ifacemodule/index.pt	2004-07-18 21:50:40 UTC (rev 26613)
+++ Zope3/trunk/src/zope/app/apidoc/ifacemodule/index.pt	2004-07-18 21:56:36 UTC (rev 26614)
@@ -63,12 +63,13 @@
     <li tal:repeat="field fields">
       <b><code tal:content="field/name">field</code></b>
       - <a href=""
-           tal:attributes="href string:../${field/iface/id}/apiindex.html">
-          <code tal:content="field/iface/name">IField</code></a>
+           tal:attributes="
+             href string:../../Class/${field/class/path}/index.html">
+          <code tal:content="field/class/name">Field</code></a>
       (<span tal:content="string:${field/required}, ">optional, </span>
         <span i18n:translate="">default</span> =
         <code tal:content="field/default" />)<br>
-      <span tal:content="field/description">field desc</span>      
+      <span tal:content="structure field/description">field desc</span>      
     </li>
 
   </ul>

Modified: Zope3/trunk/src/zope/app/apidoc/zcmlmodule/index.pt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/zcmlmodule/index.pt	2004-07-18 21:50:40 UTC (rev 26613)
+++ Zope3/trunk/src/zope/app/apidoc/zcmlmodule/index.pt	2004-07-18 21:56:36 UTC (rev 26614)
@@ -62,12 +62,12 @@
       <b><code tal:content="field/name">field</code></b>
       - <a href=""
            tal:attributes="href 
-               string:../../../Interface/${field/iface/id}/apiindex.html">
-          <code tal:content="field/iface/name">IField</code></a>
+               string:../../../Class/${field/class/path}/index.html">
+          <code tal:content="field/class/name">Field</code></a>
       (<span tal:content="string:${field/required}, ">optional, </span>
         <span i18n:translate="">default</span> =
             <code tal:content="field/default" />)<br>
-      <span tal:content="field/description">field desc</span>      
+      <span tal:content="structure field/description">field desc</span>      
     </li>
 
   </ul>



More information about the Zope3-Checkins mailing list