import re
from django.template.defaultfilters import stringfilter
from django import template
from django.contrib.auth.models import Group

register = template.Library()
whitespace_re = re.compile(r'\s')

@register.filter(name='remove_whitespace')
@stringfilter
def remove_whitespace(s):
    return whitespace_re.sub('', s)

@register.filter(name='has_group')
def has_group(user, group_name):
    group = Group.objects.get(name=group_name)
    return True if group in user.groups.all() else False