Ben Bangert wrote:
On Mar 3, 2006, at 12:56 AM, Alastair Houghton wrote:

Maybe I'm being dumb, but can't you already do this? SQLAlchemy already supports custom types for column data (so, for instance, one of my tables is returning a special UUID object based on a string column in the database).

Or is this really about syntactic sugar (i.e. making SQLAlchemy look like Django)?

What I'm looking at would simply definition, so its syntactic sugar to an extent, plus it would setup validation so that the model knows how to validate itself (to an extent).

Hi Ben,

I've done this independent of the model. In the gui layer actually. I've pretty much combined ideas from FunFormKit (for rendering fields), Django ORM (for defining fields) and FormEncode (for validation). The big difference is I've stuck it all together with helpers for autogenerating (very very usable and reusable) forms complete with validation and rendering abilities. The helpers use metadata (currently only SA at the moment, but I don't see why it can't support any other ORM) to generate the forms.

eg.

from forms import Form, field, layout, helper

user = Table('user', engine,
Column('user_id', Integer(), Sequence('user_id_seq'), primary_key=True, nullable=False),
   Column('first_name', String(50), nullable=False),
   Column('age', Integer()),
   Column('dob', Date()),
   Column('email', String(50)),
)

#manual creation
form = Form()
form.add(field.String(name="first_name"))
form.first_name.required = True
form.add(field.Integer(name="age"))
form.add(field.Date(name="dob"))
form.add(field.Email(name="email)) # this extends String
form.set_layout(layout.TwoColumnLayout()) # or form.set(layout.TwoColumnLayout(['age', 'date', 'first_name']) to change display order.
form.render()

#auto creation
form = helper.create_form(Person)
form.age.validator.set(required=True, min_value=18) # add extra validation no defined in metadata
form.render()

#validation
form.first_name.value = None # exception InvalidValue
params = {"first_name": "John", "age": "18", "dob": "24-12-1990"}
form.process(params) # validation okay all fields are converted to the required python type based on field validation.

#saving
person = Person()
helper.load_object(form, person)
objectstore.commit()

Huy
- Ben


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to