Display the relative time on mouse hover

This commit is contained in:
Jeremy Stretch 2024-04-16 15:57:12 -04:00
parent 510f1326e6
commit c580a5399f
7 changed files with 19 additions and 53 deletions

View File

@ -35,15 +35,7 @@
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Last Login" %}</th> <th scope="row">{% trans "Last Login" %}</th>
<td> <td>{{ request.user.last_login|isodatetime:"minutes"|placeholder }}</td>
{% if request.user.last_login %}
<span title="{{ object.last_login|isodatetime:"minutes" }}">
{{ request.user.last_login|timesince }} {% trans "ago" %}
</span>
{% else %}
{{ ''|placeholder }}
{% endif %}
</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Superuser" %}</th> <th scope="row">{% trans "Superuser" %}</th>

View File

@ -49,16 +49,7 @@
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Last used" %}</th> <th scope="row">{% trans "Last used" %}</th>
<td> <td>{{ object.last_used|isodatetime|placeholder }}</td>
{% if object.last_used %}
<span title="{{ object.last_used|isodatetime }}">
{{ object.last_used|timesince }}
</span>
{% trans "ago" %}
{% else %}
{{ ''|placeholder }}
{% endif %}
</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Allowed IPs" %}</th> <th scope="row">{% trans "Allowed IPs" %}</th>

View File

@ -1,4 +1,3 @@
{% load humanize %}
{% load helpers %} {% load helpers %}
{% load log_levels %} {% load log_levels %}
{% load i18n %} {% load i18n %}
@ -8,7 +7,7 @@
{% if job.started %} {% if job.started %}
{% trans "Started" %}: <strong>{{ job.started|isodatetime }}</strong> {% trans "Started" %}: <strong>{{ job.started|isodatetime }}</strong>
{% elif job.scheduled %} {% elif job.scheduled %}
{% trans "Scheduled for" %}: <strong>{{ job.scheduled|isodatetime }}</strong> ({{ job.scheduled|naturaltime }}) {% trans "Scheduled for" %}: <strong>{{ job.scheduled|isodatetime }}</strong>
{% else %} {% else %}
{% trans "Created" %}: <strong>{{ job.created|isodatetime }}</strong> {% trans "Created" %}: <strong>{{ job.created|isodatetime }}</strong>
{% endif %} {% endif %}

View File

@ -51,11 +51,7 @@ Context:
{% trans "Created" %} {{ object.created|isodatetime:"minutes" }} {% trans "Created" %} {{ object.created|isodatetime:"minutes" }}
{% if object.last_updated %} {% if object.last_updated %}
<span class="separator">&middot;</span> <span class="separator">&middot;</span>
{% trans "Updated" %} {% trans "Updated" %} {{ object.last_updated|isodatetime:"minutes" }}
<span title="{{ object.last_updated|isodatetime:"minutes" }}">
{{ object.last_updated|timesince }}
</span>
{% trans "ago" %}
{% endif %} {% endif %}
</div> </div>
{% endblock subtitle %} {% endblock subtitle %}

View File

@ -1,6 +1,6 @@
{% extends 'generic/object.html' %} {% extends 'generic/object.html' %}
{% load i18n %}
{% load helpers %} {% load helpers %}
{% load i18n %}
{% load render_table from django_tables2 %} {% load render_table from django_tables2 %}
{% block title %}{% trans "Token" %} {{ object }}{% endblock %} {% block title %}{% trans "Token" %} {{ object }}{% endblock %}
@ -37,20 +37,11 @@
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Expires" %}</th> <th scope="row">{% trans "Expires" %}</th>
<td>{{ object.expires|isodatetime }}</td> <td>{{ object.expires|isodatetime|placeholder }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Last used" %}</th> <th scope="row">{% trans "Last used" %}</th>
<td> <td>{{ object.last_used|isodatetime|placeholder }}</td>
{% if object.last_used %}
<span title="{{ object.last_used|isodatetime }}">
{{ object.last_used|timesince }}
</span>
{% trans "ago" %}
{% else %}
{{ ''|placeholder }}
{% endif %}
</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Allowed IPs" %}</th> <th scope="row">{% trans "Allowed IPs" %}</th>

View File

@ -31,15 +31,7 @@
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Last Login" %}</th> <th scope="row">{% trans "Last Login" %}</th>
<td> <td>{{ object.last_login|isodatetime:"minutes"|placeholder }}</td>
{% if object.last_login %}
<span title="{{ object.last_login|isodatetime:"minutes" }}">
{{ object.last_login|timesince }} {% trans "ago" %}
</span>
{% else %}
{{ ''|placeholder }}
{% endif %}
</td>
</tr> </tr>
<tr> <tr>
<th scope="row">{% trans "Active" %}</th> <th scope="row">{% trans "Active" %}</th>

View File

@ -5,6 +5,7 @@ import re
import yaml import yaml
from django import template from django import template
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.humanize.templatetags.humanize import naturaltime
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from markdown import markdown from markdown import markdown
@ -214,10 +215,12 @@ def render_yaml(value):
@register.filter() @register.filter()
def isodate(value): def isodate(value):
if type(value) is datetime.date: if type(value) is datetime.date:
return value.isoformat() text = value.isoformat()
if type(value) is datetime.datetime: elif type(value) is datetime.datetime:
return value.date().isoformat() text = value.date().isoformat()
return '' else:
return ''
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
@register.filter() @register.filter()
@ -232,5 +235,7 @@ def isotime(value, spec='seconds'):
@register.filter() @register.filter()
def isodatetime(value, spec='seconds'): def isodatetime(value, spec='seconds'):
if type(value) is datetime.datetime: if type(value) is datetime.datetime:
return f'{isodate(value)} {isotime(value, spec=spec)}' text = f'{isodate(value)} {isotime(value, spec=spec)}'
return '' else:
return ''
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')