The difference between getattr and restrictedTraverse
Tim Hicks
tim at sitefusion.co.uk
Fri Jun 1 09:27:06 UTC 2007
Martijn Pieters wrote:
> On 5/31/07, Tim Hicks <tim at sitefusion.co.uk> wrote:
>> I'm trying to proxy a persistent content object with a non-persistent
>> object that intercepts calls to absolute_url. The proxy object looks
>> like this::
>>
>>
>> class Proxy:
>>
>> def __init__(self, context, brain):
>> self.context = context
>> self.obj = obj
>
> Perhaps this is the wrong approach? You can't use views, where it is
> much easier to massage the to-be-displayed data structures?
Hmm, maybe views are a better way to go. I was trying to stick with the
standard zope/plone API (i.e. absolute_url) so that people didn't need
special knowledge when writing/editing templates for this stuff.
> I see that you refer to 'obj' here, while you pass in 'brain', so the
> above code wouldn't work.
Woops, my bad. I copy-pasted from slightly more complicated code to
make the example here clearer.
> But from that I infer that you are using
> CatalogBrains,
Yeah, I've got a version of my proxy class for catalog brains and one
for normal content-ish objects. See
<http://dev.plone.org/collective/browser/Quills/branches/maurits-traversal/traversalfaker.py?rev=42942>.
> in which case you'd perhaps be better off using a
> different mixin object (you can specify an additional mixin in
> catalogs).
Yeah, I thought that was possible, but as there is no useBrains method
on ZCatalog, I figured it was not the done thing. So should I just call
portal_catalog._catalog.useBrains(Proxy), or something along those lines?
Tim
More information about the Product-Developers
mailing list