there are multiple errors (and lots of unnecessary parenthesis).
first of all, define a single function to represent your value....
def represent_colored(value):
if value == 1:
return ...... <--green
elif value == 2:
....yellow
elif value == 3:
....red
else:
.....purple (just to spot occasional errors)
Then, apply the represent
db.table.field.represent = lambda row, value : represent_colored(value)
Then, show the grid, and it should work.
The grid doesn't "take" as rows your executesql statement (that returns a
resultset, not a query as intended), so those definitions you made don't
work as you expected.
On Monday, June 10, 2013 7:31:04 PM UTC+2, [email protected] wrote:
>
> Thanks for the reply, Niphlod.
>
> Now there was the following question:
>
> I add the following lines to the controller before the grid = SQLFORM.grid
> ...
>
> warn = db.executesql ('SELECT t.level_warn FROM TEMPER_RC t;')
> for val in warn:
> if (val == (1)):
> db.TEMPER_RC.level_warn.represent = lambda value, row: (B (DIV
> (str ('1 '% row if row else''), _style =' background: # 339933 ')))
> elif (val == (2)):
> db.TEMPER_RC.level_warn.represent = lambda value, row: (B (DIV
> (str ('2 '% row if row else''), _style =' background: # FFFF33 ')))
> else:
> db.TEMPER_RC.level_warn.represent = lambda value, row: (B (DIV
> (str ('3 '% row if row else''), _style =' background: # FF0000 ')))
>
> But only fulfills the first condition, and all the fields level_warn
> colored in green. Moreover, the condition fulfills wrong, because the first
> row in the table has a value of 3, that is, the field must be painted red!
>
> What am I doing wrong?
>
>
--
---
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.