From 773b19d37324c8bc4ba8923456d12e53e9385968 Mon Sep 17 00:00:00 2001 From: Oleg Date: Thu, 11 Jul 2013 18:11:37 +0200 Subject: [PATCH 1/2] allows add multiple submit buttons in "selectable" mode in SQLFORM.grid (with different decorate css classes) --- gluon/sqlhtml.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 166b60bb..791f4724 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -2413,13 +2413,38 @@ class SQLFORM(FORM): htmltable, _class='web2py_htmltable', _style='width:100%;overflow-x:auto;-ms-overflow-x:scroll') if selectable: - htmltable = FORM(htmltable, INPUT( - _type="submit", _value=T(selectable_submit_button))) + if not callable(selectable): + #now expect that selectable and related parameters are iterator (list, tuple, etc) + inputs = [] + for i, submit_info in enumerate(selectable): + submit_text = submit_info[0] + submit_class = submit_info[2] if len(submit_info) > 2 else '' + + input_ctrl = INPUT(_type="submit", _name='submit_%d' % i, _value=T(submit_text)) + input_ctrl.add_class(submit_class) + inputs.append(input_ctrl) + else: + inputs = [INPUT(_type="submit", _value=T(selectable_submit_button))] + + if formstyle == 'bootstrap': + # add space between buttons + #inputs = sum([[inp, ' '] for inp in inputs], [])[:-1] + htmltable = FORM(htmltable, DIV(*inputs, _class='form-actions')) + else: + htmltable = FORM(htmltable, *inputs) + if htmltable.process(formname=formname).accepted: htmltable.vars.records = htmltable.vars.records or [] htmltable.vars.records = htmltable.vars.records if type(htmltable.vars.records) == list else [htmltable.vars.records] records = [int(r) for r in htmltable.vars.records] - selectable(records) + if not callable(selectable): + for i, submit_info in enumerate(selectable): + submit_callback = submit_info[1] + if htmltable.vars.get('submit_%d' % i, False): + submit_callback(records) + break + else: + selectable(records) redirect(referrer) else: htmltable = DIV(T('No records found')) From 59f8362f75e09a7307947ebff2a3c33c968cfaf6 Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 14 Jul 2013 11:32:40 +0200 Subject: [PATCH 2/2] syntax fix for python 2.5 --- gluon/sqlhtml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 791f4724..dc50c6fa 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -2429,7 +2429,7 @@ class SQLFORM(FORM): if formstyle == 'bootstrap': # add space between buttons #inputs = sum([[inp, ' '] for inp in inputs], [])[:-1] - htmltable = FORM(htmltable, DIV(*inputs, _class='form-actions')) + htmltable = FORM(htmltable, DIV(_class='form-actions', *inputs)) else: htmltable = FORM(htmltable, *inputs)