Hello

I have a SQLFORM.grid, where I wanted some buttons to do different things, 
and to look different based on the status of the entities being reported in 
the grid.

Here's what I did for one of them:
     links = [            
            dict(header=T('Running'),body=lambda row: testslot(row.
currentslot)),
            dict(header=T('Control'),body=
            lambda row:
                A(
                SPAN(_class=syss.iconClass[row.currentslot])
                   ,syss.text[row.currentslot]
                   ,_class=syss.buttonClass[row.currentslot]
                   ,_title=syss.text[row.currentslot]
                   ,_href=URL("dynamic","startstop",
              args=[row.id,syss.url[row.currentslot], syss.text[row.
currentslot], db.e5system, row.currentslot])
                )
            ),

So the button can look red or orange, or green, because I populate some 
lists and use the values , 
syss.text is the text for the button
syss.buttonClass is the class to be used and so on. I call this at the 
start:

    syss=listeningSystems()
    syss.refresh()

My syss object then has these instance lists I can use to get the statuses 
of my rows. It ends up looking like:



So that's great, I get a start button for stopped systems, and a stop 
button for started ones.

Problem seems to me though, it's not very scalable or readable.

Is there a better way for me to do this? To make a decision, on my next 
button, it needs the 'id' from the table, and make some decisions.

Ideally, I'd like something similar to this:

            dict(header=T('State'),body=
            lambda row:
                A(
                SPAN(_class="icon stop icon-stop glyphicon glyphicon-stop")
                  fixstatus(row.id)
                )
            )


where the systemStatus() def would fill in the middle bit, but I can't get 
that to work:

def fixstatus(sys):
    return ',"Unfinished",_class="button btn btn-warning",_title="Unf 
Title",_href=URL("dynamic","systemStatus",args={0})'.format(sys)

Could I return the whole thing from A( to close ) from a function?

I tried that, but I just got a table cell with the actual text 
A(SPAN(_class etc ... ) in it.

Am I expecting too much from the grid?

I like how it looks with the button I have coded right now, but it does 
seem unwieldy, there must be a better way!

Thanks group

p.s. Just a thanks to web2py developers, this is a top product, really 
enjoying working with it.


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to