Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 1068:665730c27d29
nicer template absence error
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 06 Sep 2002 22:54:52 +0000 |
| parents | 73e7bbb8a1fa |
| children | cf30c6cdca02 |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Fri Sep 06 22:47:13 2002 +0000 +++ b/roundup/cgi/templating.py Fri Sep 06 22:54:52 2002 +0000 @@ -60,6 +60,9 @@ templates = {} +class NoTemplate(Exception): + pass + def getTemplate(dir, name, extension, classname=None, request=None): ''' Interface to get a template, possibly loading a compiled template. @@ -83,12 +86,24 @@ try: stime = os.stat(src)[os.path.stat.ST_MTIME] except os.error, error: - if error.errno != errno.ENOENT or not extension: + if error.errno != errno.ENOENT: raise + if not extension: + raise NoTemplate, 'Template file "%s" doesn\'t exist'%name + # try for a generic template - filename = '_generic.%s'%extension - src = os.path.join(dir, filename) - stime = os.stat(src)[os.path.stat.ST_MTIME] + generic = '_generic.%s'%extension + src = os.path.join(dir, generic) + try: + stime = os.stat(src)[os.path.stat.ST_MTIME] + except os.error, error: + if error.errno != errno.ENOENT: + raise + # nicer error + raise NoTemplate, 'No template file exists for templating '\ + '"%s" with template "%s" (neither "%s" nor "%s")'%(name, + extension, filename, generic) + filename = generic key = (dir, filename) if templates.has_key(key) and stime < templates[key].mtime:
