[Zope-CMF] Current action and action aliases

Jean-Marc Orliaguet jmo at ita.chalmers.se
Sun Oct 12 19:11:35 EDT 2003


Florent Guillaume wrote:

>Does the new action aliases code mean that there'll be an easy way to
>discover (from main_template for instance) what the current action is?
>
>Standard use case is to highlight the current action in the actions box.
>I seem to remember that Plone uses a semi-hack to do this. In CPS 2 we
>used to have a "current_action" global variable set at the beginning of
>each template. But I'd like something cleaner than that and the aliases
>code seems the perfect place to do it.
>
>Thanks,
>
>Florent
>
>  
>

I use the following code to determine whether the current URL 
corresponds to one of the listed actions:

the 'url' parameter is the action's  absolute url

=======================
    security.declarePublic('weAreHere')
    def weAreHere(self, url=None):
        """ returns true if the url corresponds to the current URL
            useful for portal actions.
        """

        if url.endswith('/'):
           url = url[:len(url)-1]
        url = string.lstrip(url)

        request_url = self.REQUEST.get('URL')
        if request_url.endswith('/index_html'):
           request_url = request_url[:-11]

        query_string = self.REQUEST.get('QUERY_STRING', None)
        if query_string:
           request_url = request_url + '?' + query_string

        if url == request_url:
           return 1

=======================

there is a simple demo at the address:
http://bell.ita.chalmers.se/cmf

JM

-- 
Jean-Marc Orliaguet - ITA
- http://www.ita.chalmers.se/~jmo
- Tel: +46 (0)31 772 8581





More information about the Zope-CMF mailing list