links = [lambda row: A(XML('<span class="glyphicon glyphicon-pencil space-after"></span> Edit'),
_href=URL('sample', 'sample', vars={'sample_id': row.sample.id}, user_signature=True),
_class='btn btn-default'),
lambda row: A(XML('<span class="glyphicon glyphicon-pencil space-after"></span> Reports'),
_href=URL('sample', 'sample_reports', vars={'sample_id': row.sample.id},
user_signature=True), _class='btn btn-default'),
lambda row: A(XML('<span class="glyphicon glyphicon-paperclip space-after"></span> Attach Document'),
_href=URL('sample', 'sample_attach_document', vars={'sample_id': row.sample.id},
user_signature=True), _class='btn btn-default', _name='attach_document'),
lambda row: A(XML('<span class="glyphicon glyphicon-eye-open space-after"></span> View Attached'),
_onclick='open_modal(%s)' % row.sample.id, _class='btn btn-default') if row.sample_attachment.id else None
]
Here is a sample we have where we add 'links'.links = [lambda row: A(XML('<span class="glyphicon glyphicon-pencil space-after"></span> Edit'),
_href=URL('sample', 'sample', vars={'sample_id': row.sample.id}, user_signature=True),
_class='btn btn-default'),
lambda row: A(XML('<span class="glyphicon glyphicon-pencil space-after"></span> Reports'),
_href=URL('sample', 'sample_reports', vars={'sample_id': row.sample.id},
user_signature=True), _class='btn btn-default'),
lambda row: A(XML('<span class="glyphicon glyphicon-paperclip space-after"></span> Attach Document'),
_href=URL('sample', 'sample_attach_document', vars={'sample_id': row.sample.id},
user_signature=True), _class='btn btn-default', _name='attach_document'),
lambda row: A(XML('<span class="glyphicon glyphicon-eye-open space-after"></span> View Attached'),
_onclick='open_modal(%s)' % row.sample.id, _class='btn btn-default') if row.sample_attachment.id else None
]It appears to me that your first 'link' is actually an extra column that you're adding to your grid.Then, the second dict shouldn't be a dict at all, links should just be a list of your lambdas, like you have in the 'body' of the second dict.
Here is my links code:links = [dict(header='Balance', body=lambda row: row.po.amount - row.invoice_items.amount_pretax),dict(header='Controls', body=[lambda row: A('Invoices',_class='button btn btn-default',_href=URL('invoice', 'list', args=['commitment', row.po.id], vars=dict(source=here))),lambda row: A('Edit',_class='button btn btn-default',_href=URL('edit', args=row.po.id, vars=dict(source=here))),lambda row: A('Files',_class='button btn btn-default',_href=URL('attachments', 'list', args=['commitment',row.po.id], vars=dict(source=here))),lambda row: A('Delete',_class='button btn btn-default',_href=URL('delete', args=row.po.id, vars=dict(source=here)))]]However, I get an "attribution error" for the first dict,
and a "list not callable" for the controls dict.
On Friday, June 15, 2018 at 12:57:54 PM UTC-4, watr wrote:Here is my links code:links = [dict(header='Balance', body=lambda row: row.po.amount - row.invoice_items.amount_pretax),dict(header='Controls', body=[lambda row: A('Invoices',_class='button btn btn-default',_href=URL('invoice', 'list', args=['commitment', row.po.id], vars=dict(source=here))),lambda row: A('Edit',_class='button btn btn-default',_href=URL('edit', args=row.po.id, vars=dict(source=here))),lambda row: A('Files',_class='button btn btn-default',_href=URL('attachments', 'list', args=['commitment',row.po.id], vars=dict(source=here))),lambda row: A('Delete',_class='button btn btn-default',_href=URL('delete', args=row.po.id, vars=dict(source=here)))]]However, I get an "attribution error" for the first dict,Presumably either row.po.amount or row.invoice_items.amount_pretax are incorrect.and a "list not callable" for the controls dict.
--The "body" item of the dictionary must be a callable that takes the row object and outputs a web2py string or web2py HTML DOM element. It cannot be a list of functions. If you want to generate a set of links, generate them all in a single function and wrap them in CAT() or DIV() (or whatever works for the desired layout within the table cell).Anthony
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/2C6S4_yaif0/unsubscribe.
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/d/optout.