possible solution to issue 1154, onvalidation = dict(onsuccess= [...])
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.2.1 (2012-11-14 08:44:05) stable
|
Version 2.2.1 (2012-11-14 13:47:50) stable
|
||||||
|
|||||||
+12
-7
@@ -129,6 +129,11 @@ def xmlescape(data, quote=True):
|
|||||||
data = cgi.escape(data, quote).replace("'", "'")
|
data = cgi.escape(data, quote).replace("'", "'")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def call_as_list(f,*a,**b):
|
||||||
|
if not isinstance(f, (list,tuple)):
|
||||||
|
f = [f]
|
||||||
|
for item in f:
|
||||||
|
item(*a,**b)
|
||||||
|
|
||||||
def truncate_string(text, length, dots='...'):
|
def truncate_string(text, length, dots='...'):
|
||||||
text = text.decode('utf-8')
|
text = text.decode('utf-8')
|
||||||
@@ -1998,20 +2003,20 @@ class FORM(DIV):
|
|||||||
onsuccess = onvalidation.get('onsuccess', None)
|
onsuccess = onvalidation.get('onsuccess', None)
|
||||||
onfailure = onvalidation.get('onfailure', None)
|
onfailure = onvalidation.get('onfailure', None)
|
||||||
onchange = onvalidation.get('onchange', None)
|
onchange = onvalidation.get('onchange', None)
|
||||||
|
if [k for k in onvalidation if not k in (
|
||||||
|
'onsuccess','onfailure','onchange')]:
|
||||||
|
raise RuntimeError('Invalid key in onvalidate dict')
|
||||||
if onsuccess and status:
|
if onsuccess and status:
|
||||||
onsuccess(self)
|
call_as_list(onsuccess,self)
|
||||||
if onfailure and request_vars and not status:
|
if onfailure and request_vars and not status:
|
||||||
onfailure(self)
|
call_as_list(onfailure,self)
|
||||||
status = len(self.errors) == 0
|
status = len(self.errors) == 0
|
||||||
if changed:
|
if changed:
|
||||||
if onchange and self.record_changed and \
|
if onchange and self.record_changed and \
|
||||||
self.detect_record_change:
|
self.detect_record_change:
|
||||||
onchange(self)
|
call_as_list(onchange,self)
|
||||||
elif status:
|
elif status:
|
||||||
if isinstance(onvalidation, (list, tuple)):
|
call_as_list(onvalidation, self)
|
||||||
[f(self) for f in onvalidation]
|
|
||||||
else:
|
|
||||||
onvalidation(self)
|
|
||||||
if self.errors:
|
if self.errors:
|
||||||
status = False
|
status = False
|
||||||
if not session is None:
|
if not session is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user