[Product-Developers] Re: portlet rendering in python code

Martin Aspeli optilude at gmx.net
Sat May 3 10:27:12 UTC 2008

Daniel Widerin wrote:
> Martin Aspeli schrieb:
>> Daniel Widerin wrote:
>>> Hello,
>>> I need some portlets to be rendered (i need their rendered html code) 
>>> in browser view. these portlets expect only one parameter, an 
>>> object_uid, which i passed to portlet renderer successfully.
>> Why? :)
>> It sounds to me like you should just do this with views or 
>> ViewPageTemplateFiles or viewlets.
> i want to select portlets in kupu using mediaobjects to make "content 
> portlets" being rendered in kupu-text.
> i added some of my custom types (which all have a portlet too) to 
> mediaobject resource types in kupu configuration to make them selectable 
> using the place-image-button.
> i added these types into the action-url table in kupu configuration
> preview: 
> string:++resource++gesundesleben.theme.images/contentPluginPreview_${portal_type}.gif?ContentPluginUrl=${object_url}
> normal image:
> string:++resource++gesundesleben.theme.images/contentPlugin_${portal_type}.gif?ContentPluginUrl=${object_url}
> now i can add my types using placeholder images into my kupu text, and 
> give them image-left, image-right classes to make text float around.
> on save i replace ${object_url} with physicalpath of the selected 
> object. (sorry, but only portal_type and object_url are available in 
> kupu resource types configuration).
> in my browser view, i parse the kupu-text and replace all images with 
> img-tags which use the 
> contentPlugin_${portal_type}.gif?ContentPluginUrl=${object_url} scheme 
> with the rendered portlet code. through the physicalpath i can locate 
> the object and then get the rendered portlet using an adapter with my 
> own factory.
> i hope you understand what i'm trying to do here, i know it's not a nice 
> way but using the kupu place-image-button makes it very simple for 
> reviewers to add such content portlets

Interestingly, this is a lot like something we've talked about doing in 
Plone proper. See 

The way I thought about implementing that would be to have a special 
contextual portlet manager, much like collective.portletpage does. We'd 
extend it so that it had a way to render one particular portlet, rather 
than just looping through all its portlets and rendering them one by one.

In kupu, you'd actually get an <img /> tag with particular attributes 
(e.g. rel="widget" if that's allowed, or something similar, and 
id="some-portlet-id"). Upon rendering of the page, a new transform would 
replace such img tags with their respective portlets, by asking the 
portlet manager to render them.

>>> i tried to call the portlet directly and construct the parameters for 
>>> the render method, but still failed.
>> You need to be more specific about what you tried.
>> The general approach should be to get the portlet assignment, make sure 
>> it's acquisition-wrapped, and then adapt to IPortletRenderer, making 
>> sure the portlet renderer is acquisition wrapped in the context, and 
>> then call update() and then render() on it.
>> You'll need to look at the portlet manager code, in particular 
>> _lazyLoadPortlets().
>>> i get a Unauthorized Exception in DC.Bindings as described here: 
>>> http://plone.org/documentation/error/unauthorized-not-authorized-to-access-binding-context 
> i still get the unauthorized exception - but it works if i do a
> except Unauthorized:
>      pass
> instead of raising the UnauthorizedBindingException. I think i have to 
> search the right context for doing such things...

Mmm that doesn't sound right. :)

I think you need to use the portlet manager setup code and just extend 
it (you can register a custom portlet manager) to be able to render just 
one portlet by id.

Look at collective.portletpage for some more inspiration.


Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

More information about the Product-Developers mailing list