go_extras.py 1.24 KB
Newer Older
1 2 3
# Future Imports
from __future__ import unicode_literals, absolute_import, print_function, division

4
# Django Imports
5
from django import template
6 7

# App Imports
8 9
from go.models import RegisteredUser

10 11 12 13
# To be a valid tag library, the module must contain a module-level variable
# named register that is a template.Library instance, in which all the tags and
# filters are registered.
register = template.Library()
14

15 16 17
"""
    check if a user is registered
"""
18
@register.filter
19
def is_registered(user):
20
    # try getting the RegisteredUser of the current user
21
    try:
22
        registered = RegisteredUser.objects.get(username=user.username)
23
        # if it works then the user is registered
24 25
        return True
    except RegisteredUser.DoesNotExist:
26
        # if they don't exist then they are not registered
27
        return False
28

29 30 31
"""
    check if a user is approved
"""
32 33
@register.filter
def is_approved(user):
34
    # try getting the RegisteredUser of the current user
35
    try:
36
        registered = RegisteredUser.objects.get(username=user.username)
37
        # if they exist, return whether or not they are approved (boolean)
38 39
        return registered.approved
    except RegisteredUser.DoesNotExist:
40
        # if they don't exist then they are not approved
41
        return False