[Grok-dev] Traverser, Request and URL mess

Souheil CHELFOUH trollfot at gmail.com
Mon Oct 12 05:31:24 EDT 2009


Hello,

2009/10/10 Martijn Faassen <faassen at startifact.com>:
> Hey Souheil,
>
[SNIP !]
>
>> I found 2
>> solutions for that :
>>
>> # This is totaly ugly, but it works without much effort :)
>> url = absoluteURL(application, request).replace('/++grokui++', '')
>
> I think this is safe enough. It's ugly, but it has the virtue of being
> short.
>

Yes, I like short and easy solutions. The con was that I was looking
for a generic solution.


>> # 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
>

This is the declaration of our traverser ++grokui++
In here, I do adapt the request to IAnnotations, so I can annotate it.
Here, I use the "grokui" key to store the root URL of our zope BEFORE
we actually shift the grokui name into the request.
It is more generic and we keep the namespace handling in the namespace
declaration.

[cut cut cut]

> Since we keep runnign into it, perhaps we can come up with a more
> limited solution, where it's at least possible to create URLs *without*
> any ++skin++ bit in it, or to at least add ++skin++foo easily to an
> existing URL (somewhere in the beginning). That won't cover all cases
> (virtual hosts, namespaces not appearing at the root of the URL, other
> things?) but it would cover a lot of them. We also need to make sure we
> can handle your case, where instead of ++skin++foo, you just want ++foo++.
[cut more]

This is what I wanted to acheive. The problem is, the request is the
base of the URL generation and there's no way we can get it to return
the URL with one or more namespace ignore.
The mehod 'getApplicationURL' or 'getURL' are both using the
'_app_names', which contains all the shifted namespaces and there's no
way we can strip it off when computing an URL.
This is very annoying, it doesn't allow flexible URL computation. I
don't really know what would be a proper way to implement what you
propose and what I thought of. If anyone has experience in
manipulating the request for such purposes, please, enlight us ! :)

Thank you Martijn for your time
>
> Regards,
>
> Martijn
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
>


More information about the Grok-dev mailing list