add nav_extras.py template tags
This commit is contained in:
0
procat2/templatetags/__init__.py
Normal file
0
procat2/templatetags/__init__.py
Normal file
28
procat2/templatetags/nav_extras.py
Normal file
28
procat2/templatetags/nav_extras.py
Normal 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()
|
||||||
Reference in New Issue
Block a user