From 1dc42bba4ab78bc35ef57825e59354c125da6a5c Mon Sep 17 00:00:00 2001 From: Jake Dahn Date: Tue, 23 Aug 2011 15:54:12 -0700 Subject: [PATCH 1/2] cleaning up recurring calls in sidebar template tag --- .../templatetags/templatetags/sidebar_modules.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py b/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py index 244a4f1f4..c5b08a51c 100644 --- a/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py +++ b/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py @@ -6,13 +6,15 @@ register = template.Library() @register.inclusion_tag('_sidebar_module.html') def dash_sidebar_modules(request): - if signals.dash_apps_detect()[0][1]['type'] == "dash": - return {'modules': [module[1] for module in signals.dash_apps_detect()], + signals_call = signals.dash_modules_detect() + if signals_call[0][1]['type'] == "dash": + return {'modules': [module[1] for module in signals_call], 'request': request } @register.inclusion_tag('_sidebar_module.html') def syspanel_sidebar_modules(request): - if signals.dash_apps_detect()[0][1]['type'] == "syspanel": - return {'modules': [module[1] for module in signals.dash_apps_detect()], + signals_call = signals.dash_modules_detect() + if signals_call[0][1]['type'] == "syspanel": + return {'modules': [module[1] for module in signals_call], 'request': request } From 2f1a0536cba981f1db4c4172bec619f163beca8a Mon Sep 17 00:00:00 2001 From: Jake Dahn Date: Tue, 23 Aug 2011 16:22:39 -0700 Subject: [PATCH 2/2] cleaning up a few things, and making template tag not error out when there are no modules --- django-openstack/django_openstack/signals.py | 10 ++++----- .../templatetags/sidebar_modules.py | 21 ++++++++++++------- django-openstack/django_openstack/urls.py | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/django-openstack/django_openstack/signals.py b/django-openstack/django_openstack/signals.py index b2c7e0681..dc5b1189f 100644 --- a/django-openstack/django_openstack/signals.py +++ b/django-openstack/django_openstack/signals.py @@ -1,11 +1,11 @@ import django.dispatch from django.dispatch import receiver -dash_apps_ping = django.dispatch.Signal() -dash_apps_urls = django.dispatch.Signal() +dash_modules_ping = django.dispatch.Signal() +dash_modules_urls = django.dispatch.Signal() -def dash_apps_detect(): +def dash_modules_detect(): """ Sends a pinging signal to the app, all listening modules will reply with items for the sidebar. @@ -20,13 +20,13 @@ def dash_apps_detect(): 'text':'Google', 'active_text': 'google'}], 'type': syspanel}) """ - return dash_apps_ping.send(sender=dash_apps_ping) + return dash_modules_ping.send(sender=dash_modules_ping) def dash_app_setup_urls(): """ Adds urls from modules """ - return dash_apps_urls.send(sender=dash_apps_urls) + return dash_modules_urls.send(sender=dash_modules_urls) diff --git a/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py b/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py index c5b08a51c..fcae5ea64 100644 --- a/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py +++ b/django-openstack/django_openstack/templatetags/templatetags/sidebar_modules.py @@ -7,14 +7,19 @@ register = template.Library() @register.inclusion_tag('_sidebar_module.html') def dash_sidebar_modules(request): signals_call = signals.dash_modules_detect() - if signals_call[0][1]['type'] == "dash": - return {'modules': [module[1] for module in signals_call], - 'request': request } - + if signals_call: + if signals_call[0][1]['type'] == "dash": + return {'modules': [module[1] for module in signals_call], + 'request': request } + else: + return {} + @register.inclusion_tag('_sidebar_module.html') def syspanel_sidebar_modules(request): signals_call = signals.dash_modules_detect() - if signals_call[0][1]['type'] == "syspanel": - return {'modules': [module[1] for module in signals_call], - 'request': request } - + if signals_call: + if signals_call[0][1]['type'] == "syspanel": + return {'modules': [module[1] for module in signals_call], + 'request': request } + else: + return {} diff --git a/django-openstack/django_openstack/urls.py b/django-openstack/django_openstack/urls.py index 8031eb8bd..d06d176af 100644 --- a/django-openstack/django_openstack/urls.py +++ b/django-openstack/django_openstack/urls.py @@ -29,5 +29,5 @@ urlpatterns = patterns('', ) # import urls from modules -for module_urls in dash_apps_urls.send(sender=dash_apps_urls): +for module_urls in dash_modules_urls.send(sender=dash_modules_urls): urlpatterns += module_urls[1].urlpatterns