How should the interaction between the deform Form object and the DB
backend be modeled? I have a schema that represents a user with at its
most simple contains a email and password field.
class User(colander.MappingSchema):
""""""
email = colander.SchemaNode(
colander.String(),
validator = colander.Email()
)
password = colander.SchemaNode(
colander.String(),
missing=colander.null,
widget=widget.CheckedPasswordWidget()
)
form = Form( UserSchema() )
try:
data = form.validate( controls )
create_record( data )
except ValidationFailure, e:
return {'form' : e.render()}
Of course the second stage of the validation is to try to insert this
user into my database (I'm using MongoDB, but the problem is the same
for any backend store). The insert will fail if the email address is
not unique, but I won't know until I actually try to insert the record
in the database.
How would I bubble up an error in the insertion code so I can raise
the correct error in the form and display an error on the email field
saying user "email@address" already exists?
I know I can (theoretically) have a deferred validator on the email
field, but that would mean doing two (or more) database roundtrips,
and I could still have race conditions between checking that the field
is valid and actually inserting the record in the database.
Is there a way to have a single top-level validation callback? maybe a
validator on the entire schema? unless there is a way to raise an
exception that would allow me to use that part of the code that re-
renders the form with all of the existing user inputs already filled
in.
oO
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.