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
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
[(<pydal.objects.Field object at 0x11eb9ad10>, datetime.datetime(2015, 5, 29, 6, 32, 27, 732420)), (<pydal.objects.Field object at 0x1334a5150>, 1L), (<pydal.objects.Field object at 0x1334a5290>, 8L), (<pydal.objects.Field object at 0x1334a5390>, 2L), (<pydal.objects.Field object at 0x11c2dfcd0>, 5.0), (<pydal.objects.Field object at 0x1334a57d0>, 14093L), (<pydal.objects.Field object at 0x1334a5b10>, 'APPEAL'), (<pydal.objects.Field object at 0x1334a5050>, 1L), (<pydal.objects.Field object at 0x1334a5410>, 358001L), (<pydal.objects.Field object at 0x11eb9a4d0>, datetime.datetime(2015, 5, 29, 6, 32, 27, 732420)), (<pydal.objects.Field object at 0x1334a53d0>, 5.0), (<pydal.objects.Field object at 0x1334a5690>, True), (<pydal.objects.Field object at 0x1334a55d0>, 1L)]
{'query_group': 1, 'name': 'asddasdasdasdsada', 'created_date': datetime.datetime(2015, 5, 29, 6, 27, 37, 2291), 'run_order': 0, 'type': '', 'sum_description': '', 'created_by': 1L}
db.income_line_item._before_insert.append(lambda f: trigger_ili_before_insert(f))
db.query._before_insert.append(lambda f: query_before_test(f))
new_ilis = []
...
new_ili = { 'income': this_rg.template_income, 'income_coding': rgli.income_coding, 'amount_item': rgli.amount_item, 'quantity': rgli.quantity, 'income_source': rgli.income_source, 'source_agency': rgli.source_agency, 'source_type': rgli.source_type } new_ilis.append(new_ili)
...
db.income_line_item.bulk_insert(new_ilis)