From 49e6d20b49a054dc380b5f1e14595dbece2e90bd Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 6 Sep 2002 22:54:52 +0000 Subject: [PATCH] nicer template absence error git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1087 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/cgi/client.py | 6 ++++-- roundup/cgi/templating.py | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index 122c0bc..58a9cff 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -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 @@ import binascii, Cookie, time, random 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 @@ class Client: except PageTemplate.PTRuntimeError, message: return '%s
    %s
'%(message, '
  • '.join(pt._v_errors)) + except NoTemplate, message: + return '%s'%message except: # everything else return cgitb.pt_html() diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index eea18ce..64f8716 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -60,6 +60,9 @@ from roundup.cgi import ZTUtils 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 @@ def getTemplate(dir, name, extension, classname=None, request=None): 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: -- 2.30.2