Merge pull request #857 from gi0baro/pickle-issues
Removed representation utils from `_default_validators` method
This commit is contained in:
@@ -27,17 +27,6 @@ def _default_validators(db, field):
|
|||||||
field_type, field_length = field.type, field.length
|
field_type, field_length = field.type, field.length
|
||||||
requires = []
|
requires = []
|
||||||
|
|
||||||
def ff(r, id):
|
|
||||||
row = r(id)
|
|
||||||
if not row:
|
|
||||||
return str(id)
|
|
||||||
elif hasattr(r, '_format') and isinstance(r._format, str):
|
|
||||||
return r._format % row
|
|
||||||
elif hasattr(r, '_format') and callable(r._format):
|
|
||||||
return r._format(row)
|
|
||||||
else:
|
|
||||||
return str(id)
|
|
||||||
|
|
||||||
if field_type in (('string', 'text', 'password')):
|
if field_type in (('string', 'text', 'password')):
|
||||||
requires.append(validators.IS_LENGTH(field_length))
|
requires.append(validators.IS_LENGTH(field_length))
|
||||||
elif field_type == 'json':
|
elif field_type == 'json':
|
||||||
@@ -60,11 +49,6 @@ def _default_validators(db, field):
|
|||||||
field_type.find('.') < 0 and \
|
field_type.find('.') < 0 and \
|
||||||
field_type[10:] in db.tables:
|
field_type[10:] in db.tables:
|
||||||
referenced = db[field_type[10:]]
|
referenced = db[field_type[10:]]
|
||||||
|
|
||||||
def repr_ref(id, row=None, r=referenced, f=ff):
|
|
||||||
return f(r, id)
|
|
||||||
|
|
||||||
field.represent = field.represent or repr_ref
|
|
||||||
if hasattr(referenced, '_format') and referenced._format:
|
if hasattr(referenced, '_format') and referenced._format:
|
||||||
requires = validators.IS_IN_DB(db, referenced._id,
|
requires = validators.IS_IN_DB(db, referenced._id,
|
||||||
referenced._format)
|
referenced._format)
|
||||||
@@ -77,24 +61,6 @@ def _default_validators(db, field):
|
|||||||
field_type.find('.') < 0 and \
|
field_type.find('.') < 0 and \
|
||||||
field_type[15:] in db.tables:
|
field_type[15:] in db.tables:
|
||||||
referenced = db[field_type[15:]]
|
referenced = db[field_type[15:]]
|
||||||
|
|
||||||
def list_ref_repr(ids, row=None, r=referenced, f=ff):
|
|
||||||
if not ids:
|
|
||||||
return None
|
|
||||||
from pydal.adapters import GoogleDatastoreAdapter
|
|
||||||
refs = None
|
|
||||||
db, id = r._db, r._id
|
|
||||||
if isinstance(db._adapter, GoogleDatastoreAdapter):
|
|
||||||
def count(values):
|
|
||||||
return db(id.belongs(values)).select(id)
|
|
||||||
rx = range(0, len(ids), 30)
|
|
||||||
refs = reduce(lambda a, b: a & b, [count(ids[i:i+30])
|
|
||||||
for i in rx])
|
|
||||||
else:
|
|
||||||
refs = db(id.belongs(ids)).select(id)
|
|
||||||
return (refs and ', '.join(f(r, x.id) for x in refs) or '')
|
|
||||||
|
|
||||||
field.represent = field.represent or list_ref_repr
|
|
||||||
if hasattr(referenced, '_format') and referenced._format:
|
if hasattr(referenced, '_format') and referenced._format:
|
||||||
requires = validators.IS_IN_DB(db, referenced._id,
|
requires = validators.IS_IN_DB(db, referenced._id,
|
||||||
referenced._format, multiple=True)
|
referenced._format, multiple=True)
|
||||||
@@ -106,12 +72,6 @@ def _default_validators(db, field):
|
|||||||
if not field.notnull:
|
if not field.notnull:
|
||||||
requires = validators.IS_EMPTY_OR(requires)
|
requires = validators.IS_EMPTY_OR(requires)
|
||||||
return requires
|
return requires
|
||||||
elif field_type.startswith('list:'):
|
|
||||||
def repr_list(values, row=None):
|
|
||||||
return', '.join(str(v) for v in (values or []))
|
|
||||||
|
|
||||||
field.represent = field.represent or repr_list
|
|
||||||
|
|
||||||
if field.unique:
|
if field.unique:
|
||||||
requires.append(validators.IS_NOT_IN_DB(db, field))
|
requires.append(validators.IS_NOT_IN_DB(db, field))
|
||||||
sff = ['in', 'do', 'da', 'ti', 'de', 'bo']
|
sff = ['in', 'do', 'da', 'ti', 'de', 'bo']
|
||||||
|
|||||||
Reference in New Issue
Block a user