How can I have optional, or vairable buttons in a sqlform.smartgrid 'links' ?

28 views
Skip to first unread message

Gary Cowell

unread,
Jan 13, 2015, 10:30:27 AM1/13/15
to web...@googlegroups.com
I have a smartgrid, thus:

    grid = SQLFORM.smartgrid(db.exsystem,linked_tables=['exsystem', 'disks'],
                             user_signature=False,
                             deletable=False,
        links = [
            lambda row:
                 A(
                SPAN(_class='icon play icon-play glyphicon glyphicon-play')
                   ,'Start'
                    ,_class='button btn btn-success',_title='Start'
                ,_href=URL(args=["exsystem/start", db.exsystem, row.id])
                ),
            lambda row:
                 A(
                SPAN(_class='icon stop icon-stop glyphicon glyphicon-stop')
                   ,'Stop'
                    ,_class='button btn btn-warning',_title='Stop'
                ,_href=URL(args=["exsystem/stop", db.exsystem, row.id])
                ),
            lambda row:
                 A(
                SPAN(_class='icon trash icon-trash glyphicon glyphicon-bin')
                   ,'Delete'
                    ,_class='button btn btn-danger',_title='Delete'
                ,_href=URL(args=["exsystem/delete", db.exsystem, row.id])
                )
            ]
    )


So this displays coloured buttons for stop, start, and delete.

Ideally, I'd like the stop button to be suppressed if the entity in question is already stopped (based on db.exsystem.system_status)

Or, the button function and URL and type could be changed, depending on system status

I don't like having button for 'stop' on a thing which is already 'stopped'

These are controls for a virtual machine manager page.

How can I do this please?

Niphlod

unread,
Jan 14, 2015, 2:49:36 PM1/14/15
to web...@googlegroups.com
easy-peasy...

given "myfunc(row)" something that returns True only if the button needs to be generated.....

lambda row: myfunc(row) and themarkup_to_generate_the_button or ''

Reply all
Reply to author
Forward
0 new messages