def validate_required_iff(**kwargs):
 def _validator(form, field):
  all_conditions_met = True
  for (key, value) in kwargs.iteritems():
   if (getattr(form, key).data != value):
    all_conditions_met = False
  if all_conditions_met:
   if ((field.data is None) or (isinstance(field.data, (str, unicode)) and (not field.data.strip())) or (isinstance(field.data, FileStorage) and (not field.data.filename.strip()))):
    raise validators.ValidationError('This field is required.')
  else:
   field.errors[:] = []
   raise validators.StopValidation()
 return _validator

def validate_required_iff ( ** kwargs ) : def _validator ( form , field ) : all_conditions_met = True for ( key , value ) in kwargs . iteritems ( ) : if ( getattr ( form , key ) . data != value ) : all_conditions_met = False if all_conditions_met : if ( ( field . data is None ) or ( isinstance ( field . data , ( str , unicode ) ) and ( not field . data . strip ( ) ) ) or ( isinstance ( field . data , FileStorage ) and ( not field . data . filename . strip ( ) ) ) ) : raise validators . ValidationError ( 'This field is required.' ) else : field . errors [ : ] = [ ] raise validators . StopValidation ( ) return _validator
used as a validator within a wtforms .