You're already looping over the tables when you define your functions, so
just use the table value from the loop in your lambda function definitions.
Not tested, but maybe something like:
def remove_filters(table):
for field in table:
field.filter_out = None
for t in db.tables:
db[t]._before_insert.insert(0, lambda f, table=db[t]: remove_filters(
table))
db[t]._before_update.insert(0, lambda s, f, table=db[t]: remove_filters(
table))
Instead, though, it might be worth figuring out why you're getting the
errors and seeing if that can be fixed.
Anthony
On Wednesday, April 30, 2014 10:03:48 AM UTC-4, Diogo Munaro wrote:
> Hey guys! Nowadays I'm using a some filter_outs but they got update and
> insert erros on record versioning.
>
> I'm solving update issue using before_update like this:
>
> def remove_filter(s,field):
> field_obj = s.query.db[str(s.query).split('.')[0][1:]][field]
> field_obj.filter_out = ''
>
> for t in db.tables:
> db[t]._before_update.insert(0, lambda s, f: not [remove_filter(s,
> field) for field in f])
>
> s.query.db is the returned db;
>
> str(s.query).split('.')[0][1:] is an ugly way to get table name
>
> field is the field_name.
>
> With update I got an ugly solution, but I got a solution. With insert I
> can't do it because before_insert don't have a Query object and I can't get
> table name
>
> Is there a better way to solve it and remove filter_outs before inserts
> and updates?
>
--
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.