Package: collective.viewportletmanager
IntroductionThis package extends the default Plone portlets framework to allow for the assignment
of portlets on a per-view basis.OverviewSometimes it may really be useful to have a different portlet assigned to
standalone views which are not necessary coupled to any content objects.
You may think that in this case it is possible to create a new content object
and apply that view to it and then finally assign the required portlets to
that object. However, inPloneyou may end up creating new content objects
for every standalone zope3 view - which is not correct from a content management
point of view.In one of our projects we had a lot of standalone views where it was a requirement
to have different portlets assigned to a standalone view (e.g. having a separate set of
portlets on user profile views, sitemap view,z3c.formform views, homepage view, etc.)To facilitate the adding of portlets there we developed this package calledcollective.viewportletmanager. It is aimed at usage byPloneintegrators
and is not working out of the box. To be able to assign portlets to your zope3
view you have to follow some simple rules.More on this below inHow to usesection.CompatibilityThis add-on was tested onPlone 3.3.5andPlone 4.1Installationto add the package to yourZopeinstance, please, follow the instructions
found inside thedocs/INSTALL.txtfilethen restart yourZopeinstanceand install theView Portlet Manager package from within the ``portal_quickinstallertoolHow to useThis packages allows you to assignPlone 3portlets to your custom zope3
views. To be able to do this we require from you the only one extra step:
mark your view withIPortletsAwareViewinterface:from zope.interface import implements
from Products.Five.browser import BrowserView
from collective.viewportletmanager.interfaces import IPortletsAwareView

class MyZope3View(BrowserView):
    implements(IPortletsAwareView)

    # your zope3 view code goes hereAfter you declare that your zope3 view implementsIPortletsAwareViewinterface, restart your zope instance and render your view. From now on you’ll
see thereManage view portletslink. This link will get you to portlets
management screen which is exactly the same as defaultManage portletsview.
The only difference is thatManage view portletsview will allow you to
manage portlets for yourIPortletsAwareViewmarked view.The portlets you add on that view will be available only while visiting your
custom zope3 view.One more important note here is that portlets are not assigned based on view alone,
but are based on context object as well. So we may say that view-based portlets
are actually view-context based portlets.View portlets will go right after context based portlets like other site-wide
portlets.You’ll also be able to block view based portlets via the standardManage portletsscreen.Design NotesThe main thing is that view portlets are saved intoPlonesite root
annotations like any other site-wide portlet categories but at the same time
view category mappings hold context object UIDs so actually view category
doesn’t look like site-wide but context based portlets category.View portlets category uses the next assignments key format:"<object_uid>:<view_name>"So, for object with uid equal “123” and it’s view called “my-view” we’ll get
portlet assignments saved under “123:my-view” key in “view” category inside
global site portlet manager annotations.For site root, which doesn’t provide “UID” attribute we use string placeholder
“nouid”. E.g. portlet assignments for “sitemap” view will be saved under
“nouid:sitemap” key.This package overrides a bunch of standardPloneportlets framework
components in order to add view portlets category to list of standard
portlet categories: context, user, group and content type.Here we’ll try to describe what exactly was overridden:PortletContextboth for site root and site content in order to add view
category to standard categories list. This context also takes care of
generating view key based on object “UID” and view name. To get view name
portlet context retrieves view as an argument to it’sglobalPortletCategoriesmethod, which actually breaks defaultPloneportlets framework designed API. To pass view object around we also had to
override portlet manager renderer and portlet retrievers.PortletManagerRenderer: to pass view object down to portlet retriever class.PortletRetriever: to pass view object down toPortletContextwhich in
turn will use it to generate view category key.ContextualEditPortletManagerRendererview to provide view category blacklist
status to be used on standardManage portletsscreen.EditPortletManagerRendererto disable inherited portlets onManage view portletsscreen. This doesn’t make much sense for view category portlets.ManageContextualPortletsto provide set blacklist status method which will
also take care of view category blacklist status.ManageViewPortlets: our ownManage view portletsviewManageViewPortletsLinkViewlet: our own viewlet that rendersManage view portletslink pointing to appropriate portlets management screen for current
content object and zope3 view. Link appears only onIPortletsAwareViewenabled zope3 views.Live Exampleshttp://www.choosehelp.com/http://www.choosehelp.com/profile/John/CreditsCompaniesMartin Schoel Web ProductionsContact usAuthorsVitaliy Podoba <vitaliy@martinschoel.com>ContributorsChangelog1.0 (August 23, 2011)Initial release
[piv]