Python ternary expressions are just expressions, so one element of a 
ternary can itself be another ternary (i.e., you can nest them). So, you 
can do:

1 if condition1 else 2 if condition2 else 3

which for clarity you could write as:

1 if condition1 else (2 if condition 2 else 3)

As an aside, lambdas are intended to be relatively short anonymous 
functions. When they get as long as yours, they become very difficult to 
comprehend. You might be better served by moving it to a standard function 
definition (which will also make it easier to test independently).

Anthony

On Friday, December 4, 2015 at 9:21:02 PM UTC-5, Alex Glaros wrote:
>
> sorry, I over simplified. I'd like to handle more than two conditionals. 
> For example, based on another field's value, I would like a different 
> message to appear.  
>
> So with two conditionals, syntax does work. Seel yellow
>
> connection_canceling_links =  [dict(header='Cancel connection', 
>  body=lambda row: A('Withdraw my invitation', 
> _href=URL('delete_connection_request_i_sent', args=row.auth_membership.id, 
> vars=dict(person_first_name=row.auth_user.first_name, 
> person_last_name=row.auth_user.last_name, person_user_id=row.auth_user.id)), 
> _class='btn') if row.auth_membership.is_active else DIV('Historical 
> data', _style='color:DarkGray'))]
>
> But how to add another IF statement as in below (which raises syntax 
> error).  See orange IF added to the already-working yellow ones
>
> connection_canceling_links =  [dict(header='Cancel connection', 
>  body=lambda row: A('Withdraw my invitation', 
> _href=URL('delete_connection_request_i_sent', args=row.auth_membership.id, 
> vars=dict(person_first_name=row.auth_user.first_name, 
> person_last_name=row.auth_user.last_name, person_user_id=row.auth_user.id)), 
> _class='btn') if row.auth_membership.is_active DIV('Testing data', 
> _style='color:Orange') if row.auth_membership.status = '10' else 
> DIV('Historical data', _style='color:DarkGray'))]
>
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to