Hi,
I'm posting this in the hope it could be useful for someone.
I've the need to use a virtual field in an autocomplete widget, to show
hierarchy of a reference, something like
Field.Virtual('fv_full_name',lambda row,alt=None : row.t_table.f_name if not
row.t_table.f_parent else row.t_table.f_parent.fl_full_name + " -> " + row.
t_table.f_name)
I've found that virtual field in sqlhtml.py autocomplete widget are not
working (web2py version 2.14.6-stable+timestamp.2016.05.10.00.21.47).
In particular the line
rows = Rows(self.db, records, table_rows.colnames, compact=table_rows.
compact)
give an error *<type 'exceptions.NameError'> global name 'Rows' is not
defined*
and count is limited to 10, regardless the limitby value.
I've managed to work with the following change:
def callback(self):
if self.keyword in self.request.vars:
field = self.fields[0]
if type(field) is Field.Virtual:
records = []
table_rows = self.db(self.db[field.tablename]).select(
orderby=self.orderby)
count = 0
for row in table_rows:
if self.at_beginning:
if row[field.name].lower().startswith(self.request.
vars[self.keyword]):
count += 1
records.append(row)
else:
if self.request.vars[self.keyword] in row[field.name
].lower():
count += 1
records.append(row)
if count == self.limitby[1]: #<<<< ADDED LIMITBY
break
rows = (table_rows.__class__)(self.db, records, table_rows.
colnames, compact=table_rows.compact) # <<<<<< CHANGED ROWS CONSTRUCTOR
I'm using (table_rows.__class__) as a way to initialize the *Rows* class.
I don't know there is a better way.
Bye.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.