Skip to content.

plope

Personal tools
You are here: Home » Members » chrism's Home » repoze.bfg.viewgroup ("content provider"-like Thingies for repoze.bfg)
 
 

repoze.bfg.viewgroup ("content provider"-like Thingies for repoze.bfg)

Although I'm not much of a fan of the concept of Zope 3 content providers (aka "viewlets" and "viewlet managers"), I've implemented something a lot like them for repoze.bfg named "repoze.bfg.viewgroup".

repoze.bfg.viewgroup is a package for repoze.bfg which implements something slightly like the concept of "content providers" or "viewlets" (ala Zope3). From the docs :

  repoze.bfg.viewgroup
  ====================

  ``repoze.bfg.viewgroup`` is an extension for :mod:`repoze.bfg` which
  makes it possible to make a ``bfg:viewgroup`` declaration in ZCML
  which acts much like ``bfg:view`` inasmuch as it results in a bfg view
  registration.  Unlike a "normal" ``bfg:view`` registration, however, a
  ``bfg:viewgroup`` registration refers to one or more other bfg views
  (matching them by name, ``for`` interface, and request type).  When a
  ``bfg:viewgroup`` is invoked (either via traversal or via programmatic
  view execution), a viewgroup will return a response which appends all
  the referenced view renderings together in a single body.

  This package is largely by request for folks that enjoy using Zope 3
  "content providers" and "viewlets", although it is slightly less
  featureful, as bfg views themselves typically do not possess an
  interface (they're just callables), so you cannot register a viewgroup
  against a view interface.

The no-interfaces-for-views limitation makes viewgroups slightly less useful than Z3 viewlets, as you'll still need to create different templates (or viewgroups) for different view "types", which isn't necessary with viewlets, as they do a multiadapter lookup using (view, context, request), whereas viewgroups only use (context, request).

For the record, I think both concepts (viewgroups and viewlets) are a bit silly, as using the CA to do the indirection for grouping view renderings together won't be very discoverable to a "maintenance" programmer who might happen to inherit code, the work you save in the view code (which is just as capable of doing the indirections itself) is minimal; doing the renderings within the view itself would likely be more understandable to most folks.

But it's done all the same. Thanks to Ferndando Correa Neto for explaining the common usage of the machinery in Z3 to me. It's still frowned upon to mention the word "viewlet" (or "portlet") in the #repoze IRC channel, sorry. ;-)

Created by chrism
Last modified 2008-09-01 02:10 AM