On 5/2/10 12:50 , mnieper wrote:
>
>
> Martin Aspeli wrote:
>>
>>> 3) Define an adapter from the IMyFolder interface to a new interface, say
>>> IHasMyItems, which has a method called "myitems". The MyPortlet then
>>> calls
>>> aq_chain and traverses the acquisition chain by hand until it has found
>>> an
>>> object which can be adaptet to a IHasMyItems.
>>
>> I'd do something similar to this, but the adapter sounds superfluous.
>>
>> In the renderer, I'd do:
>>
>> folder = None
>> for parent in aq_chain(aq_inner(self.context)):
>>      if IMyFolder.providedBy(parent):
>>          folder = parent
>>          break
>>
>> if folder is not None:
>>      ...
>>
>> You already have an interface describing the type of object you're
>> looking for, so I'd just use that.
>>
>> Martin
>>
>
> Thanks for the prompt reply, which has helped me a lot, Martin.
>
> So method 3). I agree that writing an adapter may be superfluous. However,
> assume that I have to process the list of IMyItems of IMyFolder before I
> display them in the MyPortlet. Assume as well that MyPortlet is not the only
> piece of code where the result of this processing is used. In this case, I
> guess that a method that does this processing fits best in an adapter like
> IHasMyItems (as this allows my to extend the content folder IMyFolder with
> functionality without deriving a custom class). Or would you propose to use
> a global function instead?

You could also simply add a method to the content type class itself. 
There is no requirement to use adapters - python has a nice class system 
you can use as well. Writing an adapter when you will never adapt more 
than one specific class is needless overhead imho.

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

Reply via email to