[Grok-dev] view.url

Martijn Faassen faassen at infrae.com
Tue Oct 31 09:21:37 EST 2006


Hi there,

Even though I haven't received feedback yet, I have implemented 
view.url() as described at the bottom of my mail yesterday. I'll repeat 
it here, slightly updated:

class IGrokView(Interface):

    # XXX haven't implemented this at the time of writing.
    def redirect(url):
        """Redirect to given URL"""

    def url(obj=None, name=''):
        """Construct URL.

        If no arguments given, construct URL to view itself.

        If only obj argument is given, construct URL to obj.

        If only name is given (or string as first argument, a bit of
        magic there), construct view URL to view with that name on our
        context.

        If both object and name arguments are supplied, construct
        view URL to view on that object.
        """

Usages:

   >>> view.SomeView()
   >>> view.url()
   http://localhost/foo/bar/edit
   >>> view.url('display')
   http://localhost/foo/bar/display
   >>> view.url(view.context)
   http://localhost/foo/bar
   >>> view.url(view.context, 'display')
   http://localhost/foo/bar/display
   >>> parent = view.context.__parent__
   >>> view.url(parent)
   http://localhost/foo
   >>> view.url(parent, 'display')
   http://localhost/foo/display

I'm now going to modify grokwiki to use this API and see what I run into.

Regards,

Martijn


More information about the Grok-dev mailing list