Hello,

maybe a chained validator could help you.
Something like this:

class OldPasswordValidator (FancyValidator):

    def __init__(self, sqlmodel,  sql_password_name, form_pw_name,
form_id_name = 'id'):
        self.sqlmodel = sqlmodel
        self.password_field = getattr(sqlmodel.q, sql_password_name)
        self.old_pw_name = form_pw_name
        self.id_name = form_id_name

    def validate_python(self, field_dict, state):
        if self.sqlmodel.select (AND(
                self.sqlmodel.q.id == field_dict[self.id_name],
                self.password_field  ==
field_dict[self.old_pw_name])).count() == 0:
            raise Invalid ('',
                field_dict,
                state,
                error_dict = {self.field_name : 'Old password doesn't
match!'}
            )

usage:
class MySchema (Schema):
    [...]
    chained_validators = [OldPasswordValidator(model.User, 'password',
'old_password',)

I havn't tried it, so it may be buggy.

Gergo_


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to