Need Advise on the best way to track how much time a user is logged in.....

62 views
Skip to first unread message

7equiv...@gmail.com

unread,
Aug 22, 2013, 10:06:49 AM8/22/13
to django...@googlegroups.com
I have created a model that gives me a time stamp  when a user logs in. I connected the 'user_logged_in signal' to a function:

def update_user_login(sender, user), **kwargs):
    user.userlogin_set.create(timestamp=user.last_login)
    user.save()

So this basically helps me track the login time, but how do I set the timestamp to the last_logout? There is no last_logout attribute like there is with last_login?

Tom Evans

unread,
Aug 22, 2013, 10:22:21 AM8/22/13
to django...@googlegroups.com
You cannot. The only thing you can do is to try and identify sessions.
A session starts when someone logs in, and stops when they stop using
the site.

Since a session only ends when someone stops using the site, the end
of a session cannot be recorded during a request, and therefore
session/usage analysis must be done outside of the request-response
life cycle.

IE, this needs to be a separate application that analyses the time and
user information that you log on each request.

Cheers

Tom

7equiv...@gmail.com

unread,
Aug 22, 2013, 10:46:25 AM8/22/13
to django...@googlegroups.com, teva...@googlemail.com
 I notice the Django.contrib.Auth has a logout function, is there anyway to connect a timestamp to a model when the user uses the logout function? My users will be using the log out function. This is for a time clock I'm building using RFID tags.

7equiv...@gmail.com

unread,
Aug 22, 2013, 3:09:45 PM8/22/13
to django...@googlegroups.com, teva...@googlemail.com
My users will not be able to logout by closing a browser because they have no such interaction with the system. They will be passing an RFID tag over a reader to unlock the door and clock in and a python script will handle the loging in and out. So if I can get the logout to time stamp a database entry I'll be good.

Anurag Chourasia

unread,
Aug 22, 2013, 3:22:15 PM8/22/13
to django...@googlegroups.com, teva...@googlemail.com
So they will present the RFID Tag to the reader at the time of login .....and logout also? You could do this directly in Python then....Capture the logout read (same way as login) and use the datetime module to generate the current time and save it in the Database.

Just trying to understand what is the Django bit here?

Regards,
Anurag



On Thu, Aug 22, 2013 at 3:09 PM, <7equiv...@gmail.com> wrote:
My users will not be able to logout by closing a browser because they have no such interaction with the system. They will be passing an RFID tag over a reader to unlock the door and clock in and a python script will handle the loging in and out. So if I can get the logout to time stamp a database entry I'll be good.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Huu Da Tran

unread,
Aug 23, 2013, 5:42:08 AM8/23/13
to django...@googlegroups.com, teva...@googlemail.com
On Thursday, August 22, 2013 3:09:45 PM UTC-4, 7equiv...@gmail.com wrote:
My users will not be able to logout by closing a browser because they have no such interaction with the system. They will be passing an RFID tag over a reader to unlock the door and clock in and a python script will handle the loging in and out. So if I can get the logout to time stamp a database entry I'll be good.

Am I just missing your point or you are actually defining a website with a login function and a logout function? If so, in the view for login, just call

    user.userlogin_set.create(timestamp=datetime.datetime.utcnow())

and in the logout view, just call

    user.userlogout_set.create(timestamp=datetime.datetime.utcnow())


Reply all
Reply to author
Forward
0 new messages