Dear Community,I just started with web2py and ran into some difficulties:I would like to display a custom table with my data. For the value of a specific field in each row I need the corresponding information from another table.This is what I have so far:
def get_extended_info_for_case(case_id):# DB-Query here to get the fields&values I need
return extended_infodef manage():ext_info = lambda row: get_extended_info_for_case(row.cases.id)db.cases.extended_info = Field.Virtual(ext_info)rows = db(db.cases).select()headers = ["ID", "A", "B", "C", "Extended Info"]fields = ["id", "a", "b", "c", "extended_info"]table = TABLE(THEAD(TR(*[B(header) for header in headers])),TBODY(*[TR(*[TD(row[field]) for field in fields])for row in rows]))
This works when the helper-function get_extended_info returns just a plain string. However, if I have it return a list of tuples that I can then use to dynamically create links within the virtualfield - one for each tuple - I'm lost.For example:
extended_info = [(1,"A1"), (223,"whatever")]resulting entry in the corresponding virtualfield should be a concatenation of several links:
A(A1, _href=URL("edit", args=1)), A(whatever, _href=URL("edit", args=223))How can I accomplish this? Can I integrate the query to the second databasetable into the first one? Or do I need nested lambdas? I have to admit that I don't fully understand the way lambdas and the nested table-construction work. Is there a way to display this in a more human-readable form? Or am I better of contructing my table in the view instead?Thanks a lot.Best regards,Dan
ext_info = lambda row: [A(op, _href=URL("edit", args=op_id, user_signature=True)) + " " for op, op_id in get_extended_info_for_case(row.cases.id)]
--
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/o6_wQZ_HBgM/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.