Kevin Dangoor wrote:
myform = TableForm([TextField("foo1"), TextField("foo2")])
and SQLObjects are declared like this:
class MyTable(SQLObject):
foo1 = StringCol()
foo2 = StringCol()
Some folks have expressed that they'd like forms to be like this:
class MyForm(TableForm):
foo1 = TextField()
foo2 = TextField()
I'd played around unsuccessfully with weird dual object/class objects,
but I never quite figured it out. But I must know more now, because it
wasn't too hard. Here's an example with a very brief test:
http://svn.colorstudy.com/home/ianb/subclass_instance/
Basically this:
class MyForm(TableForm):
foo1 = TextField()
foo2 = TextField()
Is exactly equivalent to:
MyForm = type(TableForm)('MyForm', (TableForm,), {'foo1':
TextField(), 'foo2': TextField})
So if TableForm is an instance, then type(TableForm) is the class, and
the class is called with those arguments (i.e., instantiating).
It's all a little wacky, so I don't know that I'd recommend the trick.
But it does make large keyword-based instanciation easier on the eye.
--
Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org