Permalink
Browse files

Conform with formencode. Fixes #28.

  • Loading branch information...
ralphbean committed Jun 15, 2012
1 parent bb006df commit f3bf2a821e1f9f7730e8ea8441918d063d1a5025
Showing with 19 additions and 19 deletions.
  1. +2 −2 tests/test_validation.py
  2. +3 −3 tests/test_widgets.py
  3. +14 −14 tw2/core/validation.py
@@ -103,7 +103,7 @@ def test_compound_validation(self):
"""
class NeverValid(Validator):
msgs = {"never": "this is never valid"}
def to_python(self, value):
def to_python(self, value, state=None):
raise ValidationError("never", self)
class FailWidget(twc.CompoundWidget):
@@ -199,7 +199,7 @@ class B(A):
def test_prepare_validate(self):
class MyValidator(twc.Validator):
def from_python(self, value):
def from_python(self, value, state=None):
return value.upper()
test = twc.Widget(id='a', template='b', validator=MyValidator()).req()
testapi.request(1)
@@ -371,7 +371,7 @@ def __init__(self, msg):
err_msg = "NO"
class MockValidator(vd.Validator):
def from_python(self, value):
def from_python(self, value, state=None):
raise vd.Invalid(err_msg)
class T(wd.Widget):
@@ -546,7 +546,7 @@ class T(wd.RepeatingWidget):
def testValidator(self):
class V(vd.Validator):
def to_python(self, data):
def to_python(self, data, state=None):
self._called = True
class T(wd.RepeatingWidget):
child = wd.Widget()
@@ -591,7 +591,7 @@ def testChildError(self):
err = vd.ValidationError("Failed")
class V(vd.Validator):
def to_python(self, value):
def to_python(self, value, state=None):
raise err
class C(wd.Widget):
@@ -73,9 +73,9 @@ def message(self):
return self.msg
def safe_validate(validator, value):
def safe_validate(validator, value, state=None):
try:
value = validator.to_python(value)
value = validator.to_python(value, state=None)
validator.validate_python(value)
return value
except ValidationError:
@@ -189,7 +189,7 @@ def __init__(self, **kw):
for k in kw:
setattr(self, k, kw[k])
def to_python(self, value):
def to_python(self, value, state=None):
if self.required and value is None:
raise ValidationError('required', self)
if isinstance(value, basestring) and self.strip:
@@ -200,7 +200,7 @@ def validate_python(self, value, state=None):
if self.required and not value:
raise ValidationError('required', self)
def from_python(self, value):
def from_python(self, value, state=None):
return value
def __repr__(self):
@@ -220,7 +220,7 @@ class BlankValidator(Validator):
Always returns EmptyField. This is the default for hidden fields,
so their values are not included in validated data.
"""
def to_python(self, value):
def to_python(self, value, state=None):
return EmptyField
@@ -311,8 +311,8 @@ class IntValidator(RangeValidator):
'notint': _('Must be an integer'),
}
def to_python(self, value):
value = super(IntValidator, self).to_python(value)
def to_python(self, value, state=None):
value = super(IntValidator, self).to_python(value, state)
try:
if value is None or str(value) == '':
return None
@@ -330,7 +330,7 @@ def validate_python(self, value, state=None):
if self.max and value > self.max:
raise ValidationError('toobig', self)
def from_python(self, value):
def from_python(self, value, state=None):
if value is None:
return None
else:
@@ -346,8 +346,8 @@ class BoolValidator(RangeValidator):
'required': ('bool_required', _('You must select this'))
}
def to_python(self, value):
value = super(BoolValidator, self).to_python(value)
def to_python(self, value, state=None):
value = super(BoolValidator, self).to_python(value, state)
return str(value).lower() in ('on', 'yes', 'true', '1')
@@ -410,8 +410,8 @@ def min_str(self):
def max_str(self):
return self.max.strftime(self.format)
def to_python(self, value):
value = super(DateValidator, self).to_python(value)
def to_python(self, value, state=None):
value = super(DateValidator, self).to_python(value, state)
if not value:
return None
try:
@@ -425,7 +425,7 @@ def validate_python(self, value, state=None):
if self.required and not value:
raise ValidationError('required', self)
def from_python(self, value):
def from_python(self, value, state=None):
return value and value.strftime(self.format) or ''
@@ -440,7 +440,7 @@ class DateTimeValidator(DateValidator):
}
format = '%d/%m/%Y %H:%M'
def to_python(self, value):
def to_python(self, value, state=None):
if not value:
return None
try:

0 comments on commit f3bf2a8

Please sign in to comment.