Viewlet Managers

Content Provider Manager implementation

class zope.viewlet.manager.ViewletManagerBase(context, request, view)[source]

Bases: object

The Viewlet Manager Base

A generic manager class which can be instantiated.

template = None

A callable that will be used by render, if present, to produce the output. It will be passed the list of viewlets in the viewlets keyword argument.

viewlets = None

A list of active viewlets for the current manager. Populated by update.

get(name, default=None)[source]

Return a viewlet registered for this object having the given name.

This takes into account security.

If no such viewlet can be found, returns default.

filter(viewlets)[source]

Filter viewlets down from all available viewlets to just the currently desired set.

Parameters:viewlets (list) – a list of tuples of the form (name, viewlet).
Returns:A list of the available viewlets in the form (name, viewlet). By default, this method checks with zope.security.checker.canAccess to see if the render method of a viewlet can be used to determine availability.
sort(viewlets)[source]

Sort the viewlets.

viewlets is a list of tuples of the form (name, viewlet).

update()[source]

Update the viewlet manager for rendering.

This method is part of the protocol of a content provider, called before render(). This implementation will use it to:

  1. Find the total set of available viewlets by querying for viewlet adapters.
  2. Filter the total set down to the active set by using filter().
  3. Sort the active set using sort().
  4. Provide viewlets that implement ILocation with a name.
  5. Set viewlets to the found set of active viewlets.
  6. Fire BeforeUpdateEvent for each active viewlet before calling update() on it.

See also

zope.contentprovider.interfaces.IContentProvider

render()[source]

Render the active viewlets.

If a template has been provided, call the template to render. Otherwise, call each viewlet in order to render.

Note

If a template is provided, it will be called even if there are no viewlets.

See also

zope.contentprovider.interfaces.IContentProvider

zope.viewlet.manager.ViewletManager(name, interface, template=None, bases=())[source]

Create and return a new viewlet manager class that implements zope.viewlet.interfaces.IViewletManager.

Parameters:
  • name (str) – The name of the generated class.
  • interface – The additional interface the class will implement.
  • bases (tuple) – The base classes to extend.
class zope.viewlet.manager.WeightOrderedViewletManager(context, request, view)[source]

Bases: zope.viewlet.manager.ViewletManagerBase

Weight ordered viewlet managers.

sort(viewlets)[source]

Sort the viewlets based on their weight attribute (if present; viewlets without a weight are sorted at the beginning but are otherwise unordered).

render()[source]

Just like ViewletManagerBase(), except that if there are no active viewlets in viewlets, we will not attempt to render the template.

class zope.viewlet.manager.ConditionalViewletManager(context, request, view)[source]

Bases: zope.viewlet.manager.WeightOrderedViewletManager

Conditional weight ordered viewlet managers.

filter(viewlets)[source]

Sort out all viewlets which are explicity not available based on the value of their available attribute (viewlets without this attribute are considered available).