Mercurial > p > roundup > code
changeset 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 | b3a2b6d2a142 |
| files | roundup/cgi/client.py roundup/cgi/templating.py |
| diffstat | 2 files changed, 23 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/cgi/client.py Fri Sep 06 22:47:13 2002 +0000 +++ b/roundup/cgi/client.py Fri Sep 06 22:54:52 2002 +0000 @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.19 2002-09-06 07:21:31 richard Exp $ +# $Id: client.py,v 1.20 2002-09-06 22:54:51 richard Exp $ __doc__ = """ WWW request handler (also used in the stand-alone server). @@ -10,7 +10,7 @@ from roundup import roundupdb, date, hyperdb, password from roundup.i18n import _ -from roundup.cgi.templating import getTemplate, HTMLRequest +from roundup.cgi.templating import getTemplate, HTMLRequest, NoTemplate from roundup.cgi import cgitb from PageTemplates import PageTemplate @@ -324,6 +324,8 @@ except PageTemplate.PTRuntimeError, message: return '<strong>%s</strong><ol>%s</ol>'%(message, '<li>'.join(pt._v_errors)) + except NoTemplate, message: + return '<strong>%s</strong>'%message except: # everything else return cgitb.pt_html()
--- 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:
