I have customized one of the fields of my SQLForm whereby instead of displaying its long content, it shows a small button that copies its content into the clipboard, as follows:
db.mytable.myfield.represent = lambda value, row: TAG.button(SPAN(DIV(row.myfield, _id="cp_"+str(row.id),_style="display:none"),_class='glyphicon glyphicon-copy'),_type="button",_onClick="copyToClipboard('#cp_%s'); $.web2py.flash('myfield copied: %s...');"% (row.id,value[:25]), _class="btn-primary")
This works fine for most purposes until I try to export the table contents to CSV, HTML and TSV using the SQLForm.smartgrid() generated buttons with an error as follows:
File ".../gluon/sqlhtml.py", line 3648, in export
self.rows.export_to_csv_file(s, represent=True)
File "/local/path/site-packages/pydal/objects.py", line 2603, in export_to_csv_file
value = field.represent(value, record)
File ".../controllers/analysis.py", line 77, in <lambda>
db.mytable.myfield.represent = lambda value, row: TAG.button(SPAN(DIV(row.myfield, _id="cp_"+str(row.id),_style="display:none"),_class='glyphicon glyphicon-copy'),_type="button",_onClick="copyToClipboard('#cp_%s'); $.web2py.flash('myfield copied: %s...');"% (row.id,value[:25]), _class="btn-primary")
File "/local/path/site-packages/pydal/objects.py", line 99, in __getattr__
raise AttributeError
AttributeError
Exporting to JSON and XML works fine though. Am I doing something wrong? Is there a way to have my form customization working without breaking the export functionality?
Thank you