Here : http://www.web2pyslices.com/slice/show/1618/basic-usage-statistics-log-what-your-users-do
Richard On Tue, Apr 23, 2013 at 4:17 PM, Richard Vézina <[email protected] > wrote: > I know, I was searching to make sure I can log delete event before... > > But thanks for the invitation, I do... > > Richard > > > On Tue, Apr 23, 2013 at 3:54 PM, Derek <[email protected]> wrote: > >> Be sure to put stuff like this that you want to share on >> http://www.web2pyslices.com <http://www.web2pyslices.com/home>. >> Searching the group for neat tricks is not something people generally do. >> >> >> On Tuesday, April 23, 2013 6:21:33 AM UTC-7, Richard wrote: >> >>> Of course, what could be done, make a variable container and differt the >>> insert? >>> >>> For my usage as far as I can see a db insert on each request is not the >>> bottle neck... >>> >>> But I understand for a bigger project it could be not praticable... >>> >>> Thanks >>> >>> Richard >>> >>> >>> On Tue, Apr 23, 2013 at 8:50 AM, Anthony <[email protected]> wrote: >>> >>>> I suppose because it does a db insert on every request. >>>> >>>> >>>> On Tuesday, April 23, 2013 8:26:53 AM UTC-4, Richard wrote: >>>> >>>>> Guruyaya, could you explain why, to you, this basic simple usage stats >>>>> is unefficiant. >>>>> >>>>> Thanks >>>>> >>>>> Richard >>>>> >>>>> >>>>> On Tue, Apr 23, 2013 at 12:26 AM, guruyaya <[email protected]> wrote: >>>>> >>>>>> The idea seems extremly unefficiant. Wouldn't it make more sense to >>>>>> build it from logs, on a seperate machine? >>>>>> >>>>>> >>>>>> On Tuesday, April 23, 2013 1:08:02 AM UTC+3, Richard wrote: >>>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> I want to share this little snippet : >>>>>>> >>>>>>> # MODEL >>>>>>> >>>>>>> # Statistics of utilisation >>>>>>> db.define_table('usage_**statist****ics', >>>>>>> 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','**st****ring', >>>>>>> default=request.controller), >>>>>>> Field('request_function','**stri****ng', >>>>>>> default=request.function), >>>>>>> Field('request_extension','**str****ing', >>>>>>> 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','**stri****ng', >>>>>>> default=request.env.http_**accep****t_language), >>>>>>> Field('description', 'text'), >>>>>>> migrate=False, >>>>>>> ) >>>>>>> >>>>>>> # CONTROLLER >>>>>>> >>>>>>> def select(): >>>>>>> """ >>>>>>> Display log event into usage_statistics table. >>>>>>> """ >>>>>>> db.usage_statistics.id.**readabl****e = False >>>>>>> table = SQLFORM.grid(db.usage_**statisti****cs, >>>>>>> orderby=~db.usage_statistics.**t****ime_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 web2py+un...@**googlegroups.com. >>>>>> >>>>>> For more options, visit >>>>>> https://groups.google.com/**grou**ps/opt_out<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 web2py+un...@**googlegroups.com. >>>> For more options, visit >>>> https://groups.google.com/**groups/opt_out<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. >> >> >> > > -- --- 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.

