import random
import crypt

from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()

@register.filter
def template_exists(template_name):
    try:
        template.loader.get_template(template_name)
        return True
    except template.TemplateDoesNotExist:
        return False

@register.filter
def shuffle(arg):
    tmp = list(arg)[:]
    random.shuffle(tmp)
    return tmp

@register.filter
def hash(arg):
    return crypt.crypt(str(arg))




#register.filter('template_exists', template_exists) 
