Add support for top-level links for simple menus
also add 'messaging_enabled' to global template context, so can include (or not) that stuff in the user menu
This commit is contained in:
parent
0eb394fb86
commit
c1eaf28812
|
@ -33,12 +33,14 @@ from rattail.util import import_module_path
|
||||||
class MenuGroup(Object):
|
class MenuGroup(Object):
|
||||||
title = None
|
title = None
|
||||||
items = None
|
items = None
|
||||||
|
is_link = False
|
||||||
|
|
||||||
|
|
||||||
class MenuItem(Object):
|
class MenuItem(Object):
|
||||||
title = None
|
title = None
|
||||||
url = None
|
url = None
|
||||||
target = None
|
target = None
|
||||||
|
is_link = True
|
||||||
is_sep = False
|
is_sep = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,6 +64,14 @@ def make_simple_menus(request):
|
||||||
final_menus = []
|
final_menus = []
|
||||||
for topitem in raw_menus:
|
for topitem in raw_menus:
|
||||||
|
|
||||||
|
if topitem.get('type') == 'link':
|
||||||
|
final_menus.append(
|
||||||
|
MenuItem(title=topitem['title'],
|
||||||
|
url=topitem['url'],
|
||||||
|
target=topitem.get('target')))
|
||||||
|
|
||||||
|
else: # assuming 'menu' type
|
||||||
|
|
||||||
# figure out which ones the user has permission to access
|
# figure out which ones the user has permission to access
|
||||||
allowed = []
|
allowed = []
|
||||||
for item in topitem['items']:
|
for item in topitem['items']:
|
||||||
|
|
|
@ -120,6 +120,10 @@ def before_render(event):
|
||||||
if request.rattail_config.getbool('tailbone', 'menus.simple', default=False):
|
if request.rattail_config.getbool('tailbone', 'menus.simple', default=False):
|
||||||
renderer_globals['menus'] = make_simple_menus(request)
|
renderer_globals['menus'] = make_simple_menus(request)
|
||||||
|
|
||||||
|
# TODO: ugh, same deal here
|
||||||
|
renderer_globals['messaging_enabled'] = request.rattail_config.getbool(
|
||||||
|
'tailbone', 'messaging.enabled', default=True)
|
||||||
|
|
||||||
|
|
||||||
def add_inbox_count(event):
|
def add_inbox_count(event):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
% for topitem in menus:
|
% for topitem in menus:
|
||||||
<li>
|
<li>
|
||||||
|
% if topitem.is_link:
|
||||||
|
${h.link_to(topitem.title, topitem.url, target=topitem.target)}
|
||||||
|
% else:
|
||||||
<a>${topitem.title}</a>
|
<a>${topitem.title}</a>
|
||||||
<ul>
|
<ul>
|
||||||
% for subitem in topitem.items:
|
% for subitem in topitem.items:
|
||||||
|
@ -14,20 +17,27 @@
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
</ul>
|
</ul>
|
||||||
|
% endif
|
||||||
</li>
|
</li>
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
## User Menu
|
## User Menu
|
||||||
% if request.user:
|
% if request.user:
|
||||||
<li>
|
<li>
|
||||||
|
% if messaging_enabled:
|
||||||
<a${' class="root-user"' if request.is_root else ''|n}>${request.user}${" ({})".format(inbox_count) if inbox_count else ''}</a>
|
<a${' class="root-user"' if request.is_root else ''|n}>${request.user}${" ({})".format(inbox_count) if inbox_count else ''}</a>
|
||||||
|
% else:
|
||||||
|
<a${' class="root-user"' if request.is_root else ''|n}>${request.user}</a>
|
||||||
|
% endif
|
||||||
<ul>
|
<ul>
|
||||||
% if request.is_root:
|
% if request.is_root:
|
||||||
<li class="root-user">${h.link_to("Stop being root", url('stop_root'))}</li>
|
<li class="root-user">${h.link_to("Stop being root", url('stop_root'))}</li>
|
||||||
% elif request.is_admin:
|
% elif request.is_admin:
|
||||||
<li class="root-user">${h.link_to("Become root", url('become_root'))}</li>
|
<li class="root-user">${h.link_to("Become root", url('become_root'))}</li>
|
||||||
% endif
|
% endif
|
||||||
|
% if messaging_enabled:
|
||||||
<li>${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'))}</li>
|
<li>${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'))}</li>
|
||||||
|
% endif
|
||||||
<li>${h.link_to("Change Password", url('change_password'))}</li>
|
<li>${h.link_to("Change Password", url('change_password'))}</li>
|
||||||
<li>${h.link_to("Logout", url('logout'))}</li>
|
<li>${h.link_to("Logout", url('logout'))}</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
<div class="navbar-start">
|
<div class="navbar-start">
|
||||||
|
|
||||||
% for topitem in menus:
|
% for topitem in menus:
|
||||||
|
% if topitem.is_link:
|
||||||
|
${h.link_to(topitem.title, topitem.url, target=topitem.target, class_='navbar-item')}
|
||||||
|
% else:
|
||||||
<div class="navbar-item has-dropdown is-hoverable">
|
<div class="navbar-item has-dropdown is-hoverable">
|
||||||
<a class="navbar-link">${topitem.title}</a>
|
<a class="navbar-link">${topitem.title}</a>
|
||||||
<div class="navbar-dropdown">
|
<div class="navbar-dropdown">
|
||||||
|
@ -39,6 +42,7 @@
|
||||||
% endfor
|
% endfor
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
</div><!-- navbar-start -->
|
</div><!-- navbar-start -->
|
||||||
|
@ -47,14 +51,20 @@
|
||||||
## User Menu
|
## User Menu
|
||||||
% if request.user:
|
% if request.user:
|
||||||
<div class="navbar-item has-dropdown is-hoverable">
|
<div class="navbar-item has-dropdown is-hoverable">
|
||||||
|
% if messaging_enabled:
|
||||||
<a class="navbar-link ${'root-user' if request.is_root else ''}">${request.user}${" ({})".format(inbox_count) if inbox_count else ''}</a>
|
<a class="navbar-link ${'root-user' if request.is_root else ''}">${request.user}${" ({})".format(inbox_count) if inbox_count else ''}</a>
|
||||||
|
% else:
|
||||||
|
<a class="navbar-link ${'root-user' if request.is_root else ''}">${request.user}</a>
|
||||||
|
% endif
|
||||||
<div class="navbar-dropdown">
|
<div class="navbar-dropdown">
|
||||||
% if request.is_root:
|
% if request.is_root:
|
||||||
${h.link_to("Stop being root", url('stop_root'), class_='navbar-item root-user')}
|
${h.link_to("Stop being root", url('stop_root'), class_='navbar-item root-user')}
|
||||||
% elif request.is_admin:
|
% elif request.is_admin:
|
||||||
${h.link_to("Become root", url('become_root'), class_='navbar-item root-user')}
|
${h.link_to("Become root", url('become_root'), class_='navbar-item root-user')}
|
||||||
% endif
|
% endif
|
||||||
|
% if messaging_enabled:
|
||||||
${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'), class_='navbar-item')}
|
${h.link_to("Messages{}".format(" ({})".format(inbox_count) if inbox_count else ''), url('messages.inbox'), class_='navbar-item')}
|
||||||
|
% endif
|
||||||
${h.link_to("Change Password", url('change_password'), class_='navbar-item')}
|
${h.link_to("Change Password", url('change_password'), class_='navbar-item')}
|
||||||
${h.link_to("Logout", url('logout'), class_='navbar-item')}
|
${h.link_to("Logout", url('logout'), class_='navbar-item')}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue