Re: [web2py] Recompute all instances of a computed field
On 10 July 2014 15:50, Fabiano Almeida fabi...@techno7.com.br wrote: Congratulations! Thanks but I do not deserve the congratulation. I was helped by somebody on this list years ago to update computed fields. Unfortunately I cannot recall the name now. I think I just added the counter for my own purposes. Regards Johann. -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Recompute all instances of a computed field
Try: #!/usr/bin/python # -*- coding: utf-8 -*- rows = db(db.urlop.id 0).select(db.urlop.ilosc_dni,db.termin_od, db.termin_do) howmany = len(rows) busy_with = 0 for row in rows: busywith += 1 print 'busy with %d of %d' % (busywith, howmany) On 19 June 2014 18:29, Tomasz Sokołowski orbitalny...@gmail.com wrote: Hello Recently I have upgraded the function dni_urlopu() which is used in a computed field in the table urlop. How can I recompute/refresh all instances of already existing records which where not properly compute because of error in previous version of function dni_urlopu() Best regards, Tomek def dni_urlopu(termin_od, termin_do): return workdays.networkdays(termin_od, termin_do, [datetime.date(year=2014,month=01,day=01), datetime.date(year=2014,month=01,day=06), datetime.date(year=2014,month=04,day=21), datetime.date(year=2014,month=05,day=01), datetime.date(year=2014,month=06,day=19), datetime.date(year=2014,month=07,day=15), datetime.date(year=2014,month=11,day=11), datetime.date(year=2014,month=12,day=25), datetime.date(year=2014,month=12,day=26)]) db.define_table('urlop', Field('user_id', db.auth_user, default=auth.user_id, writable=True, label='Pracownik' ), Field('urlop_typ', 'string', requires=IS_IN_SET(URLOP_SET), label='Rodzaj urlopu'), Field('termin_od', 'date', label='Termin od'), Field('termin_do', 'date', label='Termin do'), Field('ilosc_dni', compute=lambda r: dni_urlopu(r['termin_od'], r['termin_do']), label='Ilość dni'), Field('uzasadnienie_urlop', 'text', label='Uzasadnienie'), Field('status', requires=IS_IN_SET(STATUS_SET), default=STATUS_SET[0], label='Status'), auth.signature) -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Recompute all instances of a computed field
Sorry, I sent it before finishing #!/usr/bin/python # -*- coding: utf-8 -*- rows = db(db.urlop.id 0).select(db.urlop.ilosc_dni, db.termin_od, db.termin_do) howmany = len(rows) busy_with = 0 for row in rows: busywith += 1 print 'busy with %d of %d' % (busywith, howmany) row.update_record(ulosc_dni = db.urlop.ulosc_dni.compute(row)) db.commit() Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Recompute all instances of a computed field
Hi Johann, I recently update manually compute field. You have presented a better way, and still counter to monitor the process. Very nice! Congratulations! Fabiano. 2014-07-10 10:39 GMT-03:00 Johann Spies johann.sp...@gmail.com: Sorry, I sent it before finishing #!/usr/bin/python # -*- coding: utf-8 -*- rows = db(db.urlop.id 0).select(db.urlop.ilosc_dni, db.termin_od, db.termin_do) howmany = len(rows) busy_with = 0 for row in rows: busywith += 1 print 'busy with %d of %d' % (busywith, howmany) row.update_record(ulosc_dni = db.urlop.ulosc_dni.compute(row)) db.commit() Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Recompute all instances of a computed field
Hello Recently I have upgraded the function dni_urlopu() which is used in a computed field in the table urlop. How can I recompute/refresh all instances of already existing records which where not properly compute because of error in previous version of function dni_urlopu() Best regards, Tomek def dni_urlopu(termin_od, termin_do): return workdays.networkdays(termin_od, termin_do, [datetime.date(year=2014,month=01,day=01), datetime.date(year=2014,month=01,day=06), datetime.date(year=2014,month=04,day=21), datetime.date(year=2014,month=05,day=01), datetime.date(year=2014,month=06,day=19), datetime.date(year=2014,month=07,day=15), datetime.date(year=2014,month=11,day=11), datetime.date(year=2014,month=12,day=25), datetime.date(year=2014,month=12,day=26)]) db.define_table('urlop', Field('user_id', db.auth_user, default=auth.user_id, writable=True, label='Pracownik' ), Field('urlop_typ', 'string', requires=IS_IN_SET(URLOP_SET), label='Rodzaj urlopu'), Field('termin_od', 'date', label='Termin od'), Field('termin_do', 'date', label='Termin do'), Field('ilosc_dni', compute=lambda r: dni_urlopu(r['termin_od'], r['termin_do']), label='Ilość dni'), Field('uzasadnienie_urlop', 'text', label='Uzasadnienie'), Field('status', requires=IS_IN_SET(STATUS_SET), default=STATUS_SET[0], label='Status'), auth.signature) -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.