from django import template

register = template.Library()

@register.filter(name='has_group')
def has_group(user, group_name):
    if user is None:
        return False
    try:
        return user.groups.filter(name=group_name).exists()
    except Exception:
        return False
