Use %r in error messages. [...] (quixote/form/form.ptl)
Greg Ward <gward-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 20 Nov 2002 14:39:57 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /home/cvs/quixote/form
In directory hewson:/tmp/cvs-serv18695
Modified Files:
form.ptl
Log Message:
Use %r in error messages.
Tweak "there were errors in your form" markup.
Rewrite get_widget_class() to improve error reporting: now it requires
either a callable (which is just returned) or a registered widget class
name; if given neither, it raises ValueError with a sensible error
message.
Index: form.ptl
===================================================================
RCS file: /home/cvs/quixote/form/form.ptl,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- form.ptl 7 Nov 2002 17:49:15 -0000 1.6
+++ form.ptl 20 Nov 2002 19:39:55 -0000 1.7
@@ -88,15 +88,15 @@
def __init__ (self, method="post", enctype=None, use_tokens=1):
if method not in ("post", "get"):
- raise ValueError("Form method must be 'post' or 'get' "
- "not %s" % method)
+ raise ValueError("Form method must be 'post' or 'get', "
+ "not %r" % method)
self.method = method
if enctype is not None and enctype not in (
"application/x-www-form-urlencoded", "multipart/form-data"):
raise ValueError, ("Form enctype must be "
"'application/x-www-form-urlencoded' or "
- "'multipart/form-data' not %s" % enctype)
+ "'multipart/form-data', not %r" % enctype)
self.enctype = enctype
# The first major component of a form: its widgets. We want
@@ -216,7 +216,7 @@
def _render_error_notice [html] (self, request):
if self.error:
'<tr><td colspan="3">'
- '<font color="red">Warning:</font> '
+ '<font color="red"><strong>Warning:</strong></font> '
'there were errors processing your form. See below for details.'
'</td></tr>\n'
@@ -501,7 +501,13 @@
def get_widget_class (widget_type):
global _widget_class
- klass = _widget_class.get(widget_type, widget_type)
- if not callable(klass):
- raise TypeError, 'widget_type %r is not callable' % widget_type
- return klass
+ if callable(widget_type):
+ # Presumably someone passed a widget class object to
+ # Widget.create_subwidget() or Form.add_widget() --
+ # don't bother with the widget class registry at all.
+ return widget_type
+ else:
+ try:
+ return _widget_class[widget_type]
+ except KeyError:
+ raise ValueError("unknown widget type %r" % widget_type)