Check "if other user is logged in"

110 views
Skip to first unread message

Abhijeet Rastogi

unread,
Apr 6, 2011, 3:05:57 PM4/6/11
to django...@googlegroups.com
I have implemented two types of users using:-

    class UserProfile(models.Model):
            user = models.ForeignKey(User)
            is_counter = models.BooleanField()
            is_student = models.BooleanField()

So, a user can either be a student or counter. Basically, I have a project something like student will order food & at counter side, counter user will get the notification to prepare food.

Now, if the counter user is logged out, I dont want to allow student to order that food. For that I have to somehow check if counter user is logged in. Is it possible?
From what I feel, adding a bool field & making it True when counter user logs in and making it false when counter user logs out; is not a solution. The reason being that "what if a counter user gets disconnected somehow (or closes browser without logging out).

--
Regards,
Abhijeet Rastogi (shadyabhi)
http://www.google.com/profiles/abhijeet.1989

Shawn Milochik

unread,
Apr 6, 2011, 3:26:22 PM4/6/11
to django...@googlegroups.com
Just to be pedantic, your model allows someone to be both a student
and a counter at the same time. If they must be mutually exclusive
then you can create one CharField which uses an iterable of choices,
or add custom code to your save() (and your modelform) to require
compliance.

Unfortunately, there's no guaranteed way to know if a user is still
logged in just by the session. If you're using Comet you can be pretty
sure, depending on how quickly the Comet backend becomes aware of an
unsubscribe action. With AJAX you could do some kind of regular
check-in, but that solution sucks. Otherwise, if a person requests a
page on your site (refreshing their "last seen" status), they can
close their browser immediately after and you wouldn't know.

Shawn

Abhijeet Rastogi

unread,
Apr 6, 2011, 4:06:08 PM4/6/11
to django...@googlegroups.com, Shawn Milochik
Thanks Shawn for your reply. I was afraid if that was the only way. Anyways, I implemented using AJAX only. I already had a AJAX request being made from counter side every 3 seconds.

https://github.com/shadyabhi/pycourt_login/commit/e8303fe6a07761066a75226f7cd6dcb6d3c296f7

Thanks for that point. I didnt think about that. Anyways, its not a peoblem for my site because its only the student that registers, not the counter. Registering the counter is only done once using admin interface at the time of being deployed.

Still, I will check that condition too. That would be a learning exercise for me as I am just a beginner in web development.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages