[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/apidoc/presentation.
Finally fixed a bug that will still find the "factory"
attribute on a view
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon May 9 12:42:23 EDT 2005
Log message for revision 30312:
Finally fixed a bug that will still find the "factory" attribute on a view
function factory, but can also handle ordinary function factories.
Changed:
U Zope3/trunk/src/zope/app/apidoc/presentation.py
U Zope3/trunk/src/zope/app/apidoc/presentation.txt
-=-
Modified: Zope3/trunk/src/zope/app/apidoc/presentation.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/presentation.py 2005-05-09 14:50:48 UTC (rev 30311)
+++ Zope3/trunk/src/zope/app/apidoc/presentation.py 2005-05-09 16:42:23 UTC (rev 30312)
@@ -52,7 +52,8 @@
elif isinstance(factory, (str, unicode, float, int, list, tuple)):
info['referencable'] = False
- elif factory.__module__.startswith('zope.app.publisher.browser.viewmeta'):
+ elif factory.__module__ is not None and \
+ factory.__module__.startswith('zope.app.publisher.browser.viewmeta'):
info['path'] = getPythonPath(factory.__bases__[0])
elif hasattr(factory, '__class__') and \
@@ -67,7 +68,8 @@
info['path'] = getPythonPath(factory)
elif isinstance(factory, FunctionType):
- info['path'] = getPythonPath(factory)
+ info['path'] = getPythonPath(getattr(factory, 'factory', factory))
+
else:
info['path'] = getPythonPath(factory)
Modified: Zope3/trunk/src/zope/app/apidoc/presentation.txt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/presentation.txt 2005-05-09 14:50:48 UTC (rev 30311)
+++ Zope3/trunk/src/zope/app/apidoc/presentation.txt 2005-05-09 16:42:23 UTC (rev 30312)
@@ -79,7 +79,38 @@
'template': None,
'url': '__builtin__/Factory'}
+When factories are created by the directive, they can also be functions. In
+those cases we just simply return the function path:
+ >>> def factory():
+ ... pass
+
+ # The testing framework does not set the __module__ correctly
+ >>> factory.__module__ = '__builtin__'
+
+ >>> info = presentation.getViewFactoryData(factory)
+ >>> pprint(info)
+ {'path': '__builtin__.factory',
+ 'referencable': True,
+ 'resource': None,
+ 'template': None,
+ 'url': '__builtin__/factory'}
+
+However, the function is rather unhelpful, since it will be the same for all
+views that use that code path. For this reason the function keeps track of the
+original factory component in a function attribute called ``factory``:
+
+ >>> factory.factory = Factory
+
+ >>> info = presentation.getViewFactoryData(factory)
+ >>> pprint(info)
+ {'path': '__builtin__.Factory',
+ 'referencable': True,
+ 'resource': None,
+ 'template': None,
+ 'url': '__builtin__/Factory'}
+
+
`getPresentationType(iface)`
----------------------------
More information about the Zope3-Checkins
mailing list