Added templatetag to only display enabled apps

This commit is contained in:
2010-04-05 03:19:29 +01:00
parent 586a2727b1
commit 87b4b01ec3
3 changed files with 24 additions and 0 deletions

View File

View File

@@ -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

View File

@@ -1,3 +1,5 @@
{% load installed %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
@@ -17,7 +19,9 @@
<li><a href="/">Home</a></li>
{% if request.user %}
<li><a href="/profile">Profile</a></li>
{% if "hr"|installed %}
<li><a href="/hr/">HR</a></li>
{% endif %}
<li><a href="/profile/characters">Characters</a></li>
{% if request.user.is_staff %}
<li><a href="/users">Lookup User</a></li>