from django.template import TemplateDoesNotExist
from django.conf import settings

def load_template_source(template_name, template_dirs=None):
    if not template_dirs:
        template_dirs = settings.TEMPLATE_DIRS

    for template_dir in template_dirs:
        template_location = "%s/%s" % (template_dir, template_name)
        try:
            file_contents = open(template_location).read()
            header = "<span style='font-family:Verdana; font-size:9px;'>&nbsp;template: <u>%s</u></span><br/>" % template_name
            file_contents = header + file_contents
            return (file_contents, template_name)
        except IOError:
            continue
        raise TemplateDoesNotExist, template_name
    
load_template_source.is_usable = True