Utilities Menu and Details Views


This class provides presentation-ready data about a particular utility.


Get the name of the utility.

>>> from zope.app.apidoc.utilitymodule.browser import UtilityDetails
>>> details = UtilityDetails()
>>> details.context = Utility(None, foobar_reg)
>>> details.getName()

Return the string no name, if the utility has no name.

>>> details.context = Utility(None, noname_reg)
>>> details.getName()
'no name'


Return the interface details view for the interface the utility provides.

Let’s start by creating the utility interface and building a utility registration:

>>> from zope.interface import Interface
>>> class IBlah(Interface):
...     pass
>>> blah_reg = type(
...     'RegistrationStub', (),
...     {'name': 'Blah', 'provided': IBlah,
...      'component': None, 'info': ''})()

Then we wrap the registration in the utility documentation class and create the details view:

>>> details = UtilityDetails()
>>> details.context = Utility(None, blah_reg)
>>> details.request = None

Now that we have the details view, we can look up the interface’s detail view and get the id (for example):

>>> iface = details.getInterface()
>>> iface.getId()


Return the Python path and a code browser URL path of the implementation class.

This time around we create the utility class and put it into a utility registration:

>>> class Foo(object):
...     pass
>>> foo_reg = type(
...     'RegistrationStub', (),
...     {'name': '', 'provided': Interface, 'component': Foo(), 'info': ''})()

Then we create a utility documentation class and its details view:

>>> details = UtilityDetails()
>>> details.context = Utility(Interface, foo_reg)

Now we can get the component information:

>>> from pprint import pprint
>>> pprint(details.getComponent(), width=1)
{'path': '__builtin__.Foo', 'url': None}