[Grok-dev] Re: Cancel button in forms

Brandon Craig Rhodes brandon at rhodesmill.org
Mon May 5 10:02:53 EDT 2008

Jan-Wijbrand Kolman <janwijbrand at gmail.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?
> What does "adapt its arguments to a URL" mean? You should be able to
> redirect to *any* URL, not just ones that are "creatable" through
> view.url().

Well, strings that represent absolute URLs in the Zope framework
should already come marked with the IAbsoluteURL interface, right? :-)
It's obviously the right way to do things in a component framework,
after all.  And Grok views and models already know how to adapt
themselves to IAbsoluteURL by returning a URL.  So the first lines of
View.redirect() should look something like:

    def redirect(self, destination):
        destination = IAbsoluteURL(destination)

If we wanted to support legacy code that might pass un-adorned strings
to the redirect() method, bypassing the elegance of an adapter
framework, then we could instead write:

    def redirect(self, destination):
        destination = IAbsoluteURL(destination, destination)

so that if adaptation fails then at least you get the raw argument
back.  Anyway, that would let you pass instances of models and views
directly to redirect() without having to repeat self.url() over and
over and over again.

Brandon Craig Rhodes   brandon at rhodesmill.org   http://rhodesmill.org/brandon

More information about the Grok-dev mailing list