mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Added templatetag to only display enabled apps
This commit is contained in:
0
sso/templatetags/__init__.py
Normal file
0
sso/templatetags/__init__.py
Normal file
20
sso/templatetags/installed.py
Normal file
20
sso/templatetags/installed.py
Normal 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
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user