class OnlineMiddleware object def process_request self request if requ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class OnlineMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
request.user.last_login = datetime.datetime.now()
request.user.ip = request.META['REMOTE_ADDR']
request.user.save()
if not get_object_or_None(Online, user=request.user):
Online.objects.create(user=request.user)
users = Online.objects.all()
online_minimum = datetime.datetime.now() - datetime.timedelta(minutes=15)
for user in users:
if user.user.last_login < online_minimum:
user.delete()