Thank Anthony for your input...

Of course, it make it maybe more managebale to include the insert in
controller... In model, I don't know if it could allow me to get the LOAD
event.

I still search for a way to catch delete event thougt.

Richard


On Mon, Apr 22, 2013 at 10:19 PM, Anthony <[email protected]> wrote:

> It would probably make more sense to do the inserts in the model or
> controller. Also, no need to call db.commit(), unless you want to count the
> visit even if there is an error later in the request.
>
> Anthony
>
>
> On Monday, April 22, 2013 6:08:02 PM UTC-4, Richard wrote:
>>
>> Hello,
>>
>> I want to share this little snippet :
>>
>> # MODEL
>>
>> # Statistics of utilisation
>> db.define_table('usage_**statistics',
>>     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'),
>>     migrate=False,
>>     )
>>
>> # CONTROLLER
>>
>> 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)
>>
>> # VIEWS
>>
>> # 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!!
>>
>> {{db.usage_statistics.insert()**}}
>> {{db.commit()}}
>>
>> *Only thing I didn't figured out yet is what the best way to log delete
>> event... I thought about that :*
>>
>> # Not tested and pseudo code
>> def myeventlogcall(form)
>>     if form.delete:
>>         db.usage_statistics.insert()
>>         db.commit()
>>
>> def update_functions():
>> ...
>>      form.process(ondelete=myevent**logcall)
>> ...
>>
>> But, it makes things complicated if case there is already ondelete in an
>> update_function...
>>
>> Any suggestion is welcome.
>>
>> Thanks
>>
>> Richard
>>
>>  --
>
> ---
> 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/groups/opt_out.
>
>
>

-- 

--- 
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/groups/opt_out.


Reply via email to