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
|
## - api is an example of Hypermedia API support and access control
|
||||||
#########################################################################
|
#########################################################################
|
||||||
|
|
||||||
def test():
|
|
||||||
return locals()
|
|
||||||
|
|
||||||
def index():
|
def index():
|
||||||
"""
|
"""
|
||||||
example action using the internationalization operator T and flash
|
example action using the internationalization operator T and flash
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ service = Service()
|
|||||||
plugins = PluginManager()
|
plugins = PluginManager()
|
||||||
|
|
||||||
## create all tables needed by auth if not custom tables
|
## 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)
|
auth.define_tables(username=False, signature=False)
|
||||||
|
|
||||||
## configure email
|
## configure email
|
||||||
|
|||||||
+2
-2
@@ -246,7 +246,7 @@ except ImportError:
|
|||||||
simplejson = None
|
simplejson = None
|
||||||
|
|
||||||
LOGGER = logging.getLogger("web2py.dal")
|
LOGGER = logging.getLogger("web2py.dal")
|
||||||
DEFAULT = lambda: 0
|
DEFAULT = lambda: None
|
||||||
|
|
||||||
GLOBAL_LOCKER = threading.RLock()
|
GLOBAL_LOCKER = threading.RLock()
|
||||||
THREAD_LOCAL = threading.local()
|
THREAD_LOCAL = threading.local()
|
||||||
@@ -10122,7 +10122,7 @@ class Field(Expression):
|
|||||||
self.custom_qualifier = custom_qualifier
|
self.custom_qualifier = custom_qualifier
|
||||||
self.label = (label if label is not None else
|
self.label = (label if label is not None else
|
||||||
fieldname.replace('_', ' ').title())
|
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.map_none = map_none
|
||||||
self._rname = rname
|
self._rname = rname
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -1846,8 +1846,12 @@ class INPUT(DIV):
|
|||||||
if requires:
|
if requires:
|
||||||
if not isinstance(requires, (list, tuple)):
|
if not isinstance(requires, (list, tuple)):
|
||||||
requires = [requires]
|
requires = [requires]
|
||||||
for validator in requires:
|
for k,validator in enumerate(requires):
|
||||||
(value, errors) = validator(value)
|
try:
|
||||||
|
(value, errors) = validator(value)
|
||||||
|
except:
|
||||||
|
msg = "Validation error, field:%s %s" % (name,validator)
|
||||||
|
raise Exception(msg)
|
||||||
if not errors is None:
|
if not errors is None:
|
||||||
self.vars[name] = value
|
self.vars[name] = value
|
||||||
self.errors[name] = errors
|
self.errors[name] = errors
|
||||||
|
|||||||
+8
-3
@@ -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 TABLE, THEAD, TBODY, TR, TD, TH, STYLE
|
||||||
from gluon.html import URL, truncate_string, FIELDSET
|
from gluon.html import URL, truncate_string, FIELDSET
|
||||||
from gluon.dal import DAL, Field, Table, Row, CALLABLETYPES, smart_query, \
|
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.storage import Storage
|
||||||
from gluon.utils import md5_hash
|
from gluon.utils import md5_hash
|
||||||
from gluon.validators import IS_EMPTY_OR, IS_NOT_EMPTY, IS_LIST_OF, IS_DATE, \
|
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 []
|
extra_fields = extra_fields or []
|
||||||
self.extra_fields = {}
|
self.extra_fields = {}
|
||||||
for extra_field in extra_fields:
|
for extra_field in extra_fields:
|
||||||
extra_field.tablename = '_extra'
|
|
||||||
self.fields.append(extra_field.name)
|
self.fields.append(extra_field.name)
|
||||||
self.extra_fields[extra_field.name] = extra_field
|
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:
|
for fieldname in self.fields:
|
||||||
if fieldname.find('.') >= 0:
|
if fieldname.find('.') >= 0:
|
||||||
@@ -1186,7 +1191,7 @@ class SQLFORM(FORM):
|
|||||||
|
|
||||||
if cond:
|
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
|
# ## ignore blob and preview uploaded images
|
||||||
# ## format everything else
|
# ## format everything else
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -354,7 +354,7 @@ def getipaddrinfo(host):
|
|||||||
|
|
||||||
def obj2dict(obj, processed=None):
|
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()
|
processed = processed if not processed is None else set()
|
||||||
if obj is None:
|
if obj is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user