better navbar, thanks Anthony

This commit is contained in:
mdipierro
2012-08-08 18:56:02 -05:00
parent 990f1b1ea9
commit 3c4336d25c
2 changed files with 18 additions and 11 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-08-08 15:40:40) dev Version 2.00.0 (2012-08-08 18:55:59) dev
+17 -10
View File
@@ -1207,18 +1207,16 @@ class Auth(object):
else: else:
raise HTTP(404) raise HTTP(404)
def navbar(self, prefix='Welcome %(first_name)s', action=None, def navbar(self, prefix='Welcome', action=None,
separators=(' [ ',' | ',' ] '), separators=(' [ ',' | ',' ] '), user_identifier=DEFAULT,
referrer_actions=DEFAULT): referrer_actions=DEFAULT):
referrer_actions = [] if not referrer_actions else referrer_actions referrer_actions = [] if not referrer_actions else referrer_actions
request = current.request request = current.request
T = current.T T = current.T
if isinstance(prefix,str) and self.user: if isinstance(prefix, str):
# backward compatibility prefix = T(prefix)
if not '%' in prefix: prefix+' %(first_name)s' if prefix:
prefix_str = (T(prefix) % self.user).strip() prefix = prefix.strip() + ' '
else:
prefix_str = str(prefix or '')
if not action: if not action:
action=self.url(self.settings.function) action=self.url(self.settings.function)
s1,s2,s3 = separators s1,s2,s3 = separators
@@ -1232,12 +1230,21 @@ class Auth(object):
next if referrer_actions is DEFAULT or function in referrer_actions else '') next if referrer_actions is DEFAULT or function in referrer_actions else '')
if self.user_id: 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' % logout = A(T('Logout'), _href='%s/logout?_next=%s' %
(action, urllib.quote(self.settings.logout_next))) (action, urllib.quote(self.settings.logout_next)))
profile = A(T('Profile'), _href=href('profile')) profile = A(T('Profile'), _href=href('profile'))
password = A(T('Password'), _href=href('change_password')) password = A(T('Password'), _href=href('change_password'))
bar = SPAN(prefix_str, bar = SPAN(prefix, user_identifier, s1, logout, s3, _class='auth_navbar')
s1, logout, s3, _class='auth_navbar')
if not 'profile' in self.settings.actions_disabled: if not 'profile' in self.settings.actions_disabled:
bar.insert(-1, s2) bar.insert(-1, s2)
bar.insert(-1, profile) bar.insert(-1, profile)