This commit is contained in:
Leonel Câmara
2017-06-05 23:52:25 +01:00
parent 7769917102
commit 617ca4a98d
2 changed files with 7 additions and 2 deletions
+5
View File
@@ -235,6 +235,11 @@ class TestValidators(unittest.TestCase):
self.assertEqual(sorted(rtn), [('%d' % george_id, 'george'), ('%d' % costanza_id, 'costanza')])
rtn = IS_IN_DB(db, db.person.id, db.person.name, error_message='oops', sort=True).options(zero=True)
self.assertEqual(rtn, [('', ''), ('%d' % costanza_id, 'costanza'), ('%d' % george_id, 'george')])
# Test None
rtn = IS_IN_DB(db, 'person.id', '%(name)s', error_message='oops')(None)
self.assertEqual(rtn, (None, 'oops'))
rtn = IS_IN_DB(db, 'person.name', '%(name)s', error_message='oops')(None)
self.assertEqual(rtn, (None, 'oops'))
# Test using the set it made for options
vldtr = IS_IN_DB(db, 'person.name', '%(name)s', error_message='oops')
vldtr.options()
+2 -2
View File
@@ -21,7 +21,7 @@ import urllib
import struct
import decimal
import unicodedata
from gluon._compat import StringIO, long, basestring, unicodeT, to_unicode, urllib_unquote, unichr, to_bytes, PY2, to_unicode, to_native
from gluon._compat import StringIO, long, basestring, unicodeT, to_unicode, urllib_unquote, unichr, to_bytes, PY2, to_unicode, to_native, string_types
from gluon.utils import simple_hash, web2py_uuid, DIGEST_ALG_BY_SIZE
from pydal.objects import Field, FieldVirtual, FieldMethod
from functools import reduce
@@ -659,7 +659,7 @@ class IS_IN_DB(Validator):
return (values, None)
else:
if field.type in ('id', 'integer'):
if isinstance(value, (int, long)) or value.isdigit():
if isinstance(value, (int, long)) or (isinstance(value, string_types) and value.isdigit()):
value = int(value)
elif self.auto_add:
value = self.maybe_add(table, self.fieldnames[0], value)