Hi,

I am having problems with a portlet that is contextually assigned. The 
basic idea is to show news but only within the container subtree where 
it is assigned. Therefore, I need the path to the object where the 
assignment is stored.

My first try was to get the object/path from the __portlet_metadata__ 
attribute of the renderer. That works fine at the time of getting the 
contents that will be shown in the portlet. However, I also need that 
information in the "available" property of the renderer, or even just in 
its __init__ method, and at that time, the __portlet_metadata__ is just 
not there. So that is a dead end.

My second try is to add that path as a property in the schema of the 
assignment. Thus, there is a field in it's add/edit form, but I also 
want to make the field not required, so that on the assignment of a 
portlet instance I can provide the path where it is created as a 
default. And that is what I am doing, in the create method of the 
AddForm. It looks really ugly, though, and I am not sure whether this is 
sane/robust. Say I am assigning the portlet in /Plone/a/b; if I insert a 
pdb in the create method of the add form, this is what I get:


ipdb> type(self)
<class 'Products.Five.metaclass.EventsAddForm'>
ipdb> type(self.context)
<type 'Acquisition.ImplicitAcquisitionWrapper'>
ipdb> from Acquisition import aq_base
ipdb> type(aq_base(self.context))
<class 'Products.Five.metaclass.+'>           # ouch, a '+' type?!
ipdb> type(aq_base(self.context.context))
<class 'plone.app.portlets.storage.PortletAssignmentMapping'>
ipdb> self.context.context
<PortletAssignmentMapping at 
/Plone/a/b/++contextportlets++plone.leftcolumn used for 
/Plone/a/b/++contextportlets++plone.leftcolumn/+>

So, now, I am getting the path to the context like this (self is the 
AddForm):

root_path = '/'.join(self.context.context.getPhysicalPath()[:-1])

What would be the sensible way? Where can I find an example?

Thanks, and best regards


-- 
Enrique Pérez Arnaud <[email protected]>
Yaco Sistemas SL| http://www.yaco.es
C/ Rioja 5, 41001 Sevilla (España)
Tel: (+34) 954 50 00 57
Fax 954 50 09 29

_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers

Reply via email to