From bd44a42c890930903449aadce8e321a5c1e82f2e Mon Sep 17 00:00:00 2001 From: mdipierro Date: Mon, 28 Jul 2014 23:29:26 -0500 Subject: [PATCH] =?UTF-8?q?allow=20arbistrary=20params=20to=20formstyle=3D?= =?UTF-8?q?style(placeholder=3DTrue,=20errors=3D'down'),=20thanks=20Andr?= =?UTF-8?q?=C3=A9=20Kablu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VERSION | 2 +- gluon/sqlhtml.py | 5 +++-- gluon/utils.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index a2814742..8ae28d40 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.9.5-trunk+timestamp.2014.07.28.00.20.49 +Version 2.9.5-trunk+timestamp.2014.07.28.23.28.19 diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 9f106bde..62e53507 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -35,7 +35,7 @@ import re import cStringIO from gluon.globals import current from gluon.http import redirect -import inspect +from gluon.utils import get_callable_argspec try: import gluon.settings as settings @@ -1278,6 +1278,7 @@ class SQLFORM(FORM): table = self.createform(xfields) self.components = [table] + def createform(self, xfields): formstyle = self.formstyle if isinstance(formstyle, basestring): @@ -1288,7 +1289,7 @@ class SQLFORM(FORM): if callable(formstyle): # backward compatibility, 4 argument function is the old style - args, varargs, keywords, defaults = inspect.getargspec(formstyle) + args, varargs, keywords, defaults = get_callable_argspec(formstyle) if defaults and len(args) - len(defaults) == 4 or len(args) == 4: table = TABLE() for id, a, b, c in xfields: diff --git a/gluon/utils.py b/gluon/utils.py index 83d97cb0..c4d57bc6 100644 --- a/gluon/utils.py +++ b/gluon/utils.py @@ -14,6 +14,7 @@ import threading import struct import uuid import random +import inspect import time import os import re @@ -132,6 +133,16 @@ DIGEST_ALG_BY_SIZE = { 512 / 4: 'sha512', } +def get_callable_argspec(fn): + if inspect.isfunction(fn) or inspect.ismethod(fn): + inspectable = fn + elif inspect.isclass(fn): + inspectable = fn.__init__ + elif hasattr(fn, '__call__'): + inspectable = fn.__call__ + else: + inspectable = fn + return inspect.getargspec(inspectable) def pad(s, n=32, padchar=' '): return s + (32 - len(s) % 32) * padchar