[Grok-dev] Traverser, Request and URL mess

Souheil CHELFOUH trollfot at gmail.com
Fri Oct 9 11:56:04 EDT 2009


Hello Grokkers !

I'm currently working on grokui.base and grokui.admin
With Uli, we decided to use a namespace for the views, to get a cleaner base.

Everything is working nicely. The views are registered for a skin
layer, the skin is applied on traversal by a namespace traverser,
++grokui++. However, when an application is created, we'd like to be
able to acces its URL without having the traverser ++grokui++ added in
the request. I couldn't find an easy way to do that without
duplicating the request and modifying the _app_names. I found 2
solutions for that :

# This is totaly ugly, but it works without much effort :)
url = absoluteURL(application, request).replace('/++grokui++', '')


# This is nicer, but maybe there's another solution :
class GrokUINamespace(grok.MultiAdapter):
    grok.name('grokui')
    grok.provides(ITraversable)
    grok.adapts(IRootFolder, browser.IBrowserRequest)

    def __init__(self, context, request):
        self.context = context

        annotations = IAnnotations(request)
        grokui_info = annotations.get('grokui', None)
        if grokui_info is None:
            grokui_info = annotations['grokui'] = {}
        # we get the root url before the ++grokui++ is shifted
        # and use this URL to compute the application one
        grokui_info['root_url'] = request.getApplicationURL()

        applySkin(self.request, GrokUISkin)
        request.shiftNameToApplication()

    def traverse(self, name, ignore):
        return self.context


Anyone could help me, with any kind of trick/tip/opinion ?
The second solution works and is much nicer than the first one, but it
looks a bit hackish.


More information about the Grok-dev mailing list