From 581d3643678ba0fa59ff34032083166aa10e1e2c Mon Sep 17 00:00:00 2001 From: mdipierro Date: Wed, 8 Aug 2012 18:56:02 -0500 Subject: [PATCH] better navbar, thanks Anthony --- VERSION | 2 +- gluon/tools.py | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index d2f4e066..0789b459 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.0 (2012-08-08 15:40:40) dev +Version 2.00.0 (2012-08-08 18:55:59) dev diff --git a/gluon/tools.py b/gluon/tools.py index 534e6e7e..9ace09c5 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -1207,18 +1207,16 @@ class Auth(object): else: raise HTTP(404) - def navbar(self, prefix='Welcome %(first_name)s', action=None, - separators=(' [ ',' | ',' ] '), + def navbar(self, prefix='Welcome', action=None, + separators=(' [ ',' | ',' ] '), user_identifier=DEFAULT, referrer_actions=DEFAULT): referrer_actions = [] if not referrer_actions else referrer_actions request = current.request T = current.T - if isinstance(prefix,str) and self.user: - # backward compatibility - if not '%' in prefix: prefix+' %(first_name)s' - prefix_str = (T(prefix) % self.user).strip() - else: - prefix_str = str(prefix or '') + if isinstance(prefix, str): + prefix = T(prefix) + if prefix: + prefix = prefix.strip() + ' ' if not action: action=self.url(self.settings.function) s1,s2,s3 = separators @@ -1232,12 +1230,21 @@ class Auth(object): next if referrer_actions is DEFAULT or function in referrer_actions else '') if self.user_id: + if user_identifier is DEFAULT: + user_identifier = '%(first_name)s' + if callable(user_identifier): + user_identifier = user_identifier(self.user) + elif ((isinstance(user_identifier, str) or + type(user_identifier).__name__ == 'lazyT') and + re.search(r'%\(.+\)s', user_identifier)): + user_identifier = user_identifier % self.user + if not user_identifier: + user_identifier = '' logout = A(T('Logout'), _href='%s/logout?_next=%s' % (action, urllib.quote(self.settings.logout_next))) profile = A(T('Profile'), _href=href('profile')) password = A(T('Password'), _href=href('change_password')) - bar = SPAN(prefix_str, - s1, logout, s3, _class='auth_navbar') + bar = SPAN(prefix, user_identifier, s1, logout, s3, _class='auth_navbar') if not 'profile' in self.settings.actions_disabled: bar.insert(-1, s2) bar.insert(-1, profile)