Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mkesicki committed Apr 30, 2017
1 parent a7dd767 commit ff08553
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 17 additions & 16 deletions excel_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ def isValid(settings, value, coordinate, errors, value2 = None):
}

violations = []
for data in settings:
for name in data:
validator = classmap[name](data[name])
type = settings.keys()[0]
data = settings.values()[0]
validator = classmap[type](data)

if name != 'Conditional':
result = validator.validate(value)
else:
result = validator.validate(value, value2)
if type != 'Conditional':
result = validator.validate(value)
else:
result = validator.validate(value, value2)

if (result == False):
violations.append(validator.getMessage())
if (result == False):
violations.append(validator.getMessage())

if len(violations) > 0:
errors.append((coordinate, violations))
Expand Down Expand Up @@ -184,13 +184,14 @@ def validate(settings, excelFile, sheetName, tmpDir, printErrors = False):
coordinates = "%s%d" % (column, rowCounter)

if column in settings['validators']:
name = settings['validators'][column][0].keys()[0]
if name != 'Conditional':
isValid(settings['validators'][column], value, coordinates, errors)
else:
fieldB = settings['validators'][column][0]['Conditional']['fieldB']
value2 = ws.cell(fieldB + str(rowCounter)).value
isValid(settings['validators'][column], value, coordinates, errors, value2)
for type in settings['validators'][column]:
name = type.keys()[0]
if name != 'Conditional':
isValid(type, value, coordinates, errors)
else:
fieldB = type.values()[0]['fieldB']
value2 = ws.cell(fieldB + str(rowCounter)).value
isValid(type, value, coordinates, errors, value2)

elif settings['defaultValidator'] != None:
isValid(settings['defaultValidator'], value, coordinates, errors)
Expand Down
2 changes: 1 addition & 1 deletion validator/ConditionalValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
class ConditionalValidator(BaseValidator.BaseValidator):

operator = None #should be a lambda expression which return boolean variable
fieldB = None
message = "This value is not valid"

def validate(self, fieldA, fieldB):

fieldA = super(ConditionalValidator, self).validate(fieldA)
fieldB = super(ConditionalValidator, self).validate(fieldB)

return self.operator(fieldA, fieldB)

def __init__(self, params):
Expand Down

0 comments on commit ff08553

Please sign in to comment.