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

Philipp von Weitershausen philipp at weitershausen.de
Wed Jun 21 09:20:45 EDT 2006


Rupert Redington wrote:
>> 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:

That already sounds like bad design. Why would the local utility worry
about URLs at all?

> 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?

Don't have your utilities involve URLs...

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

Why would you want to? If you really want to use events, throw an event
that also holds on to the request. I still think that this wouldn't be
necessary in most cases.

Philipp


More information about the Zope3-users mailing list