[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
One year later I still can't display virtual field in the SQLFORM.grid with an error: type 'exceptions.AttributeError' 'Row' object has no attribute 'broj' And my virtual field is defined as: db.define_table('fin_fis', Field('god','integer',label=T('Year')), Field('pod','reference sif_pod',label=T('Company'),writable=False, readable=False), Field('oj','reference sif_oj',label=T('Department')), Field('kasa','integer',label=T('Billing device')), Field('vd','reference sif_vd',label=T('Document type')), Field('br','integer',label=T('Number')), Field.Virtual('broj',lambda row: '%05d/P%03d%03d/%d'%(row.fin_fis.br,row.fin_fis.oj,row.fin_fis.vd,row.fin_fis.kasa),label='Broj'), . ) This is my field list: fields = (db.fin_fis.oj,db.fin_fis.kasa,db.fin_fis.br,db.fin_fis.broj,db.fin_fis.dvi,db.fin_fis.iznrac,db.fin_fis.npl,db.sif_radnici.ime, db.sif_radnici.prezime) I'm using: 2.9.5-stable+timestamp.2014.03.16.02.35.39 (Running on Apache/2.4.9 (Ubuntu), Python 2.7.3) Dana subota, 20. srpnja 2013. 11:54:24 UTC+2, korisnik peckto napisao je: I think i can explain this behaviour. The statement var in list cals the lists __contains__ method, which loops through the list and compares each element with var. But in case of an Field object the equals operator (__eq__) has another meaning, it's the WHERE part of the db query: db(db.table.id==1).select() So this comparison will olways return True. Am Samstag, 20. Juli 2013 09:00:52 UTC+2 schrieb Massimo Di Pierro: Strange. Ok. I changed it again. Can you please check it. I am still trying to avoid the double loop for every virtual table. On Friday, 19 July 2013 16:54:05 UTC-5, peckto wrote: 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). -- 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.
[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
I think the problem is that your virtual field depends on some fields you have not included in your grid, so the virtual field values cannot be calculated. Instead of specifying the fields argument, you can hide particular fields from the grid by setting their readable attribute to False. In that case, all the fields will be included in the query done by the grid, which will enable the virtual field values to be calculated. Anthony On Wednesday, July 23, 2014 10:41:54 AM UTC-4, Adam Filić wrote: One year later I still can't display virtual field in the SQLFORM.grid with an error: type 'exceptions.AttributeError' 'Row' object has no attribute 'broj' And my virtual field is defined as: db.define_table('fin_fis', Field('god','integer',label=T('Year')), Field('pod','reference sif_pod',label=T('Company'),writable=False, readable=False), Field('oj','reference sif_oj',label=T('Department')), Field('kasa','integer',label=T('Billing device')), Field('vd','reference sif_vd',label=T('Document type')), Field('br','integer',label=T('Number')), Field.Virtual('broj',lambda row: '%05d/P%03d%03d/%d'%(row.fin_fis.br ,row.fin_fis.oj,row.fin_fis.vd,row.fin_fis.kasa),label='Broj'), . ) This is my field list: fields = (db.fin_fis.oj,db.fin_fis.kasa,db.fin_fis.br,db.fin_fis.broj,db.fin_fis.dvi,db.fin_fis.iznrac,db.fin_fis.npl,db.sif_radnici.ime, db.sif_radnici.prezime) I'm using: 2.9.5-stable+timestamp.2014.03.16.02.35.39 (Running on Apache/2.4.9 (Ubuntu), Python 2.7.3) Dana subota, 20. srpnja 2013. 11:54:24 UTC+2, korisnik peckto napisao je: I think i can explain this behaviour. The statement var in list cals the lists __contains__ method, which loops through the list and compares each element with var. But in case of an Field object the equals operator (__eq__) has another meaning, it's the WHERE part of the db query: db(db.table.id==1).select() So this comparison will olways return True. Am Samstag, 20. Juli 2013 09:00:52 UTC+2 schrieb Massimo Di Pierro: Strange. Ok. I changed it again. Can you please check it. I am still trying to avoid the double loop for every virtual table. On Friday, 19 July 2013 16:54:05 UTC-5, peckto wrote: 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). -- 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.
Re: [web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
Yes, you are right. That was the problem and it shows up in the grid now, but I can't see it in the view form. All included fields are readable. Thank you 2014-07-23 17:53 GMT+02:00 Anthony abasta...@gmail.com: I think the problem is that your virtual field depends on some fields you have not included in your grid, so the virtual field values cannot be calculated. Instead of specifying the fields argument, you can hide particular fields from the grid by setting their readable attribute to False. In that case, all the fields will be included in the query done by the grid, which will enable the virtual field values to be calculated. Anthony On Wednesday, July 23, 2014 10:41:54 AM UTC-4, Adam Filić wrote: One year later I still can't display virtual field in the SQLFORM.grid with an error: type 'exceptions.AttributeError' 'Row' object has no attribute 'broj' And my virtual field is defined as: db.define_table('fin_fis', Field('god','integer',label=T('Year')), Field('pod','reference sif_pod',label=T('Company'),writable=False, readable=False), Field('oj','reference sif_oj',label=T('Department')), Field('kasa','integer',label=T('Billing device')), Field('vd','reference sif_vd',label=T('Document type')), Field('br','integer',label=T('Number')), Field.Virtual('broj',lambda row: '%05d/P%03d%03d/%d'%(row.fin_fis.br ,row.fin_fis.oj,row.fin_fis.vd,row.fin_fis.kasa),label='Broj'), . ) This is my field list: fields = (db.fin_fis.oj,db.fin_fis.kasa,db.fin_fis.br,db.fin_fis. broj,db.fin_fis.dvi,db.fin_fis.iznrac,db.fin_fis.npl,db.sif_radnici.ime, db.sif_radnici.prezime) I'm using: 2.9.5-stable+timestamp.2014.03.16.02.35.39 (Running on Apache/2.4.9 (Ubuntu), Python 2.7.3) Dana subota, 20. srpnja 2013. 11:54:24 UTC+2, korisnik peckto napisao je: I think i can explain this behaviour. The statement var in list cals the lists __contains__ method, which loops through the list and compares each element with var. But in case of an Field object the equals operator (__eq__) has another meaning, it's the WHERE part of the db query: db(db.table.id==1).select() So this comparison will olways return True. Am Samstag, 20. Juli 2013 09:00:52 UTC+2 schrieb Massimo Di Pierro: Strange. Ok. I changed it again. Can you please check it. I am still trying to avoid the double loop for every virtual table. On Friday, 19 July 2013 16:54:05 UTC-5, peckto wrote: 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). -- 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/yIRGzpZYcbg/unsubscribe. To unsubscribe from this group and all its topics, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- Srdačan pozdrav Adam Filić www.tt-program.com -- 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.
Re: [web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
True, readonly forms do not show virtual fields. Perhaps submit a Google Code issue requesting that feature. Anthony On Wednesday, July 23, 2014 12:44:30 PM UTC-4, Adam Filić wrote: Yes, you are right. That was the problem and it shows up in the grid now, but I can't see it in the view form. All included fields are readable. Thank you 2014-07-23 17:53 GMT+02:00 Anthony abasta...@gmail.com: I think the problem is that your virtual field depends on some fields you have not included in your grid, so the virtual field values cannot be calculated. Instead of specifying the fields argument, you can hide particular fields from the grid by setting their readable attribute to False. In that case, all the fields will be included in the query done by the grid, which will enable the virtual field values to be calculated. Anthony On Wednesday, July 23, 2014 10:41:54 AM UTC-4, Adam Filić wrote: One year later I still can't display virtual field in the SQLFORM.grid with an error: type 'exceptions.AttributeError' 'Row' object has no attribute 'broj' And my virtual field is defined as: db.define_table('fin_fis', Field('god','integer',label=T('Year')), Field('pod','reference sif_pod',label=T('Company'),writable=False, readable=False), Field('oj','reference sif_oj',label=T('Department')), Field('kasa','integer',label=T('Billing device')), Field('vd','reference sif_vd',label=T('Document type')), Field('br','integer',label=T('Number')), Field.Virtual('broj',lambda row: '%05d/P%03d%03d/%d'%(row.fin_ fis.br,row.fin_fis.oj,row.fin_fis.vd,row.fin_fis.kasa),label='Broj'), . ) This is my field list: fields = (db.fin_fis.oj,db.fin_fis.kasa,db.fin_fis.br,db.fin_fis. broj,db.fin_fis.dvi,db.fin_fis.iznrac,db.fin_fis.npl,db.sif_radnici.ime, db.sif_radnici.prezime) I'm using: 2.9.5-stable+timestamp.2014.03.16.02.35.39 (Running on Apache/2.4.9 (Ubuntu), Python 2.7.3) Dana subota, 20. srpnja 2013. 11:54:24 UTC+2, korisnik peckto napisao je: I think i can explain this behaviour. The statement var in list cals the lists __contains__ method, which loops through the list and compares each element with var. But in case of an Field object the equals operator (__eq__) has another meaning, it's the WHERE part of the db query: db(db.table.id==1).select() So this comparison will olways return True. Am Samstag, 20. Juli 2013 09:00:52 UTC+2 schrieb Massimo Di Pierro: Strange. Ok. I changed it again. Can you please check it. I am still trying to avoid the double loop for every virtual table. On Friday, 19 July 2013 16:54:05 UTC-5, peckto wrote: 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). -- 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/yIRGzpZYcbg/unsubscribe. To unsubscribe from this group and all its topics, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- Srdačan pozdrav Adam Filić www.tt-program.com -- 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.
[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
Strange. Ok. I changed it again. Can you please check it. I am still trying to avoid the double loop for every virtual table. On Friday, 19 July 2013 16:54:05 UTC-5, peckto wrote: 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). -- --- 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.
[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
I think i can explain this behaviour. The statement var in list cals the lists __contains__ method, which loops through the list and compares each element with var. But in case of an Field object the equals operator (__eq__) has another meaning, it's the WHERE part of the db query: db(db.table.id==1).select() So this comparison will olways return True. Am Samstag, 20. Juli 2013 09:00:52 UTC+2 schrieb Massimo Di Pierro: Strange. Ok. I changed it again. Can you please check it. I am still trying to avoid the double loop for every virtual table. On Friday, 19 July 2013 16:54:05 UTC-5, peckto wrote: 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). -- --- 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.
[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
Your code is in trunk with some minor refactoring. Should work as in your patch. Can you please help me check it? Thanks On Thursday, 18 July 2013 17:19:00 UTC-5, peckto wrote: Hi, i have just created a small patch to get virtual fields working with SQLFORM.grid. Let me know when it doesn't work for you. I have tested it only with my mysql db and without db options like left join, group, etc .. A pull request is on the way. Have fun using virtual field in you grid! 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.
[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
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.
[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
Hi, i have just created a small patch to get virtual fields working with SQLFORM.grid. Let me know when it doesn't work for you. I have tested it only with my mysql db and without db options like left join, group, etc .. A pull request is on the way. Have fun using virtual field in you grid! 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. diff --exclude .git -u -r -N web2py_plain/gluon/dal.py web2py_patched/gluon/dal.py --- web2py_plain/gluon/dal.py 2013-07-18 22:51:46.493777980 +0200 +++ web2py_patched/gluon/dal.py 2013-07-18 22:51:23.387066854 +0200 @@ -1538,6 +1538,7 @@ args_get = attributes.get tablenames = tables(query) tablenames_for_common_filters = tablenames +fields = [f for f in fields if not isinstance(f,Field.Virtual)] # skip virtual fields for field in fields: if isinstance(field, basestring) \ and REGEX_TABLE_DOT_FIELD.match(field): @@ -2111,10 +2112,14 @@ for tablename in virtualtables: ### new style virtual fields table = db[tablename] +#fields_virtual = [(f,v) for (f,v) in table.iteritems() +# if isinstance(v,FieldVirtual)] +#print('fields_virtual(old): %s' %fields_virtual) fields_virtual = [(f,v) for (f,v) in table.iteritems() - if isinstance(v,FieldVirtual)] + if isinstance(v,FieldVirtual) and v.name in [f_.name for f_ in fields] and v.tablename == tablename] fields_lazy = [(f,v) for (f,v) in table.iteritems() - if isinstance(v,FieldMethod)] + if isinstance(v,FieldMethod) and v.name in [f_.name for f_ in fields] and v.tablename == tablename] +#print('fields_virtual(new): %s' %fields_virtual) if fields_virtual or fields_lazy: for row in rowsobj.records: box = row[tablename] diff --exclude .git -u -r -N web2py_plain/gluon/sqlhtml.py web2py_patched/gluon/sqlhtml.py --- web2py_plain/gluon/sqlhtml.py 2013-07-18 22:51:46.499777905 +0200 +++ web2py_patched/gluon/sqlhtml.py 2013-07-18 22:51:15.275168266 +0200 @@ -1928,6 +1928,7 @@ if isinstance(f,Field.Virtual) and f.readable: f.tablename = table._tablename columns.append(f) +fields.append(f) if not field_id: field_id = tables[0]._id if not any(str(f)==str(field_id) for f in fields): @@ -2239,7 +2240,10 @@ limitby = None try: -table_fields = [f for f in fields if f.tablename in tablenames] +table_fields = list() +for f in fields: +if f.tablename in tablenames: +
[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
By the way, I found http://www.web2py.com/book/default/chapter/06#before-and-after-callbacks which can help in some cases, where I thought to use virtual fields as with callbacks you can update needed info from foreign tables (or computed fields might also be enough in some cases) 2012 m. gruodis 18 d., antradienis 09:03:05 UTC+2, software.ted rašė: 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.
Re: [web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
Hi, probably, virtual fields can be injected somewhere in: https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L1931 https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L2242 https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L2322 ps.: For virtual fields, one should know which other fields of table it depends on - to .select(..) them for calculations. that might need some changes when defining VirtualField ? and but these other fields might not need be shown in grid..., so should be apart from fields=... argument. ps.: VirutalFields doesn't have .tablename property - not implemented yet, or other reasons? 2013 m. balandis 6 d., šeštadienis 19:33:01 UTC+3, Massimo Di Pierro rašė: I will be fixed asap. I cannot give you a deadline. On Friday, 5 April 2013 19:42:04 UTC-5, Richard wrote: I fall on this exact problem, I don't see anything about taht in the change log of 2.4.4. Is this will be fix soon? I mean SQLFORM.grid support for virtual field THanks Richard On Tue, Dec 18, 2012 at 10:32 AM, Massimo Di Pierro massimo@gmail.com wrote: Right now grid does not work with virtual fields. There is a pending proposal for enhancement to support them. On Tuesday, 18 December 2012 01:03:05 UTC-6, software.ted wrote: 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.
Re: [web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
for now the workaround might be manipulating generated html table like https://groups.google.com/d/msg/web2py/BmbIlkWYZVo/hccT2JQCUp0J you need to know id of records - so you could get info for calculating virtual field, so instead : fields=[db.product.name, db.product.cost, db.product.quantity, db.product.virtual_total] give fields=[db.product.name, db.product.cost, db.product.quantity, db.product.id] and then replace/calculate the 4th column contents: grid = SQLFORM.grid(query or table, fields=fields) trs = grid.element(table).elements(tr) for tr in grid.element(tbody).elements(tr): id = int(tr[3][0]) tr[3][0] = str( db.product(id).virtual_total ) ps.: for easier manipulation could use dict notation: db.product['virtual_total'] db.product(id)['virtual_total'] 2013 m. balandis 21 d., sekmadienis 21:49:36 UTC+3, Jurgis Pralgauskis rašė: Hi, probably, virtual fields can be injected somewhere in: https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L1931 https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L2242 https://github.com/web2py/web2py/blob/master/gluon/sqlhtml.py#L2322 ps.: For virtual fields, one should know which other fields of table it depends on - to .select(..) them for calculations. that might need some changes when defining VirtualField ? and but these other fields might not need be shown in grid..., so should be apart from fields=... argument. ps.: VirutalFields doesn't have .tablename property - not implemented yet, or other reasons? 2013 m. balandis 6 d., šeštadienis 19:33:01 UTC+3, Massimo Di Pierro rašė: I will be fixed asap. I cannot give you a deadline. On Friday, 5 April 2013 19:42:04 UTC-5, Richard wrote: I fall on this exact problem, I don't see anything about taht in the change log of 2.4.4. Is this will be fix soon? I mean SQLFORM.grid support for virtual field THanks Richard On Tue, Dec 18, 2012 at 10:32 AM, Massimo Di Pierro massimo@gmail.com wrote: Right now grid does not work with virtual fields. There is a pending proposal for enhancement to support them. On Tuesday, 18 December 2012 01:03:05 UTC-6, software.ted wrote: 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.
Re: [web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
No problem, thanks for the answer! Richard On Sat, Apr 6, 2013 at 12:33 PM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: I will be fixed asap. I cannot give you a deadline. On Friday, 5 April 2013 19:42:04 UTC-5, Richard wrote: I fall on this exact problem, I don't see anything about taht in the change log of 2.4.4. Is this will be fix soon? I mean SQLFORM.grid support for virtual field THanks Richard On Tue, Dec 18, 2012 at 10:32 AM, Massimo Di Pierro massimo@gmail.com wrote: Right now grid does not work with virtual fields. There is a pending proposal for enhancement to support them. On Tuesday, 18 December 2012 01:03:05 UTC-6, software.ted wrote: Does SQLFORM.grid support adding and display of a virtual field...am getting an exception...my code: db.file_subject_issue.file_**nam**e = 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_**cre**ated, db.file_subject_issue.file_** nam**e] query = form = SQLFORM.grid(query,fields=**fiel**ds,...) 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/**r**estricted.py, line 212, in restricted exec ccode in environment File /home/www-data/web2py/**applica**tions/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/**g**lobals.py, line 188, in lambda self._caller = lambda f: f() File /home/www-data/web2py/**applica**tions/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/**s**qlhtml.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. -- --- 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.
Re: [web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
I will be fixed asap. I cannot give you a deadline. On Friday, 5 April 2013 19:42:04 UTC-5, Richard wrote: I fall on this exact problem, I don't see anything about taht in the change log of 2.4.4. Is this will be fix soon? I mean SQLFORM.grid support for virtual field THanks Richard On Tue, Dec 18, 2012 at 10:32 AM, Massimo Di Pierro massimo@gmail.comjavascript: wrote: Right now grid does not work with virtual fields. There is a pending proposal for enhancement to support them. On Tuesday, 18 December 2012 01:03:05 UTC-6, software.ted wrote: 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.
Re: [web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
I fall on this exact problem, I don't see anything about taht in the change log of 2.4.4. Is this will be fix soon? I mean SQLFORM.grid support for virtual field THanks Richard On Tue, Dec 18, 2012 at 10:32 AM, Massimo Di Pierro massimo.dipie...@gmail.com wrote: Right now grid does not work with virtual fields. There is a pending proposal for enhancement to support them. On Tuesday, 18 December 2012 01:03:05 UTC-6, software.ted wrote: 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.
[web2py] Re: REF: Displaying a Virtual Field in SQLFORM.grid throws an exception....
Right now grid does not work with virtual fields. There is a pending proposal for enhancement to support them. On Tuesday, 18 December 2012 01:03:05 UTC-6, software.ted wrote: 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 /~ --