If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!


# Ex.: usage_statistics.py
# Statistics of utilisation
    Field('time_stamp','datetime', default=request.now),
    Field('client_ip','string', default=request.client),
    Field('user_id', 'reference auth_user', default=auth.user and auth.user.id),
    Field('request_controller','string', default=request.controller),
    Field('request_function','string', default=request.function),
    Field('request_extension','string', default=request.extension),
    Field('request_ajax','string', default=request.ajax),
    Field('request_args','string', default=request.args),
    Field('request_vars','string', default=request.vars),
    Field('request_view','string', default=request.view),
    Field('request_http_user_agent','string', default=request.env.http_user_agent),
    Field('request_language','string', default=request.env.http_accept_language),
    Field('description', 'text'),
def select():
    Display log event into usage_statistics table.
    db.usage_statistics.id.readable = False
    table = SQLFORM.grid(db.usage_statistics, orderby=~db.usage_statistics.time_stamp, ui='jquery-ui', formstyle = 'divs')
    return dict(table=table)
# Just put these two lines in ALL your views or only the views you want to log and you can log what your users do!!
NOTE: You may put db.usage_statistics.insert() in your controller functions and you may also just put it only in a model file.
NOTE2: db.commit() is not required
NOTE3: Some have said that this approach maybe impraticcable because it requires a db insert for each request... You are advised!

Related slices

Comments (3)

Hosting graciously provided by:
Python Anywhere