Ticket #1194: filesystem.diff
File filesystem.diff, 2.1 KB (added by , 18 years ago) |
---|
-
__init__.py
116 116 class TemplateDoesNotExist(Exception): 117 117 pass 118 118 119 class TemplateIsNotReadable(TemplateDoesNotExist): 120 # subclassed to provide backwards-compatibility in catch blocks 121 pass 122 119 123 class VariableDoesNotExist(Exception): 120 124 121 125 def __init__(self, msg, params=()): -
loaders/filesystem.py
1 1 # Wrapper for loading templates from the filesystem. 2 2 3 3 from django.conf import settings 4 from django.template import TemplateDoesNotExist 4 from django.template import TemplateDoesNotExist, TemplateIsNotReadable 5 5 import os 6 import errno 6 7 7 8 def get_template_sources(template_name, template_dirs=None): 8 9 if not template_dirs: … … 12 13 13 14 def load_template_source(template_name, template_dirs=None): 14 15 tried = [] 16 found = [] 17 error_class = TemplateDoesNotExist 15 18 for filepath in get_template_sources(template_name, template_dirs): 16 19 try: 17 20 return (open(filepath).read(), filepath) 18 except IOError: 19 tried.append(filepath) 20 if tried: 21 except IOError, (code, message): 22 if code == errno.EACCES: 23 # file exists but is unreadable 24 tried.append(filepath) 25 found.append(filepath) 26 error_class = TemplateIsNotReadable 27 else: 28 # file didn't exist, or something else happened 29 tried.append(filepath) 30 31 if found: 32 # if we found something, but it was unreadable, make a special note 33 error_msg = "Tried %s, Found unreadable %s" % (tried, found) 34 elif tried: 21 35 error_msg = "Tried %s" % tried 22 36 else: 23 37 error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory." 24 raise TemplateDoesNotExist, error_msg38 raise error_class, error_msg 25 39 load_template_source.is_usable = True