Hi Anthony,
The proposal does not work as is. It looks like there is
no request.vars._formname.
P.S. : There is a small typo : request.vars._formname.startswith(...
However, with strong inspiration of your solution I made some additonal
tests and found a compute function that perfectly works :
compute=lambda row: db.t_templates(request.vars.id).f_revision + 1 if (
request.vars.id and db.t_templates(request.vars.id).f_revision) else 1,
Super thanks Anthony. I'll use this solution as I prefer to have it on the
DAL.
Le mardi 1 mai 2012 15:48:06 UTC+2, Anthony a écrit :
>
> I think the row object submitted to the compute function only includes the
> fields that are part of the update, so it won't include row['f_revision'].
> Instead, you could get the record id from request.vars and use that to
> query the current value of the f_revision field:
>
> db.define_table('t_templates', Field('name'),
> Field('f_template', 'upload', label=T('File'), notnull=True),
> Field('f_revision', 'integer', label=T('Revision'),
> compute=lambda: db.t_templates(request.vars.id).f_revision + 1 if
> (request.vars.id and
> request.vars._formname and request.vars_formname.startswith(
> 't_templates')) else 1))
>
> Anthony
>
> On Tuesday, May 1, 2012 7:31:43 AM UTC-4, François Delpierre wrote:
>>
>> Hi,
>>
>> Here is exactly what I would like to have, but it does not compute on
>> update :
>>
>> db.define_table('t_templates',
>> Field('f_template', type='upload', label=T('File'),notnull=True),
>>
>>
>> Field('f_revision', type='integer', label=T('Revision'),
>> default=1,
>> compute=lambda row: row['f_revision']+1 ,
>> ),
>> )
>>
>>