Skip to content

Commit

Permalink
Fix IntegerField and FloatField validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrAndSE committed Jun 17, 2012
1 parent 42d326a commit faf1ee4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lighty/db/fields.py
Expand Up @@ -133,7 +133,7 @@ class IntegerField(FieldDescriptor, NumericField):
def __init__(self, **options):
'''Create new field. Adds validator that checks is value passed integer
'''
options = add_validator(lighty.validators.IntegerValidator, options)
options = add_validator(lighty.validators.INTEGER_VALIDATOR, options)
super(IntegerField, self).__init__(**options)

def __set__(self, instance, value):
Expand Down Expand Up @@ -172,7 +172,7 @@ class FloatField(FieldDescriptor, NumericField):
def __init__(self, **options):
'''Create new field. Adds validator that checks is value passed integer
'''
options = add_validator(lighty.validators.FloatValidator, options)
options = add_validator(lighty.validators.FLOAT_VALIDATOR, options)
super(FloatField, self).__init__(**options)

def __set__(self, instance, value):
Expand Down
6 changes: 4 additions & 2 deletions lighty/validators.py
Expand Up @@ -165,7 +165,7 @@ def validate(self, url):
validate_comma_separated_integer_list = RegexValidator("^(([\d]+\,)*[\d]+)$")


class IntegerValidator(ValueError):
class IntegerValidator(Validator):
'''Check is value can be safelly converted to int
'''

Expand All @@ -176,9 +176,10 @@ def validate(self, value):
return self.error(value)
else:
return result
INTEGER_VALIDATOR = IntegerValidator()


class FloatValidator(ValueError):
class FloatValidator(Validator):
'''Check is value can be safelly converted to int
'''

Expand All @@ -189,6 +190,7 @@ def validate(self, value):
return self.error(value)
else:
return result
FLOAT_VALIDATOR = FloatValidator()


class MaxValueValidator(Validator):
Expand Down

0 comments on commit faf1ee4

Please sign in to comment.