Ignore:
Timestamp:
3 Jan 2010, 17:01:16 (15 years ago)
Author:
uli
Message:

Add support for activating a certain primary navigation tab if a page
provides a pnav attribute.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-layout/src/waeup/browser/layout.py

    r4619 r4649  
    1616
    1717grok.templatedir('templates')
    18    
     18
     19# The list of primary navigation tabs.
     20# Each entry is a tuple
     21#
     22#   (<id_number>, <order_number>, <text_to_render>, <link_target>)
     23#
     24# where id number is the number pages can use as their pnav attribute,
     25# order number determines the order in which the primary tabs are
     26# rendered, text_to_render gives the text displayed and link_target
     27# says, what url (relative to application URL) the tab should link to.
     28#
     29PRIMARY_NAV = [
     30    (0, 0, u'Home', ''),
     31    (1, 1, u'Faculties', '/faculties'),
     32    (2, 2, u'Search', '/search'),
     33    ]
     34
    1935class UtilityView(object):
    2036    """A view mixin with useful methods.
    2137
    22     XXX: This class was copied verbatim from megrok.layout trunk. It
    23     can be imported with next release of megrok.layout, so that this
    24     piece can be removed.
     38    The ``pnav`` attribute (a number) tells, to which primary
     39    navigation tab a page declares to belong.
    2540    """
    2641    title = u'' # What appears in the content title...
     42    pnav = 0 # Primary navigation index...
    2743   
    2844    def application_url(self, name=None):
     
    95111    grok.context(IWAeUPObject)
    96112
     113    def getPrimaryNav(self, view):
     114        """Get an ordered list of primary navigation entries.
     115
     116        Each is a dict with keys
     117
     118          'url': <link-target>
     119          'active' : <value for HTML class attribute: 'active' or ''
     120          'title': <text to be rendered in menu tab>
     121          'order': <num indicating order num of this entry>
     122
     123        Pages attatched to this layout can provide an attribute 'pnav'
     124        to indicate, to which tab they belong. This tab will then be
     125        rendered 'active'.
     126        """
     127        result = []
     128        app_url = view.application_url()
     129        for item in PRIMARY_NAV:
     130            active = ''
     131            pnav = getattr(view, 'pnav', 0)
     132            if pnav == item[0]:
     133                active = 'active'
     134            url =  app_url + item[3]
     135            result.append(
     136                dict(title=item[2],
     137                     url=url,
     138                     order=item[1],
     139                     active=active)
     140                )
     141        return sorted(result, key=lambda x: x['order'])
     142   
    97143    def isAuthenticated(self):
    98144        """Return True if the calling user is authenticated.
     
    102148   
    103149    def getUserTitle(self):
     150        """Return principal title of current user.
     151        """
    104152        usertitle = self.request.principal.title
    105153        if usertitle == 'Unauthenticated User':
    106154            return u''
    107155        return usertitle
    108    
     156
    109157    def update(self):
    110158        yui.reset_fonts_grids.need()
Note: See TracChangeset for help on using the changeset viewer.