[Grok-dev] grok.url() requiring a request object a bit inconvenient
sylvain at infrae.com
sylvain at infrae.com
Fri Oct 30 10:18:15 EDT 2009
> Hi Sebastian,
>
> On Fri, Oct 30, 2009 at 14:04, Sebastian Ware <sebastian at urbantalk.se>
> wrote:
>> I find it a bit inconvenient that you have to supply a request object
>> with the grok.url() method. If I want to create an url during an event
>> to for example send an email, it would be great if I could call...
>>
>> grok.url(obj)
>>
>> ...without having to supply a request object.
>
> The problem is that, with Virtual Hosting, it's not actually possible
> to know the URL of an object unless you hardcode the information of
> where the "root" of the website is in relation to the "root" of your
> application. In Unix-y terms, it's not possible to know beforehand
> which "folder" or "object" of your application is "mounted" in which
> "folder" of the URL space. A single apache installation could point to
> your Grok application from multiple hostnames, foldernames and even
> ports.
>
> Only the request object has the proper information of how a browser
> request is coming to your application to be able to calculate the
> proper url of an object.
>
> [...]
>
> Neither of these seem to be palatable to the current direction of
> development of the Zope community, but I mention them here for
> completeness, and so that we don't forget our past :-)
>
You can already get back the request via getInteraction(). As far as I
know.
You don't need evil hacks like you describe (even it's what may do
getInteraction()).
So you can make it work easily. (However you need something different on
Zope 2 for five.grok, so the code to get the request needs to be easily
changeable).
And at some point I need the url function as well, and didn't have, and
the code in grok.View is quite long before calling an utility function,
and I was sad. +1 to have a such method (if it's possible).
Best regards,
Sylvain,
More information about the Grok-dev
mailing list