diff --git a/django-openstack/django_openstack/templates/django_openstack/common/_sidebar_module.html b/django-openstack/django_openstack/templates/django_openstack/common/_sidebar_module.html
index a472725e5..661108dc7 100644
--- a/django-openstack/django_openstack/templates/django_openstack/common/_sidebar_module.html
+++ b/django-openstack/django_openstack/templates/django_openstack/common/_sidebar_module.html
@@ -1,6 +1,6 @@
{% for module in modules %}
{{module.title}}
-
+
{% for link in module.links %}
- {{link.text}}
diff --git a/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py b/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py
index 4727c5f70..c4172e22c 100644
--- a/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py
+++ b/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py
@@ -28,8 +28,8 @@ register = template.Library()
def dash_sidebar_modules(request):
signals_call = signals.dash_modules_detect()
if signals_call:
- if signals_call[0][1]['type'] == "dash":
- return {'modules': [module[1] for module in signals_call],
+ return {'modules': [module[1] for module in signals_call
+ if module[1]['type'] == "dash"],
'request': request}
else:
return {}
@@ -39,8 +39,8 @@ def dash_sidebar_modules(request):
def syspanel_sidebar_modules(request):
signals_call = signals.dash_modules_detect()
if signals_call:
- if signals_call[0][1]['type'] == "syspanel":
- return {'modules': [module[1] for module in signals_call],
+ return {'modules': [module[1] for module in signals_call
+ if module[1]['type'] == "syspanel"],
'request': request}
else:
return {}
diff --git a/django-openstack/django_openstack/tests/api_tests.py b/django-openstack/django_openstack/tests/api_tests.py
index 584bd7a9f..70c616555 100644
--- a/django-openstack/django_openstack/tests/api_tests.py
+++ b/django-openstack/django_openstack/tests/api_tests.py
@@ -309,13 +309,13 @@ class ApiHelperTests(test.TestCase):
GLANCE_URL = 'http://glance/glanceapi/'
NOVA_URL = 'http://nova/novapi/'
- url = api.url_for(self.request, 'glance')
+ url = api.url_for(self.request, 'image')
self.assertEqual(url, GLANCE_URL + 'internal')
- url = api.url_for(self.request, 'glance', admin=False)
+ url = api.url_for(self.request, 'image', admin=False)
self.assertEqual(url, GLANCE_URL + 'internal')
- url = api.url_for(self.request, 'glance', admin=True)
+ url = api.url_for(self.request, 'image', admin=True)
self.assertEqual(url, GLANCE_URL + 'admin')
url = api.url_for(self.request, 'compute')
@@ -1238,7 +1238,7 @@ class GlanceApiTests(test.TestCase):
client_instance.auth_tok = TEST_TOKEN
self.mox.StubOutWithMock(api, 'url_for')
- api.url_for(IsA(http.HttpRequest), 'glance').AndReturn(TEST_URL)
+ api.url_for(IsA(http.HttpRequest), 'image').AndReturn(TEST_URL)
self.mox.ReplayAll()
diff --git a/django-openstack/django_openstack/tests/templatetag_tests.py b/django-openstack/django_openstack/tests/templatetag_tests.py
new file mode 100644
index 000000000..c49f90521
--- /dev/null
+++ b/django-openstack/django_openstack/tests/templatetag_tests.py
@@ -0,0 +1,62 @@
+import re
+
+from django import dispatch, http, template
+from django.utils.text import normalize_newlines
+
+from django_openstack import signals, test
+
+def single_line(text):
+ ''' Quick utility to make comparing template output easier. '''
+ return re.sub(' +', ' ', normalize_newlines(text).replace('\n', '')).strip()
+
+
+class TemplateTagTests(test.TestCase):
+ def setUp(self):
+ super(TemplateTagTests, self).setUp()
+ self._signal = self.mox.CreateMock(dispatch.Signal)
+
+ def test_sidebar_modules(self):
+ '''
+ Tests for the sidebar module registration mechanism.
+
+ The standard "ping" signal return value looks like this:
+
+ tuple(, {
+ 'title': 'Nixon',
+ 'links': [{'url':'/syspanel/nixon/google',
+ 'text':'Google', 'active_text': 'google'}],
+ 'type': 'syspanel',
+ })
+ '''
+ self.mox.StubOutWithMock(signals, 'dash_modules_detect')
+ signals_call= (
+ (self._signal, {
+ 'title': 'Nixon',
+ 'links': [{'url':'/dash/nixon/google',
+ 'text':'Google', 'active_text': 'google'}],
+ 'type': 'dash',
+ }),
+ (self._signal, {
+ 'title': 'Nixon',
+ 'links': [{'url':'/syspanel/nixon/google',
+ 'text':'Google', 'active_text': 'google'}],
+ 'type': 'syspanel',
+ }),
+ )
+ signals.dash_modules_detect().AndReturn(signals_call)
+ signals.dash_modules_detect().AndReturn(signals_call)
+ self.mox.ReplayAll()
+
+ context = template.Context({'request': self.request})
+
+ # Dash module is rendered correctly, and only in dash sidebar
+ ttext = '{% load sidebar_modules %}{% dash_sidebar_modules request %}'
+ t = template.Template(ttext)
+ self.assertEqual(single_line(t.render(context)) , 'Nixon
')
+
+ # Syspanel module is rendered correctly and only in syspanel sidebar
+ ttext = '{% load sidebar_modules %}{% syspanel_sidebar_modules request %}'
+ t = template.Template(ttext)
+ self.assertEqual(single_line(t.render(context)) , 'Nixon
')
+
+ self.mox.VerifyAll()