Add 'newstyle' behavior for Form.validate()

This commit is contained in:
Lance Edgar 2018-02-09 15:03:44 -06:00
parent c35bfa3e4e
commit 035a7b2096

View file

@ -789,13 +789,28 @@ class Form(object):
return getattr(record, field_name, None) return getattr(record, field_name, None)
def validate(self, *args, **kwargs): def validate(self, *args, **kwargs):
raise_error = kwargs.pop('raise_error', True) if kwargs.pop('newstyle', False):
form = self.make_deform_form() # yay, new behavior!
try: if hasattr(self, 'validated'):
return form.validate(*args, **kwargs) del self.validated
except deform.ValidationFailure: if self.request.method != 'POST':
if raise_error: return False
raise 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): class FieldList(list):