the book shows how to print every argument passed to those functions.... I
dunno how to make the book clearer :°°°D
before_insert ....
def this_is_before_insert(some_dict):
if 'last_name' in some_dict:
some_dict['last_name'] = 'altering' + some_dict['last_name']
db.auth_user._before_insert.append(lambda f: this_is_before_insert(f))
>>>db.auth_user.insert(first_name='john')
1L
>>> db.auth_user.insert(last_name='doe')
2L
>>> rtn = db(db.auth_user.id>0).select(db.auth_user.first_name, db.auth_user
.last_name)
>>> print str(rtn)
auth_user.first_name,auth_user.last_name
john,
,alteringdoe
before_update ...
def this_is_before_update(a_set, some_dict):
if 'last_name' in some_dict:
some_dict['last_name'] += 'was_updated'
db.auth_user._before_update.append(lambda s,f: this_is_before_update(s,f))
>>> db.auth_user.insert(first_name='john', last_name='doe')
1L
>>> db(db.auth_user.first_name=='john').update(last_name='white')
1
>>> rtn = db(db.auth_user.id>0).select(db.auth_user.first_name, db.auth_user
.last_name)
>>> print str(rtn)
auth_user.first_name,auth_user.last_name
john,whitewas_updated
--
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.