[Zope3-Users] Re: Access request object from content_factory

Rupert Redington rupert at neontribe.co.uk
Wed Jun 21 07:07:51 EDT 2006


Philipp von Weitershausen wrote:
> Marco Mariani wrote:
>> Rupert Redington wrote:
>>> from zope.security.management import getInteraction
>>>
>>> request = getInteraction().participations[0]
>>>
>>> Why this works is outlined (IIRC) in zope/app/securitypolicy/zopepolicy.txt.
>>>
>>> There may well be better ways to fish for the request than this... any
>>> offerings?
>>>   
>> In my understanding, if you need to look for the request inside a
>> content object, you're doing something that should be done in another
>> place, be it a view or an adapter.
> 

I understand this... I think...

> Indeed.
> 
>> Of course, I've been wrong before :-]
> 
> Not this time :).
> 
> The hack displayed above (going thru the security interaction) should
> not be considered a standard procedure for getting at the request in
> places where you don't have it. Content objects are dull. They do
> nothing. Other stuff does things *to* them. Mats' solution is the better
> one.
> 

That's me told :-)

The place I found myself doing this was not in a content object, but in
a local utility which needed to return some absolute urls:

siteurl = zapi.absoluteURL(getSite(), getInteraction().participations[0])

I really don't like passing the request from the view to the utility's
method - I often end up calling one utility from another and feel
uncomfortable with forwarding the request through several calls - it
just seems ugly.

I realise that I shouldn't use zapi anymore... apart from that - what
can I do to achieve the effect of lines like the one above without
resorting to a hack?

Furthermore I sometimes find myself using this in event subscribers - I
can't see any way to get request data from an event...

What am I missing this time?

Cheers

Rupert


More information about the Zope3-users mailing list