I have the following auth.settings :
# log system events
auth.settings.login_onaccept = lambda form:logactivity('Login','none')
auth.settings.profile_onaccept = lambda form:logactivity('Update
Profile','none')
auth.settings.register_onaccept = lambda form:logactivity('Register','none')
which call the following function:
def logactivity(action, details):
db.log.insert(action=action, details=details)
return True
The log table is defined as follows:
#----------------------Log-------------------------------
db.define_table('log',
Field('action'),
Field('details'),
Field('created_by',db.auth_user,readable=False,writable=False),
Field('created_on','datetime',default=request.now,
readable=False,writable=False),
migrate=migrate_db)
db.log.action.requires = IS_NOT_EMPTY()
db.log.details.requires = IS_NOT_EMPTY()
if auth.is_logged_in():
db.log.created_by.default = auth.user.id
The problem is the *created_by* field is not being set to the logged in
user, but rather non. The weird thing is the *created_on* is being set
properly. I suspect this has something to do with timing, but the
documentation says onaccept happens after IO so I expected the auth.user
object to be fully populated. And ideas how I can fix this so the login
action is logged in the table?