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):
|
||||
title = None
|
||||
items = None
|
||||
is_link = False
|
||||
|
||||
|
||||
class MenuItem(Object):
|
||||
title = None
|
||||
url = None
|
||||
target = None
|
||||
is_link = True
|
||||
is_sep = False
|
||||
|
||||
|
||||
|
@ -62,6 +64,14 @@ def make_simple_menus(request):
|
|||
final_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
|
||||
allowed = []
|
||||
for item in topitem['items']:
|
||||
|
|
|
@ -120,6 +120,10 @@ def before_render(event):
|
|||
if request.rattail_config.getbool('tailbone', 'menus.simple', default=False):
|
||||
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):
|
||||
"""
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
% for topitem in menus:
|
||||
<li>
|
||||
% if topitem.is_link:
|
||||
${h.link_to(topitem.title, topitem.url, target=topitem.target)}
|
||||
% else:
|
||||
<a>${topitem.title}</a>
|
||||
<ul>
|
||||
% for subitem in topitem.items:
|
||||
|
@ -14,20 +17,27 @@
|
|||
% endif
|
||||
% endfor
|
||||
</ul>
|
||||
% endif
|
||||
</li>
|
||||
% endfor
|
||||
|
||||
## User Menu
|
||||
% if request.user:
|
||||
<li>
|
||||
% if messaging_enabled:
|
||||
<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>
|
||||
% if request.is_root:
|
||||
<li class="root-user">${h.link_to("Stop being root", url('stop_root'))}</li>
|
||||
% elif request.is_admin:
|
||||
<li class="root-user">${h.link_to("Become root", url('become_root'))}</li>
|
||||
% endif
|
||||
% if messaging_enabled:
|
||||
<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("Logout", url('logout'))}</li>
|
||||
</ul>
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
<div class="navbar-start">
|
||||
|
||||
% 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">
|
||||
<a class="navbar-link">${topitem.title}</a>
|
||||
<div class="navbar-dropdown">
|
||||
|
@ -39,6 +42,7 @@
|
|||
% endfor
|
||||
</div>
|
||||
</div>
|
||||
% endif
|
||||
% endfor
|
||||
|
||||
</div><!-- navbar-start -->
|
||||
|
@ -47,14 +51,20 @@
|
|||
## User Menu
|
||||
% if request.user:
|
||||
<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>
|
||||
% else:
|
||||
<a class="navbar-link ${'root-user' if request.is_root else ''}">${request.user}</a>
|
||||
% endif
|
||||
<div class="navbar-dropdown">
|
||||
% if request.is_root:
|
||||
${h.link_to("Stop being root", url('stop_root'), class_='navbar-item root-user')}
|
||||
% elif request.is_admin:
|
||||
${h.link_to("Become root", url('become_root'), class_='navbar-item root-user')}
|
||||
% endif
|
||||
% if messaging_enabled:
|
||||
${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("Logout", url('logout'), class_='navbar-item')}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue