Regarding your changes:
+            all_fields = filter(lambda nv: nv[1] in fields and 
+                                isinstance(nv[1],(FieldVirtual,FieldMethod
)), 
+                                table.iteritems())            
It doesn't work. It ends up in returning all virtual fields, even when they 
are not requested.
It's because of the "var in list" statement:
nv[1] in fields
always returns True. I don't know why.

Another solution would be to use the id() function:
id(nv[1]) in [id(f_) for f_ in fields]
but you have overwritten this function
2091: id = value

So I came finally to the complicated looking statement:
nv[0] in [f_.name for f_ in fields] and nv[1].tablename == tablename

Maybe you can tell me why the "var in list" statement fails 
or we use one of the other solutions (while renaming the id value).


Am Dienstag, 18. Dezember 2012 08:03:05 UTC+1 schrieb software.ted:
>
> Does SQLFORM.grid support adding and display of a virtual field...am 
> getting an exception...my code:
>
> db.file_subject_issue.file_name = Field.Virtual(lambda row: 
> get_file_name(row.file_subject_issue.file_id))
> fields = [db.file_subject_issue.file_id, 
> db.file_subject_issue.date_created, db.file_subject_issue.file_name]
> query =....
>
> form = SQLFORM.grid(query,fields=fields,...)
>
> I am getting the error
>
> <type 'exceptions.AttributeError'> 'FieldVirtual' object has no attribute 
> '_tablename'
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
>
> Traceback (most recent call last):
>   File "/home/www-data/web2py/gluon/restricted.py", line 212, in restricted
>
>     exec ccode in environment
>   File 
> "/home/www-data/web2py/applications/intranet/controllers/administration.py" 
> <https://192.168.0.251/admin/default/edit/intranet/controllers/administration.py>,
>  line 176, in <module>
>
>   File "/home/www-data/web2py/gluon/globals.py", line 188, in <lambda>
>
>     self._caller = lambda f: f()
>
>   File 
> "/home/www-data/web2py/applications/intranet/controllers/administration.py" 
> <https://192.168.0.251/admin/default/edit/intranet/controllers/administration.py>,
>  line 71, in file_track
>
>     selectable=False,csv=False , paginate=20, user_signature=False)
>
>   File "/home/www-data/web2py/gluon/sqlhtml.py", line 1796, in grid
>
>     if field._tablename in tablenames]
> AttributeError: 'FieldVirtual' object has no attribute '_tablename'
>
>
>
>
> -- 
>
> .......................................................................................
> Teddy Lubasi Nyambe
> Opensource Zambia
> Lusaka, ZAMBIA
>
> Cell: +260 97 7760473
> website: http://www.opensource.org.zm
>
> ~/
> Human Knowledge belongs to the world! - AntiTrust
>
> Man is a tool-using animal. Without tools he is nothing, with tools he is 
> all - Thomas Carlyle 1795-1881
>
> /~
>  

-- 

--- 
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/groups/opt_out.


Reply via email to