refactored backward compatibility on formstyles to use try except instead of inspecting arguments, should make the new style faster as it never raises the exception
This commit is contained in:
+7
-9
@@ -35,7 +35,6 @@ import re
|
|||||||
import cStringIO
|
import cStringIO
|
||||||
from gluon.globals import current
|
from gluon.globals import current
|
||||||
from gluon.http import redirect
|
from gluon.http import redirect
|
||||||
from gluon.utils import get_callable_argspec
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import gluon.settings as settings
|
import gluon.settings as settings
|
||||||
@@ -1288,9 +1287,13 @@ class SQLFORM(FORM):
|
|||||||
raise RuntimeError('formstyle not found')
|
raise RuntimeError('formstyle not found')
|
||||||
|
|
||||||
if callable(formstyle):
|
if callable(formstyle):
|
||||||
# backward compatibility, 4 argument function is the old style
|
try:
|
||||||
args, varargs, keywords, defaults = get_callable_argspec(formstyle)
|
table = formstyle(self, xfields)
|
||||||
if defaults and len(args) - len(defaults) == 4 or len(args) == 4:
|
for id, a, b, c in xfields:
|
||||||
|
self.field_parent[id] = getattr(b, 'parent', None) \
|
||||||
|
if isinstance(b, XmlComponent) else None
|
||||||
|
except TypeError:
|
||||||
|
# backward compatibility, 4 argument function is the old style
|
||||||
table = TABLE()
|
table = TABLE()
|
||||||
for id, a, b, c in xfields:
|
for id, a, b, c in xfields:
|
||||||
newrows = formstyle(id, a, b, c)
|
newrows = formstyle(id, a, b, c)
|
||||||
@@ -1300,11 +1303,6 @@ class SQLFORM(FORM):
|
|||||||
newrows = [newrows]
|
newrows = [newrows]
|
||||||
for newrow in newrows:
|
for newrow in newrows:
|
||||||
table.append(newrow)
|
table.append(newrow)
|
||||||
else:
|
|
||||||
table = formstyle(self, xfields)
|
|
||||||
for id, a, b, c in xfields:
|
|
||||||
self.field_parent[id] = getattr(b, 'parent', None) \
|
|
||||||
if isinstance(b, XmlComponent) else None
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('formstyle not supported')
|
raise RuntimeError('formstyle not supported')
|
||||||
return table
|
return table
|
||||||
|
|||||||
Reference in New Issue
Block a user