Group dynamically generated menu items
Also allow for grouping other views by setting the 'sidebar_grouping'
param to a value another than 'main'.
Patch by: Sverre Rabbelier
--- a/app/soc/templates/soc/sidebar/menuitem.html Wed Jan 28 02:25:51 2009 +0000
+++ b/app/soc/templates/soc/sidebar/menuitem.html Wed Jan 28 02:27:25 2009 +0000
@@ -1,3 +1,3 @@
-<li class="leaf">
-<span><a href="{{ item.url }}">{{ item.title }}</a></span>
-</li>
\ No newline at end of file
+ <li class="leaf">
+ <span><a href="{{ item.url }}">{{ item.title }}</a></span>
+ </li>
\ No newline at end of file
--- a/app/soc/templates/soc/sidebar/sidebar.html Wed Jan 28 02:25:51 2009 +0000
+++ b/app/soc/templates/soc/sidebar/sidebar.html Wed Jan 28 02:27:25 2009 +0000
@@ -1,5 +1,24 @@
<ul>
-{% for subitem in sidebar_menu_items %}
+{% regroup sidebar_menu_items by group as grouped_items %}
+
+{% for grouped_item in grouped_items %}
+ {% ifequal grouped_item.grouper 'main' %}
+ {% for subitem in grouped_item.list %}
{% include 'soc/sidebar/submenu.html' %}
+ {% endfor %}
+ {% endifequal %}
+{% endfor %}
+
+{% for grouped_item in grouped_items %}
+ {% ifnotequal grouped_item.grouper 'main' %}
+ <li class="expandable">
+ <span>{{ grouped_item.grouper }}</span>
+ <ul>
+ {% for subitem in grouped_item.list %}
+{% include 'soc/sidebar/submenu.html' %}
+ {% endfor %}
+ </ul>
+ </li>
+ {% endifnotequal %}
{% endfor %}
</ul>
\ No newline at end of file
--- a/app/soc/templates/soc/sidebar/submenu.html Wed Jan 28 02:25:51 2009 +0000
+++ b/app/soc/templates/soc/sidebar/submenu.html Wed Jan 28 02:27:25 2009 +0000
@@ -1,8 +1,8 @@
-<li class="expandable">
-<span>{{ subitem.heading }}</span>
-<ul>
+ <li class="expandable">
+ <span>{{ subitem.heading }}</span>
+ <ul>
{% for item in subitem.items %}
{% include 'soc/sidebar/menuitem.html' %}
{% endfor %}
-</ul>
-</li>
\ No newline at end of file
+ </ul>
+ </li>
\ No newline at end of file
--- a/app/soc/views/helper/params.py Wed Jan 28 02:25:51 2009 +0000
+++ b/app/soc/views/helper/params.py Wed Jan 28 02:27:25 2009 +0000
@@ -102,6 +102,7 @@
new_params['invite_redirect'] = '/request/list'
new_params['sidebar'] = None
+ new_params['sidebar_grouping'] = 'main'
new_params['sidebar_defaults'] = [
('/%s/create', 'New %(name)s', 'create'),
('/%s/list', 'List %(name_plural)s', 'list'),
--- a/app/soc/views/models/group.py Wed Jan 28 02:25:51 2009 +0000
+++ b/app/soc/views/models/group.py Wed Jan 28 02:27:25 2009 +0000
@@ -347,6 +347,7 @@
# add the items together
menu['items'] = doc_items + group_items
+ menu['group'] = 'Clubs'
# append this as a new menu
menus.append(menu)
--- a/app/soc/views/models/program.py Wed Jan 28 02:25:51 2009 +0000
+++ b/app/soc/views/models/program.py Wed Jan 28 02:27:25 2009 +0000
@@ -140,6 +140,7 @@
menu['heading'] = entity.short_name
items = document_view.view.getMenusForScope(entity, params)
menu['items'] = sidebar.getSidebarMenu(id, user, items, params=doc_params)
+ menu['group'] = 'Programs'
menus.append(menu)
return menus
--- a/app/soc/views/sitemap/sidebar.py Wed Jan 28 02:25:51 2009 +0000
+++ b/app/soc/views/sitemap/sidebar.py Wed Jan 28 02:27:25 2009 +0000
@@ -22,6 +22,8 @@
]
+import operator
+
from soc.views import out_of_band
from soc.views.helper import access
@@ -56,7 +58,7 @@
for menu in (menus if menus else []):
sidebar.append(menu)
- return sidebar
+ return sorted(sidebar, key=lambda x: x.get('group'))
def getSidebarItems(params):
@@ -175,6 +177,7 @@
menu['heading'] = params['sidebar_heading']
menu['items'] = submenus
+ menu['group'] = params['sidebar_grouping']
menus = [menu]