Implement user status display

This commit is contained in:
Kumi 2019-02-01 08:19:18 +00:00
parent 7476c08529
commit d175fbcb38
3 changed files with 19 additions and 8 deletions

View file

@ -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 "<!-- %s -->" % updateUserStatus(user, True)
return "Unresolved IndexError"
except Exception as e:
return "<!-- %s -->" % str(e)
return ""

View file

@ -12,7 +12,8 @@
{% load static %}
{% load repo %}
{% load userstatus %}
{% updateUserStatus user %}
{% block header %}
{% endblock %}

View file

@ -74,7 +74,7 @@
<tr>
<th>Username</th>
<th>Real name</th>
<th>Last Login</th>
<th>Last Activity</th>
<th>Options</th>
</tr>
</thead>
@ -83,7 +83,7 @@
<tr>
<td><div style="display:inline;" {% if user.is_superuser %}title="{% for orga in auser.organizations %}{{ orga }}&#10;{% endfor %}"{% endif %}>{% if auser.is_staff %}<b>{% endif %}{{ auser.username }}{% if auser.is_staff %}</b>{% endif %}</div></td>
<td>{% if auser.is_staff %}<b>{% endif %}{{ auser.first_name }} {{ auser.last_name }}{% if auser.is_staff %}</b>{% endif %}</td>
<td>{{ auser.last_login }}</td>
<td>{{ auser.userstatus.last_action }}</td>
<td><a href="/user/{{ auser.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a> {% if auser.email %}<a href="mailto:{{ auser.email }}"><i class="fas fa-envelope" title="Send Email"></i></a>{% endif %}</td>
</tr>
{% endfor %}