This can probably be improved, but the problem is that your grid does not 
include all the fields needed by the "represent" function (i.e., it is 
missing the "id" field). You could (a) re-write the represent so it doesn't 
fail when the "id" field is missing, (b) use one of the "hidden column" 
downloads instead, or (c) in the controller, check whether the request is 
for an export (i.e, '_export_type' in request.vars), and include the "id" 
field in that case.

Unfortunately, these solutions mean you either won't have the "represented" 
value in the CSV file (which you may not want anyway, as it is an HTML 
anchor tag in this case), or you will have extra fields that you otherwise 
might want excluded (in this case, the "id" field).

Note, you can also use the "exportclasses" argument to provide your own 
custom export class, and use something like option (c) above, but write the 
export class so it excludes any columns you want to hide.

Anthony

On Friday, February 12, 2016 at 5:01:40 PM UTC-5, olivier hubert wrote:
>
>
> I implemented a clone of Notifier application from Massimo.
> If I try to export data from the grid via the grid bottom button I receive 
> an error if I use export to CSV, HTML & TSV but not with JSON or XML.
>
> *default.py*
> @auth.requires_login()
> def tasks():
>     db.task.created_on.readable = True
>     db.task.created_by.readable = True
>     db.task.title.represent = lambda title, row:A(title, _href=URL(
> 'view_task', args=row.id))
>     query = (db.task.assigned_to==me)|(db.task.created_by==me)
>     grid = SQLFORM.grid(query,
>                         orderby=~db.task.modified_on,
>                         create=False,
>                         details=False,
>                         editable=False,
>                         deletable=lambda row: (row.created_by==me),
>                         fields=[
>                                 db.task.status,
>                                 db.task.title,
>                                 db.task.created_on,
>                                 db.task.deadline,
>                                 db.task.created_by,
>                                 db.task.assigned_to
>                         ])
>     return locals()
>
> *Traceback*
>
>  Traceback (most recent call last):
>  File "/home/sysadmin/Téléchargements/web2py/gluon/restricted.py", line 
> 227, in restricted
>  exec ccode in environment
>  File 
> "/home/sysadmin/Téléchargements/web2py/applications/tasklist/controllers/default.py"
>  
> <http://127.0.0.1:8000/admin/default/edit/tasklist/controllers/default.py>
> , line 134, in <module>
>  File "/home/sysadmin/Téléchargements/web2py/gluon/globals.py", line 412, 
> in <lambda>
>  self._caller = lambda f: f()
>  File "/home/sysadmin/Téléchargements/web2py/gluon/tools.py", line 4236, 
> in f
>  return action(*a, **b)
>  File 
> "/home/sysadmin/Téléchargements/web2py/applications/tasklist/controllers/default.py"
>  
> <http://127.0.0.1:8000/admin/default/edit/tasklist/controllers/default.py>
> , line 31, in tasks
>  db.task.assigned_to
>  File "/home/sysadmin/Téléchargements/web2py/gluon/sqlhtml.py", line 2440, 
> in grid
>  raise HTTP(200, oExp.export(), **response.headers)
>  File "/home/sysadmin/Téléchargements/web2py/gluon/sqlhtml.py", line 3468, 
> in export
>  self.rows.export_to_csv_file(s, represent=True)
>  File "/home/sysadmin/.local/lib/python2.7/site-packages/pydal/objects.py"
> , line 2412, in export_to_csv_file
>  value = field.represent(value, record)
>  File 
> "/home/sysadmin/Téléchargements/web2py/applications/tasklist/controllers/default.py"
>  
> <http://127.0.0.1:8000/admin/default/edit/tasklist/controllers/default.py>
> , line 17, in <lambda>
>  db.task.title.represent = lambda title, row:A(title, _href=URL(
> 'view_task', args=row.id))
>  File "/home/sysadmin/.local/lib/python2.7/site-packages/pydal/objects.py"
> , line 90, in __getattr__
>  raise AttributeError
> AttributeError
>
>
> The error come from the bellow code line from the file default.py
> db.task.title.represent = lambda title, row:A(title, _href=URL('view_task'
> , args=row.id))
>
> If I remove the previous row the export function work for all format but I 
> lose the cliquable link on the task title.
>
> I checked with the Notifier application available on GitHub 
> https://github.com/mdipierro/web2py-appliances/tree/master/Notifier and I 
> see the same problem.
>
> If you can help me it's very appreciate.
>
> Kind regards
> Olivier
>
>
>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to