you need do use websockets (gluon/contrib/comet_messaging.py)

On Feb 28, 4: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