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,6 +789,21 @@ 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):
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) raise_error = kwargs.pop('raise_error', True)
form = self.make_deform_form() form = self.make_deform_form()
try: try: