[Zope-CMF] Access rule for setting skin

Jean-Francois.Doyon at CCRS.NRCan.gc.ca Jean-Francois.Doyon at CCRS.NRCan.gc.ca
Fri Apr 1 17:43:04 EST 2005


Hello,

I'm trying to setup a way to change skin and language settings on the fly,
based on URL traversal.

I've got it all setup as a python script and access rule, but it ain't
working quite right.

Notably, the default view for the object doesn't "kick in", I have to do it
explicitely.

And I get some page telling me that there is no admin user setup and so on,
which isn't true.

So for instance I have a CMF root at /site/atlas ... This works fine.  The
view is "root_view" (A FS based PT in the skins).

If I do /site/atlas/en or /site/atlas/fr, I get something entirely
unexpected.

If I do /site/atlas/en/root_view or /site/atlas/fr/root_view, then I'm back
in business.

I'm guessing this has something to do with when the access rule actually
gets called and so on (too early? Too late?).

But if not an access rule, where else could I safely put this code?:

request = context.REQUEST

stack = request['TraversalRequestNameStack']

if stack and stack[-1] in ['en','fr']:
    lang = stack.pop()
    virtual_url_parts = request.get('VIRTUAL_URL_PARTS', None)
    # Rewrite the path so all links will have the language path entry
    if virtual_url_parts and len(virtual_url_parts) > 2:
        base_parts = virtual_url_parts[1]
        base_parts = base_parts.split('/')
        request.setVirtualRoot(base_parts + request.steps + [lang])
    else:                
        request.setVirtualRoot(request.steps + [lang])
    context.changeSkin('atlas-' + lang)
    request.set('HTTP_ACCEPT_LANGUAGE', lang)


Thanks,
J.F.


More information about the Zope-CMF mailing list