trying to import *.csv with before insert callback not work correctly (no
error occured but the result is not expected)
*e.g. *
*csv_files_0.csv*
TABLE bonus
bonus.bonus_date,bonus.employee,bonus.is_packing
2016-11-10,4,1
END
*csv_files_1.csv*
TABLE bonus
bonus.bonus_date,bonus.employee,bonus.is_packing
2016-11-11,4,T
END
*csv_files_2.csv*
TABLE bonus
bonus.bonus_date,bonus.employee,bonus.is_packing
2016-11-12,4,True
END
*models/db.py*
def __before_insert_bonus(f):
chosen_employee = db(db.employee.id == f['employee'] ).iterselect().first()
if f['is_packing'] == True:
f['packing'] = 1 * chosen_employee.packing
else:
f['packing'] = 0 * chosen_employee.packing
db.define_table('bonus',
Field('bonus_date', 'date'),
Field('employee', 'reference employee'),
Field('is_packing', 'boolean'),
Field('packing', 'integer'),
format = lambda r: '%s - %s %s' % (r.bonus_date, r.employee.first_name,
r.employee.last_name) )
db.bonus._before_insert.append(__before_insert_bonus)
any idea how to handle it using web2py way?
thanks and best regards,
stifan
--
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.