From 50fdf06c97dad185392e74090694bc6a7f921dce Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Fri, 15 Mar 2019 21:33:50 -0700 Subject: [PATCH] add nav_extras.py template tags --- procat2/templatetags/__init__.py | 0 procat2/templatetags/nav_extras.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 procat2/templatetags/__init__.py create mode 100644 procat2/templatetags/nav_extras.py diff --git a/procat2/templatetags/__init__.py b/procat2/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/procat2/templatetags/nav_extras.py b/procat2/templatetags/nav_extras.py new file mode 100644 index 0000000..38d3544 --- /dev/null +++ b/procat2/templatetags/nav_extras.py @@ -0,0 +1,28 @@ +from django import template +from django.contrib.auth import get_user +from lazysignup.utils import is_lazy_user +import logging + +log = logging.getLogger(__name__) + +register = template.Library() + + +@register.simple_tag(takes_context=True) +def if_in_app(context, app_name, output): + """If this view is in app 'app_name', output 'output'""" + current_app = context['request'].current_app + return output if app_name == current_app else '' + + +@register.simple_tag(takes_context=True) +def username(context): + """Return a sensible name for the current user.""" + user = get_user(context['request']) + + if is_lazy_user(user): + return "Guest" + elif user.is_anonymous: + return "Anon" + else: + return user.get_full_name()