Code

nicer template absence error
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Fri, 6 Sep 2002 22:54:52 +0000 (22:54 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Fri, 6 Sep 2002 22:54:52 +0000 (22:54 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1087 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/cgi/client.py
roundup/cgi/templating.py

index 122c0bc07a936cbfe03d271bd0155e5a94ea4b3d..58a9cffb3036ad473c85d40d15ec1cde79678148 100644 (file)
@@ -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 '<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()
index eea18ce7497ba5d1b0bf2f54fd592d1754ce5bf6..64f871614e8173f090048b6aec8d09c15a6f7cfc 100644 (file)
@@ -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: