Adds PanelGroup class and site customization hook.

* Adds a PanelGroup class and slightly reworks the way panel
    ordering is handled to fix bug 963550.

  * Adds the option to load a python module containing
    site customizations after the site is fully initialized,
    but before the URLConf is dynamically constructed.
    Fixes bug 965839.

Change-Id: Idc5358f2db6751494bcdfc382ec3bb6af65199b9
This commit is contained in:
Gabriel Hurley
2012-03-26 18:08:48 -07:00
parent a5d5b4f288
commit ac71246802
9 changed files with 206 additions and 56 deletions

View File

@@ -16,9 +16,8 @@
from __future__ import absolute_import
import copy
from django import template
from django.utils.datastructures import SortedDict
from horizon.base import Horizon
@@ -78,21 +77,20 @@ def horizon_dashboard_nav(context):
if 'request' not in context:
return {}
dashboard = context['request'].horizon['dashboard']
if isinstance(dashboard.panels, dict):
panels = copy.copy(dashboard.get_panels())
else:
panels = {dashboard.name: dashboard.get_panels()}
panel_groups = dashboard.get_panel_groups()
non_empty_groups = []
for heading, items in panels.iteritems():
temp_panels = []
for panel in items:
for group in panel_groups.values():
allowed_panels = []
for panel in group:
if callable(panel.nav) and panel.nav(context):
temp_panels.append(panel)
allowed_panels.append(panel)
elif not callable(panel.nav) and panel.nav:
temp_panels.append(panel)
panels[heading] = temp_panels
non_empty_panels = dict([(k, v) for k, v in panels.items() if len(v) > 0])
return {'components': non_empty_panels,
allowed_panels.append(panel)
if allowed_panels:
non_empty_groups.append((group.name, allowed_panels))
return {'components': SortedDict(non_empty_groups),
'user': context['request'].user,
'current': context['request'].horizon['panel'].slug,
'request': context['request']}