models:
class PwdSchema(Schema):
oldpassword = validators.String(not_empty=True)
password = validators.String(not_empty=True)
passwordverify = validators.String(not_empty=True)
chained_validators = [validators.FieldsMatch('password',
'passwordverify')]
class password_form(TableForm):
class fields(WidgetsList):
oldpassword = PasswordField(validator=NotEmpty)
password = PasswordField(validator=NotEmpty)
passwordverify = PasswordField(validator=NotEmpty)
change_password_form = password_form('change_password_form',
action='passwordsave')
controller:
@validate(change_password_form, error_handler=password)
def passwordsave(self, oldpassword, password, passwordverify):
flash("Password updated")
redirect('password')
When I do this, and leave any of the password fields empty, I get
'Please enter a value' on the respective fields.
If I change the controller to:
@validate(validators = PwdSchema())
def passwordsave(self, oldpassword, password, passwordverify):
if pylons.c.form_errors:
flash("error", status="status_warning")
else:
flash("Password updated")
redirect('password')
I lose the 'Please enter a value' error messages, and am handed the
flash message when pylons..form_errors is raised.
If I detect an error, how can I send the error through to the form so
that the forms act like the errors messages from the @validate
(change_password_form, error_handler=password) decorator? I have
looked through the code and tests, but, I don't see why this
validators= raises errors differently than validator=. I tried
chaining the validate decorators, but, that doesn't appear to work
either.
The flow that I am trying to accomplish is:
check the value in oldpassword against the table, making sure that it
does match the existing hash
check the value of password and passwordverify to make sure they match
If both validations pass, update the table with the new password hash.
However, I want to the user to experience the same error messages
consistent with the rest of the application rather than communicating
the error condition through flash messages.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---