From 1ef3649006d7aa54aa1facd64b3c52f434023f84 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 25 Feb 2004 23:27:54 +0000 Subject: [PATCH] forward-port from maint branch git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2121 57a73879-2fb5-44c3-a270-3262357dd7e2 --- CHANGES.txt | 2 ++ roundup/cgi/actions.py | 19 ++++++++++++++----- roundup/cgi/client.py | 4 +++- roundup/cgi/exceptions.py | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 60abfcb..2cc9657 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/roundup/cgi/actions.py b/roundup/cgi/actions.py index ceb89bb..1f57ff8 100755 --- a/roundup/cgi/actions.py +++ b/roundup/cgi/actions.py @@ -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 diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index 5c31b77..d96aa16 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -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 diff --git a/roundup/cgi/exceptions.py b/roundup/cgi/exceptions.py index 1ae37e1..0b3fe93 100755 --- a/roundup/cgi/exceptions.py +++ b/roundup/cgi/exceptions.py @@ -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 ''' +Roundup issue tracker: An error has occurred + + + + +

%s

+ +'''%cgi.escape(self.args[0]) + -- 2.30.2