Back to index

plone3  3.1.7
Functions | Variables
plone.app.portlets.metaconfigure Namespace Reference

Functions

def portletDirective
def portletRendererDirective

Variables

dictionary _default_renderers = {}

Function Documentation

def plone.app.portlets.metaconfigure.portletDirective (   _context,
  name,
  interface,
  assignment,
  renderer,
  addview,
  view_permission = u"zope2.View",
  edit_permission = "plone.app.portlets.ManageOwnPortlets",
  editview = None 
)
Register a portlet assignment type using typical options. 

Portlets that consist of a simple assignment class deriving form 
base.Assignment, a renderer deriving from base.Renderer, an addview
using formlib and deriving from base.AddForm and an editview (optional)
using formlib and deriving from base.EditForm, can use this directive
to avoid having to regiter each of those components individually.

In addition, we register the portlet interface using IPortletTypeInterface
and an IFactory utility, in order to help the GenericSetup handler and
other generic code instantiate portlets.

Definition at line 27 of file metaconfigure.py.

00027 
00028         view_permission=u"zope2.View", edit_permission="plone.app.portlets.ManageOwnPortlets", editview=None):
00029     """Register a portlet assignment type using typical options. 
00030     
00031     Portlets that consist of a simple assignment class deriving form 
00032     base.Assignment, a renderer deriving from base.Renderer, an addview
00033     using formlib and deriving from base.AddForm and an editview (optional)
00034     using formlib and deriving from base.EditForm, can use this directive
00035     to avoid having to regiter each of those components individually.
00036     
00037     In addition, we register the portlet interface using IPortletTypeInterface
00038     and an IFactory utility, in order to help the GenericSetup handler and
00039     other generic code instantiate portlets.
00040     """
00041 
00042     # Register the portlet interface as named utility so that we can find it
00043     # again (in the GS handler)
00044     
00045     alsoProvides(interface, IPortletTypeInterface)
00046     utility(_context, 
00047             provides=IPortletTypeInterface,
00048             name=name,
00049             component=interface)
00050             
00051     # Register a factory
00052     
00053     utility(_context,
00054             provides=IFactory,
00055             name=name,
00056             component=Factory(assignment))
00057 
00058     # Set permissions on the assignment class
00059     
00060     # <class class="[assignment]">
00061     #   <require 
00062     #       permission="[view_permission]"
00063     #       interface="[interface]"
00064     #       />
00065     # </class>
00066     
00067     # XXX: Is this necessary? The renderer doesn't need it, so it may
00068     # just be superfluous.
00069     
00070     # Register the renderer:
00071     
00072     # <adapter 
00073     #   factory="[renderer]"
00074     #   for="zope.interface.Interface
00075     #        zope.publisher.interfaces.browser.IDefaultBrowserLayer
00076     #        zope.publisher.interfaces.browser.IBrowserView
00077     #        plone.portlets.interfaces.IPortletManager
00078     #        [interface]
00079     #   provides="plone.portlets.interfaces.IPortletRenderer"
00080     #   />
00081     
00082     adapter(_context, (renderer,), provides=IPortletRenderer,
00083             for_=(Interface, IDefaultBrowserLayer, IBrowserView, IPortletManager, interface,))
00084     _default_renderers[interface] = renderer
00085     
00086     # Register the adding view
00087     
00088     # <browser:page 
00089     #   for="plone.app.portlets.browser.interfaces.IPortletAdding"
00090     #   name="[name]"
00091     #   class="[addview]"
00092     #   permission="[edit_permission]"
00093     #   />
00094     
00095     page(_context, 
00096          for_=IPortletAdding,
00097          name=name,
00098          class_=addview,
00099          permission=edit_permission)
00100     
00101     # Register the edit view, if applicable
00102     
00103     # <browser:page 
00104     #   for="[interface]"
00105     #   name="edit"
00106     #   class="[editview]"
00107     #   permission="[edit_permission]"
00108     #   />
00109     
00110     if editview is not None:
00111         page(_context, 
00112              for_=interface,
00113              name=u"edit",
00114              class_=editview,
00115              permission=edit_permission)
             

Here is the call graph for this function:

def plone.app.portlets.metaconfigure.portletRendererDirective (   _context,
  portlet,
  class_ = None,
  template = None,
  for_ = Interface,
  layer = IDefaultBrowserLayer,
  view = IBrowserView,
  manager = IPortletManager 
)
Register a custom/override portlet renderer

Definition at line 117 of file metaconfigure.py.

00117 
00118         for_=Interface, layer=IDefaultBrowserLayer, view=IBrowserView, manager=IPortletManager):
00119     """Register a custom/override portlet renderer
00120     """
00121     
00122     if class_ is None and template is None:
00123         raise TypeError("Either 'template' or 'class' must be given")
00124     if class_ is not None and template is not None:
00125         raise TypeError("'template' and 'class' cannot be specified at the same time")
00126     
00127     if template is not None:
00128         
00129         # Look up the default renderer for this portlet
00130         base_class = _default_renderers.get(portlet, None)
00131         if base_class is None:
00132             raise TypeError("Can't find default renderer for %s. "
00133                             "Perhaps the portlet has not been registered yet?" % portlet.__identifier__)
00134 
00135         # Generate a subclass with 'renderer' using this template
00136         class_ = makeClass("PortletRenderer from %s" % template, 
00137                             (base_class,), {'render' : ViewPageTemplateFile(template)})
00138     
00139     adapter(_context, (class_,), provides=IPortletRenderer,
00140                 for_=(for_, layer, view, manager, portlet,))

Here is the caller graph for this function:


Variable Documentation

Definition at line 24 of file metaconfigure.py.