From d175fbcb385fe903f7934011b421c38475db5be9 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 1 Feb 2019 08:19:18 +0000 Subject: [PATCH] Implement user status display --- manager/templatetags/userstatus.py | 20 +++++++++++++++----- templates/base.html | 3 ++- templates/manager/index.html | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/manager/templatetags/userstatus.py b/manager/templatetags/userstatus.py index b2d8ab1..1026e04 100644 --- a/manager/templatetags/userstatus.py +++ b/manager/templatetags/userstatus.py @@ -6,8 +6,18 @@ from django.utils import timezone register = template.Library() @register.simple_tag -def updateUserStatus(user): - try: - UserStatus.objects.filter(user=user)[0].last_action = timezone.now() - except: - pass +def updateUserStatus(user, sec = False): + if user.is_authenticated: + try: + status = UserStatus.objects.filter(user=user)[0] + status.last_action = timezone.now() + status.save() + return "" + except IndexError: + if not sec: + UserStatus.objects.create(user=user) + return "" % updateUserStatus(user, True) + return "Unresolved IndexError" + except Exception as e: + return "" % str(e) + return "" diff --git a/templates/base.html b/templates/base.html index 63b18e5..6d7f962 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,7 +12,8 @@ {% load static %} {% load repo %} - + {% load userstatus %} + {% updateUserStatus user %} {% block header %} {% endblock %} diff --git a/templates/manager/index.html b/templates/manager/index.html index ccb94c3..57ac89c 100644 --- a/templates/manager/index.html +++ b/templates/manager/index.html @@ -74,7 +74,7 @@ Username Real name - Last Login + Last Activity Options @@ -83,7 +83,7 @@
{% if auser.is_staff %}{% endif %}{{ auser.username }}{% if auser.is_staff %}{% endif %}
{% if auser.is_staff %}{% endif %}{{ auser.first_name }} {{ auser.last_name }}{% if auser.is_staff %}{% endif %} - {{ auser.last_login }} + {{ auser.userstatus.last_action }} {% if auser.email %}{% endif %} {% endfor %}