Add 'newstyle' behavior for Form.validate()
This commit is contained in:
parent
c35bfa3e4e
commit
035a7b2096
|
@ -789,13 +789,28 @@ class Form(object):
|
|||
return getattr(record, field_name, None)
|
||||
|
||||
def validate(self, *args, **kwargs):
|
||||
raise_error = kwargs.pop('raise_error', True)
|
||||
form = self.make_deform_form()
|
||||
try:
|
||||
return form.validate(*args, **kwargs)
|
||||
except deform.ValidationFailure:
|
||||
if raise_error:
|
||||
raise
|
||||
if kwargs.pop('newstyle', False):
|
||||
# yay, new behavior!
|
||||
if hasattr(self, 'validated'):
|
||||
del self.validated
|
||||
if self.request.method != 'POST':
|
||||
return False
|
||||
controls = self.request.POST.items()
|
||||
dform = self.make_deform_form()
|
||||
try:
|
||||
self.validated = dform.validate(controls)
|
||||
return True
|
||||
except deform.ValidationFailure:
|
||||
return False
|
||||
|
||||
else: # legacy behavior
|
||||
raise_error = kwargs.pop('raise_error', True)
|
||||
form = self.make_deform_form()
|
||||
try:
|
||||
return form.validate(*args, **kwargs)
|
||||
except deform.ValidationFailure:
|
||||
if raise_error:
|
||||
raise
|
||||
|
||||
|
||||
class FieldList(list):
|
||||
|
|
Loading…
Reference in a new issue