fixed a problem with extra fields and better validation errors
This commit is contained in:
@@ -9,9 +9,6 @@
|
||||
## - api is an example of Hypermedia API support and access control
|
||||
#########################################################################
|
||||
|
||||
def test():
|
||||
return locals()
|
||||
|
||||
def index():
|
||||
"""
|
||||
example action using the internationalization operator T and flash
|
||||
|
||||
@@ -50,7 +50,6 @@ service = Service()
|
||||
plugins = PluginManager()
|
||||
|
||||
## create all tables needed by auth if not custom tables
|
||||
auth.settings.extra_fields['auth_user'] = [Field('claims','list:string')]
|
||||
auth.define_tables(username=False, signature=False)
|
||||
|
||||
## configure email
|
||||
|
||||
@@ -246,7 +246,7 @@ except ImportError:
|
||||
simplejson = None
|
||||
|
||||
LOGGER = logging.getLogger("web2py.dal")
|
||||
DEFAULT = lambda: 0
|
||||
DEFAULT = lambda: None
|
||||
|
||||
GLOBAL_LOCKER = threading.RLock()
|
||||
THREAD_LOCAL = threading.local()
|
||||
@@ -10122,7 +10122,7 @@ class Field(Expression):
|
||||
self.custom_qualifier = custom_qualifier
|
||||
self.label = (label if label is not None else
|
||||
fieldname.replace('_', ' ').title())
|
||||
self.requires = requires if not requires in (None, DEFAULT) else []
|
||||
self.requires = requires if requires is not None else []
|
||||
self.map_none = map_none
|
||||
self._rname = rname
|
||||
|
||||
|
||||
@@ -1846,8 +1846,12 @@ class INPUT(DIV):
|
||||
if requires:
|
||||
if not isinstance(requires, (list, tuple)):
|
||||
requires = [requires]
|
||||
for validator in requires:
|
||||
(value, errors) = validator(value)
|
||||
for k,validator in enumerate(requires):
|
||||
try:
|
||||
(value, errors) = validator(value)
|
||||
except:
|
||||
msg = "Validation error, field:%s %s" % (name,validator)
|
||||
raise Exception(msg)
|
||||
if not errors is None:
|
||||
self.vars[name] = value
|
||||
self.errors[name] = errors
|
||||
|
||||
@@ -22,7 +22,8 @@ from gluon.html import FORM, INPUT, LABEL, OPTION, SELECT, COL, COLGROUP
|
||||
from gluon.html import TABLE, THEAD, TBODY, TR, TD, TH, STYLE
|
||||
from gluon.html import URL, truncate_string, FIELDSET
|
||||
from gluon.dal import DAL, Field, Table, Row, CALLABLETYPES, smart_query, \
|
||||
bar_encode, Reference, Expression, SQLCustomType
|
||||
bar_encode, Reference, Expression, SQLCustomType, sqlhtml_validators, \
|
||||
DEFAULT
|
||||
from gluon.storage import Storage
|
||||
from gluon.utils import md5_hash
|
||||
from gluon.validators import IS_EMPTY_OR, IS_NOT_EMPTY, IS_LIST_OF, IS_DATE, \
|
||||
@@ -1118,9 +1119,13 @@ class SQLFORM(FORM):
|
||||
extra_fields = extra_fields or []
|
||||
self.extra_fields = {}
|
||||
for extra_field in extra_fields:
|
||||
extra_field.tablename = '_extra'
|
||||
self.fields.append(extra_field.name)
|
||||
self.extra_fields[extra_field.name] = extra_field
|
||||
extra_field.db = table._db
|
||||
extra_field.table = table
|
||||
extra_field.tablename = table._tablename
|
||||
if extra_field.requires == DEFAULT:
|
||||
extra_field.requires = sqlhtml_validators(extra_field)
|
||||
|
||||
for fieldname in self.fields:
|
||||
if fieldname.find('.') >= 0:
|
||||
@@ -1186,7 +1191,7 @@ class SQLFORM(FORM):
|
||||
|
||||
if cond:
|
||||
|
||||
# ## if field.represent is available else
|
||||
# ## if field.re field.requires = sqlhtml_validators(field) field.requires = sqlhtml_validators(field)present is available else
|
||||
# ## ignore blob and preview uploaded images
|
||||
# ## format everything else
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ def getipaddrinfo(host):
|
||||
|
||||
def obj2dict(obj, processed=None):
|
||||
"""
|
||||
converts any objet into a dict, recursively
|
||||
converts any object into a dict, recursively
|
||||
"""
|
||||
processed = processed if not processed is None else set()
|
||||
if obj is None:
|
||||
|
||||
Reference in New Issue
Block a user