[Grok-dev] grok and urls

Martijn Faassen faassen at infrae.com
Mon Oct 30 09:13:46 EST 2006


Hi there,

Grok is but a simple caveman. Grok just needs a simple way to generate 
URLs to things without too much thinking. We're not there yet with grok.

The current Zope 3 way to generate a URL is something like:

zapi.absoluteURL(object, request)

which is in fact zope.traversing.browser.absoluteurl's absoluteURL which 
then really does a component.getMultiAdapter((ob, request), IAbsoluteURL)()

Meanwhile, grok also needs to generate various kinds of URLs. the 
grokwiki has a number of places where URLs are involved:

* the redirect in wiki.py does self.request.response.redirect('home')
   That's a relative URL that just happens to work. Relative URLs
   unfortunately don't always happen to work.

* in page.Index there's a before method which does:

   zapi.absoluteURL(self.context.__parent__, self.request)

   to get the URL to the wiki itself.

* in page.Edit there's another interesting
   combination:

   wiki_url = zapi.absoluteURL(self.wiki, self.request)
   self.request.response.redirect("%s/%s" % (wiki_url, 
self.context.__name__))

   This one is particularly horrible as it takes place in a 'before()'
   method. We have a special class of URL redirects which happen
   after form submits and we're sort of misusing before() here to make
   that happen.

* then in page_templates/edit.pt, there's a form submit to request/URL
   We get the URL from the request here.

* and in page_templates/index.pt there's a tal:attributes="href 
string:${context/@@absolute_url}/edit

   We use the absolute_url view that gets registered for lots of things,
   looking it up by name. Then we tack /edit after it.

* and then in layout.pt

   tal:define="wiki context/__parent__;
               wiki_url wiki/@@absolute_url"

   and later

    <a tal:attributes="href string:$wiki_url/$page"
                      tal:content="page"
                      />

   And here we tack do some more construction, this time constructing
   the name from two other names.

There appear to be about as many ways to generate URLs in this little 
application as we *have* urls. ME GROK THINK NO GOOD.

In my next mail, I'll try to think through some options we got here to 
make this a uniform, easily understood situation.

Regards,

Martijn



More information about the Grok-dev mailing list