[Grok-dev] Re: Cancel button in forms

Martijn Faassen faassen at startifact.com
Mon May 5 13:33:41 EDT 2008


Brandon Craig Rhodes wrote:
> Martijn Faassen <faassen at startifact.com> writes:
> 
>> Brandon Craig Rhodes wrote:
>>
>>> Given that redirection, by definition, is always to a URL, could we
>>> improve self.redirect() so that it always attempts to adapt its
>>> argument to a URL?
>> I think the task of redirection and the task of generating a URL are
>> quite different...
> 
> My point was not about what redirection should do, but about the kind
> of argument that redirect() can accept.  It is my belief that the
> *target* of a redirection *must* always be a URL.  (I could easily be
> wrong about this; but if I am, then please point out why.)  In which
> case, the redirect() method as it stands today is incorrect and
> unsafe, because it does not attempt to adapt its argument to the
> kind-of-thing-it-needs.

unsafe, sure, as you could pass in a non-URL and things would fail. This 
is common in Python APIs. :)

Incorrect, no. We pass URLs around as strings. This is something that is 
extremely common in APIs that expect URLs.

> If we have an interface-marker that says "this thing is a URL" (and we
> do), then redirect(), since it needs a URL, ought simply on principle
> to make sure its arguments gets adapted to AbsoluteURL.  This has
> nothing to do, in my view, with adding "magic"; it simply has to do
> with the fact that, per everything from Design Patterns in 1995 on
> down to PvW's own book about Zope 3, if you're going to live inside of
> an adapter framework, then framework functions need to insist that
> their arguments be adapted to appropriate interfaces before attempting
> to use them.

Since the 'redirect' function has access to the request too, I guess it 
could allow what is put in to be a non-string as well, and try to adapt 
it to IAbsoluteURL.

I don't how this will help you to stop writing 
"self.redirect(self.url(..)" very frequently though. You could do 
self.redirect(obj)' in some cases if self.redirect tried to adapt to 
IAbsoluteURL, but only if you're not redirecting to a view on that 
object or don't want to pass in URL paramters. Code that produces URLs 
might also become a bit harder to recognize; we'll have more than one 
ways to do things.

You need to explain how this will actually help the writer and the 
reader of code that deals with redirects significantly enough to be 
worth having another way of doing things.

Regards,

Martijn



More information about the Grok-dev mailing list