The FormComponent abstraction in quixote.form2 is nice, but it's hard to
specify a default component class without subclassing Form and setting
WIDGET_ROW_CLASS. Come to think of it, COMPONENT_CLASS would be a
better name than WIDGET_ROW_CLASS.
Here's a patch. Suggested checkin comment:
"""
Rename Form.WIDGET_ROW_CLASS to COMPONENT_CLASS, since that'
what it really is. Make it an instance attribute as well as a
class attribute, so it can be overridden at form construction
time.
"""
Of course, the renaming will break all existing code that uses
quixote.form2, but better now than later, eh?
--- form.py.orig0 2003-11-17 21:45:04.000000000 -0500
+++ form.py 2003-11-23 11:03:27.000000000 -0500
@@ -240,10 +240,15 @@
TOKEN_NAME = "_form_id" # name of hidden token widget
- WIDGET_ROW_CLASS = WidgetRow
+ COMPONENT_CLASS = WidgetRow
- def __init__(self, name=None, method="post", action_url=None,
- enctype=None, use_tokens=True):
+ def __init__(self,
+ name=None,
+ method="post",
+ action_url=None,
+ enctype=None,
+ use_tokens=True,
+ component_class=None):
if method not in ("post", "get"):
raise ValueError("Form method must be 'post' or 'get', "
@@ -272,6 +277,8 @@
self.add_hidden(self.TOKEN_NAME, None, FormTokenWidget)
self.use_form_tokens = True
+ self.component_class = component_class or self.COMPONENT_CLASS
+
def _get_default_action_url(self):
request = get_request()
action_url = url_quote(request.get_path())
@@ -384,7 +391,7 @@
"""
if issubclass(klass, HiddenWidget):
raise TypeError, "use add_hidden() to add hidden widgets"
- self.add_component(self.WIDGET_ROW_CLASS, name, klass, value,
+ self.add_component(self.component_class, name, klass, value,
title, hint, required, **kwargs)
Whaddya think?
Greg
--
Greg Ward http://www.gerg.ca/
If you and a friend are being chased by a lion, it is not necessary to
outrun the lion. It is only necessary to outrun your friend.