Your first suggestion's clever, and not too hard to extend. Have a list of
admin functions, check if request.function is in it.
At the moment, I've got a disabling routine, and pass all the table names:
def suppress_timestamp(*tables):
#Stop updating of modified_on and _by, given a list of tables
(strings)
for table in tables:
try:
idb[table_name].modified_on.update = None
idb[table_name].modified_by.update = None
except:
pass
On Tuesday, 27 January 2015 19:31:00 UTC, Anthony wrote:
>
> I think you can take two approaches. One option would be to conditionally
> set the update attribute depending on the request:
>
> Field('modified_on', 'datetime',
> update=request.now if request.function != 'admin_routine' else
> None, ...)
>
> The other approach is to pass in the current value when doing the update
> in the admin routine:
>
> def admin_routine:
> ...
> idb.student(source.id).address.update(student=target.id,
> modified_on=idb.student.address)
>
> Anthony
>
> On Tuesday, January 27, 2015 at 9:48:54 AM UTC-5, [email protected]
> wrote:
>>
>> I'm really liking the ability to automatically timestamp when records are
>> updated, but I'm wondering if there's a simple way of suppressing this
>> behaviour when needed:
>>
>> I have these signature fields appended to a number of tables,
>> automatically recording when users update records:
>> signature_fields = idb.Table(
>> idb, 'signature_fields', #Dummy table, not actually in the db
>> Field('created_on', 'datetime',
>> default=request.now,
>> writable=False, readable=False,
>> label='Created on'),
>> Field('created_by', 'string',
>> default=auth.user.username
>> writable=False, readable=False,
>> label='Created by'),
>> Field('modified_on', 'datetime',
>> update=request.now, default=request.now,
>> writable=False, readable=False,
>> label='Modified on'),
>> Field('modified_by', 'string',
>> default=auth.user.username, update=signature_username,
>> writable=False, readable=False,
>> label='Modified by'),
>> )
>>
>> For example:
>>
>> idb.define_table(
>> 'address',
>> Field('id', 'id', readable=False),
>> Field('student', idb.student, readable=False, writable=False),
>> Field('line1', 'string'),
>> Field('line2', 'string'),
>> Field('line3', 'string'),
>> Field('town', 'string'),
>> Field('countystate', 'string'),
>> Field('country', 'string'),
>> Field('postcode', 'string'),
>> signature_fields
>> )
>>
>> But I have an admin routine that allows me to move addreses to another
>> student, and I don't want the timestamping to occur when I run:
>> idb.student(source.id).address.update(student=target.id)
>>
>> Is there a simple way to suppress automatic update values? e.g.:
>> idb.student(source.id).address.update(student=target.id,
>> _defaults=False)
>>
>> I know I can disable them one by one before running the queries, but
>> it'll add lots of boilerplate a la:
>> idb.address.modified_on.update = idb.address.modified_by.update = None
>>
>>
>>
>>
--
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.