add nav_extras.py template tags

This commit is contained in:
Seth Ladygo
2019-03-15 21:33:50 -07:00
parent 5b6b7c4964
commit 50fdf06c97
2 changed files with 28 additions and 0 deletions

View File

View File

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