From da341d29226325536f58fb520e0e9c497bacd55d Mon Sep 17 00:00:00 2001 From: Attila-Mihaly Balazs Date: Tue, 25 Mar 2014 12:41:00 +0200 Subject: [PATCH] Simplify registry logic --- forum/modules/ui_objects.py | 1 + forum/registry.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/forum/modules/ui_objects.py b/forum/modules/ui_objects.py index a51044a..7fae3d4 100644 --- a/forum/modules/ui_objects.py +++ b/forum/modules/ui_objects.py @@ -40,6 +40,7 @@ class Visibility(object): Visibility.PUBLIC = Visibility('public') +Visibility.ANONYMOUS = Visibility('authenticated', negated=True) Visibility.AUTHENTICATED = Visibility('authenticated') Visibility.STAFF = Visibility('staff') Visibility.SUPERUSER = Visibility('superuser') diff --git a/forum/registry.py b/forum/registry.py index 871f1e5..ad75b1a 100644 --- a/forum/registry.py +++ b/forum/registry.py @@ -25,10 +25,15 @@ ui.register(ui.HEADER_LINKS, ui.Link(_('about'), ui.Url('about'), weight=300, name='ABOUT'), ui.Link( - text=lambda u, c: u.is_authenticated() and _('logout') or _('login'), - url=lambda u, c: u.is_authenticated() and reverse('logout') or reverse('auth_signin'), - weight=200, name='LOGIN/OUT'), - + visibility=ui.Visibility.ANONYMOUS, + text=_('login'), + url=lambda u, c: reverse('auth_signin'), + weight=200, name='LOGIN'), + ui.Link( + visibility=ui.Visibility.AUTHENTICATED, + text=_('login'), + url=lambda u, c: reverse('logout'), + weight=200, name='LOGOUT'), ui.Link( visibility=ui.Visibility.AUTHENTICATED, text=lambda u, c: smart_unicode(u.username), -- 2.39.5