From 87b4b01ec329500de62c8e83dbdfbe7afb960690 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Mon, 5 Apr 2010 03:19:29 +0100 Subject: [PATCH] Added templatetag to only display enabled apps --- sso/templatetags/__init__.py | 0 sso/templatetags/installed.py | 20 ++++++++++++++++++++ templates/base.html | 4 ++++ 3 files changed, 24 insertions(+) create mode 100644 sso/templatetags/__init__.py create mode 100644 sso/templatetags/installed.py diff --git a/sso/templatetags/__init__.py b/sso/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sso/templatetags/installed.py b/sso/templatetags/installed.py new file mode 100644 index 0000000..01a68a7 --- /dev/null +++ b/sso/templatetags/installed.py @@ -0,0 +1,20 @@ +from django import template +from django.conf import settings +from django.template.defaultfilters import stringfilter + +register = template.Library() + +@register.filter +@stringfilter +def installed(value): + apps = settings.INSTALLED_APPS + if "." in value: + for app in apps: + if app == value: + return True + else: + for app in apps: + fields = app.split(".") + if fields[-1] == value: + return True + return False diff --git a/templates/base.html b/templates/base.html index 7c8b1b0..9de6e3c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,3 +1,5 @@ +{% load installed %} + @@ -17,7 +19,9 @@
  • Home
  • {% if request.user %}
  • Profile
  • + {% if "hr"|installed %}
  • HR
  • + {% endif %}
  • Characters
  • {% if request.user.is_staff %}
  • Lookup User