1- # $Id: client.py,v 1.130.2.11 2004-02-24 23:37:10 richard Exp $
1+ # $Id: client.py,v 1.130.2.12 2004-02-25 23:23:56 richard Exp $
22
33__doc__ = """
44WWW request handler (also used in the stand-alone server).
@@ -26,6 +26,23 @@ class Redirect(HTTPException):
2626 pass
2727class NotModified (HTTPException ):
2828 pass
29+ class SeriousError (Exception ):
30+ ''' Raised when we can't reasonably display an error message on a
31+ templated page.
32+
33+ The exception value will be displayed in the error page, HTML
34+ escaped.
35+ '''
36+ def __str__ (self ):
37+ return '''
38+ <html><head><title>Roundup issue tracker: An error has occurred</title>
39+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8;">
40+ <link rel="stylesheet" type="text/css" href="_file/style.css">
41+ </head>
42+ <body class="body" marginwidth="0" marginheight="0">
43+ <p class="error-message">%s</p>
44+ </body></html>
45+ ''' % cgi .escape (self .args [0 ])
2946
3047# set to indicate to roundup not to actually _send_ email
3148# this var must contain a file to write the mail to
@@ -262,6 +279,8 @@ def inner_main(self):
262279
263280 # render the content
264281 self .write (self .renderContext ())
282+ except SeriousError , message :
283+ self .write (str (message ))
265284 except Redirect , url :
266285 # let's redirect - if the url isn't None, then we need to do
267286 # the headers, otherwise the headers have been set before the
@@ -1458,7 +1477,6 @@ def retirePermission(self):
14581477 return 0
14591478 return 1
14601479
1461-
14621480 def showAction (self , typere = re .compile ('[@:]type' ),
14631481 numre = re .compile ('[@:]number' )):
14641482 ''' Show a node of a particular class/id
@@ -1470,7 +1488,18 @@ def showAction(self, typere=re.compile('[@:]type'),
14701488 elif numre .match (key ):
14711489 n = self .form [key ].value .strip ()
14721490 if not t :
1473- raise ValueError , 'Invalid %s number' % t
1491+ raise ValueError , 'No type specified'
1492+ return
1493+ if not n :
1494+ raise SeriousError , _ ('No ID entered' )
1495+ return
1496+ try :
1497+ int (n )
1498+ except ValueError :
1499+ d = {'input' : n , 'classname' : t }
1500+ raise SeriousError , _ (
1501+ '"%(input)s" is not an ID (%(classname)s ID required)' )% d
1502+ return
14741503 url = '%s%s%s' % (self .db .config .TRACKER_WEB , t , n )
14751504 raise Redirect , url
14761505
0 commit comments