Andrea Riciputi
2009-04-19 21:26:06 UTC
Hi all,
I've noticed that a chained validator with validate_partial_form=True
is called twice. The first time its .validate_partial() method is
called (which in turn calls .validate_python()),
then .validate_python() is called directly.
The problem is that the second time the input has been already
converted and the validators could fails (e.g. if the input string has
been converted into a datetime object).
Probably I haven't understood how to get this kind of validators to
work properly. I usually define them like this:
class Foo(FancyValidator):
validate_partial_form = True
messages = {
'message_key' : u"the message"
}
def validate_partial(self, values, state):
self.validate_python(values, state)
def validate_python(self, values, state):
...actual validating code here...
...raise Invalid in case...
Can anyone explain me why I get this wrong?
TIA,
Andrea
I've noticed that a chained validator with validate_partial_form=True
is called twice. The first time its .validate_partial() method is
called (which in turn calls .validate_python()),
then .validate_python() is called directly.
The problem is that the second time the input has been already
converted and the validators could fails (e.g. if the input string has
been converted into a datetime object).
Probably I haven't understood how to get this kind of validators to
work properly. I usually define them like this:
class Foo(FancyValidator):
validate_partial_form = True
messages = {
'message_key' : u"the message"
}
def validate_partial(self, values, state):
self.validate_python(values, state)
def validate_python(self, values, state):
...actual validating code here...
...raise Invalid in case...
Can anyone explain me why I get this wrong?
TIA,
Andrea