first commit

This commit is contained in:
Senad Uka
2017-11-07 09:23:57 +01:00
commit 0eee92660a
356 changed files with 747259 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
from wtforms.validators import Optional
class ConditionalValidator(object):
def __init__(self, other_field_name, other_data_contents, dependent_validator):
self.other_field_name = other_field_name
self.other_data_contents = other_data_contents
self.dependent_validator = dependent_validator
def __call__(self, form, field):
other_field = form._fields.get(self.other_field_name)
if other_field is None:
raise Exception('no field named "%s" in form' % self.other_field_name)
if other_field.data in self.other_data_contents:
self.dependent_validator.__call__(form, field)
else:
Optional().__call__(form, field)