Code

forward-port from maint branch
authorrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Wed, 25 Feb 2004 23:27:54 +0000 (23:27 +0000)
committerrichard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2>
Wed, 25 Feb 2004 23:27:54 +0000 (23:27 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2121 57a73879-2fb5-44c3-a270-3262357dd7e2

CHANGES.txt
roundup/cgi/actions.py
roundup/cgi/client.py
roundup/cgi/exceptions.py

index 60abfcbed0ba1281bcfebd2669c5791f676e19e5..2cc96571d6e8ec08f668d3f32003b2b7a19d694c 100644 (file)
@@ -78,6 +78,8 @@ Cleanup:
 Fixed:
 - made error on create consistent with edit when user enters invalid data
   for Multilink and Link form fields (sf bug 904072)
+- made errors from bad input in the quick "Show issue:" form more
+  user-friendly (sf bug 904064)
 
 
 2004-02-25 0.6.6
index ceb89bb8344443d962e1e3a98c7a276222b7acb8..1f57ff8e63b14aa0852befa329b82fbb3fa43893 100755 (executable)
@@ -3,7 +3,7 @@ import re, cgi, StringIO, urllib, Cookie, time, random
 from roundup import hyperdb, token, date, password, rcsv
 from roundup.i18n import _
 from roundup.cgi import templating
-from roundup.cgi.exceptions import Redirect, Unauthorised
+from roundup.cgi.exceptions import Redirect, Unauthorised, SeriousError
 from roundup.mailgw import uidFromAddress
 
 __all__ = ['Action', 'ShowAction', 'RetireAction', 'SearchAction',
@@ -66,7 +66,15 @@ class ShowAction(Action):
             elif numre.match(key):
                 n = self.form[key].value.strip()
         if not t:
-            raise ValueError, 'Invalid %s number'%t
+            raise ValueError, 'No type specified'
+        if not n:
+            raise SeriousError, _('No ID entered')
+        try:
+            int(n)
+        except ValueError:
+            d = {'input': n, 'classname': t}
+            raise SeriousError, _(
+                '"%(input)s" is not an ID (%(classname)s ID required)')%d
         url = '%s%s%s'%(self.db.config.TRACKER_WEB, t, n)
         raise Redirect, url
 
@@ -593,7 +601,8 @@ Your password is now: %(password)s
 
         # generate the one-time-key and store the props for later
         otk = ''.join([random.choice(chars) for x in range(32)])
-        self.db.otks.set(otk, uid=uid, __time=time.time())
+        d = {'uid': uid, self.db.otks.timestamp: time.time()}
+        self.db.otks.set(otk, **d)
 
         # send the email
         tracker_name = self.db.config.TRACKER_NAME
@@ -658,7 +667,7 @@ class RegisterAction(Action):
 
         Return 1 on successful login.
         """
-        props = self.client.parsePropsFromForm(create=1)[0][('user', None)]
+        props = self.client.parsePropsFromForm(create=True)[0][('user', None)]
 
         # registration isn't allowed to supply roles
         if props.has_key('roles'):
@@ -686,7 +695,7 @@ class RegisterAction(Action):
                 props[propname] = str(value)
             elif isinstance(proptype, hyperdb.Password):
                 props[propname] = str(value)
-        props['__time'] = time.time()
+        props[self.db.otks.timestamp] = time.time()
         self.db.otks.set(otk, **props)
 
         # send the email
index 5c31b774fe5e2e674cdae96d54a5c3aec85dbd32..d96aa168258a13532244194fd88ef6eabc16a394 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: client.py,v 1.164 2004-02-25 03:39:53 richard Exp $
+# $Id: client.py,v 1.165 2004-02-25 23:27:54 richard Exp $
 
 """WWW request handler (also used in the stand-alone server).
 """
@@ -208,6 +208,8 @@ class Client:
 
             # render the content
             self.write(self.renderContext())
+        except SeriousError, message:
+            self.write(str(message))
         except Redirect, url:
             # let's redirect - if the url isn't None, then we need to do
             # the headers, otherwise the headers have been set before the
index 1ae37e1b89d87b5eaccc2761d3ac7aa9f3987d57..0b3fe932bc7e2c094271da79dd077130b1b27ce3 100755 (executable)
@@ -30,3 +30,22 @@ class SendFile(Exception):
 
 class SendStaticFile(Exception):
     """Send a static file from the instance html directory."""
+
+class SeriousError(Exception):
+    """Raised when we can't reasonably display an error message on a
+    templated page.
+
+    The exception value will be displayed in the error page, HTML
+    escaped.
+    """
+    def __str__(self):
+        return '''
+<html><head><title>Roundup issue tracker: An error has occurred</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8;">
+ <link rel="stylesheet" type="text/css" href="_file/style.css">
+</head>
+<body class="body" marginwidth="0" marginheight="0">
+ <p class="error-message">%s</p>
+</body></html>
+'''%cgi.escape(self.args[0])
+