For checking if the server is up from the client browser (without
refreshing the page) you can use jQuery .ajax() and a simple function
at the controller to return the server state. I have submitted a LOAD
helper enhancement to perform a ajax loop at the client side. It could
be used for this purpose also (by defining an iterative javascript
routine in a .load view)

The inverse case is more difficult. Your operating system should write
a sentry file before turning off for the web2py app to check it in a
cron task or you could examine the system environment for checking the
status from the web2py app also.

Another way would be to have an operating system script to fire on
shut down with a web request to the web2py application. The web2py app
should implement a listener to perform the required actions before
system shut down.

On Feb 28, 7:55 am, Sanjeet Kumar <sanjeet....@gmail.com> wrote:
> I am going to develop the time sheet app so for that i captured the login
> and logout event through this :-
> auth.settings.login_onaccept = lambda form: lgin(form)
> auth.settings.logout_onlogout = lambda usr: lgout(usr)
>
> and one more question in my mind when the browser will be closed by some
> reasons and the system will be shut-down due to power loss that time how we
> capture the event and will show it logout and update our database following
> is my database and the controller :-
>
> database:-
>
> db.define_table('employee_login_detail',
>                 Field('employee_id'),
>                 Field('employee_name'),
>                 Field('employee_login_date'),
>                 Field('employee_login_time'),
>                 Field('employee_logout_date',default='Logged in'),
>                 Field('employee_logout_time',default='Logged in'),
>                 Field('total_minutes',default='Logged in'))
>
> Controller:-
>
> def lgin(form):
>     import datetime
>     import time
>     currentdate=datetime.date.today()
>     now = time.localtime(time.time())
>     starttime = datetime.datetime.now()
>     session.starttime = starttime
>     currenttime = time.strftime("%H:%M:%S", now)
>     session.time = currenttime
>     for row in db(db.auth_user.email ==
> auth.user.email).select(db.auth_user.first_name):
>         firstname=row.first_name
>     db.employee_login_detail.insert(employee_id = auth.user.email,
> employee_name=firstname, employee_login_date=currentdate,
> employee_login_time=currenttime)
>     return ''
>
> def lgout(usr):
>     import datetime
>     import time
>     currentdate=datetime.date.today()
>     now = time.localtime(time.time())
>     endtime=datetime.datetime.now()
>     starttime = session.starttime
>     delta = (endtime - starttime)
>     totalminutes = str(delta.seconds / 60)
>     currenttime = time.strftime("%H:%M:%S", now)
>     db((db.employee_login_detail.employee_id == auth.user.email) &
> (db.employee_login_detail.employee_login_date == currentdate) &
> (db.employee_login_detail.employee_login_time ==
> session.time)).update(employee_logout_date=currentdate,
> employee_logout_time=currenttime, total_minutes=totalminutes)
>     return ''

Reply via email to