def in_group(user, groups):
    """Returns a boolean if the user is in the given group, or comma-separated
    list of groups.

    Usage::

        {% if user|in_group:"Friends" %}
        ...
        {% endif %}

    or::

        {% if user|in_group:"Friends,Enemies" %}
        ...
        {% endif %}

    """
    group_list = (groups).split(',')
    try:
#        print group_list, user.groups.filter(), user.groups.values('name'), user

        return bool(user.groups.filter(name__in=group_list).values('name'))
    except:
        return False