mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-15 20:18:17 -06:00
Introduce the isodate(), isotime(), and isodatetime() template filters
This commit is contained in:
parent
4e4c277711
commit
510f1326e6
@ -31,11 +31,19 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Account Created" %}</th>
|
<th scope="row">{% trans "Account Created" %}</th>
|
||||||
<td>{{ request.user.date_joined|annotated_date }}</td>
|
<td>{{ request.user.date_joined|isodate }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Last Login" %}</th>
|
<th scope="row">{% trans "Last Login" %}</th>
|
||||||
<td>{{ request.user.last_login|annotated_date }}</td>
|
<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>
|
||||||
|
@ -41,15 +41,24 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Created" %}</th>
|
<th scope="row">{% trans "Created" %}</th>
|
||||||
<td>{{ object.created|annotated_date }}</td>
|
<td>{{ object.created|isodatetime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Expires" %}</th>
|
<th scope="row">{% trans "Expires" %}</th>
|
||||||
<td>{{ object.expires|placeholder }}</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>{{ object.last_used|placeholder }}</td>
|
<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>
|
||||||
|
@ -45,11 +45,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Install Date" %}</th>
|
<th scope="row">{% trans "Install Date" %}</th>
|
||||||
<td>{{ object.install_date|annotated_date|placeholder }}</td>
|
<td>{{ object.install_date|isodate|placeholder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Termination Date" %}</th>
|
<th scope="row">{% trans "Termination Date" %}</th>
|
||||||
<td>{{ object.termination_date|annotated_date|placeholder }}</td>
|
<td>{{ object.termination_date|isodate|placeholder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Commit Rate" %}</th>
|
<th scope="row">{% trans "Commit Rate" %}</th>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
{% block subtitle %}
|
{% block subtitle %}
|
||||||
{% if object.created %}
|
{% if object.created %}
|
||||||
<div class="text-secondary fs-5">
|
<div class="text-secondary fs-5">
|
||||||
{% trans "Created" %} {{ object.created|annotated_date }}
|
{% trans "Created" %} {{ object.created|isodatetime }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock subtitle %}
|
{% endblock subtitle %}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
{% block subtitle %}
|
{% block subtitle %}
|
||||||
<div class="text-secondary fs-5">
|
<div class="text-secondary fs-5">
|
||||||
{% trans "Created" %} {{ object.created|annotated_date }}
|
{% trans "Created" %} {{ object.created|isodatetime }}
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -49,12 +49,12 @@
|
|||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Created" %}</th>
|
<th scope="row">{% trans "Created" %}</th>
|
||||||
<td>{{ object.created|annotated_date }}</td>
|
<td>{{ object.created|isodatetime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Scheduled" %}</th>
|
<th scope="row">{% trans "Scheduled" %}</th>
|
||||||
<td>
|
<td>
|
||||||
{{ object.scheduled|annotated_date|placeholder }}
|
{{ object.scheduled|isodatetime|placeholder }}
|
||||||
{% if object.interval %}
|
{% if object.interval %}
|
||||||
({% blocktrans with interval=object.interval %}every {{ interval }} minutes{% endblocktrans %})
|
({% blocktrans with interval=object.interval %}every {{ interval }} minutes{% endblocktrans %})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -62,11 +62,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Started" %}</th>
|
<th scope="row">{% trans "Started" %}</th>
|
||||||
<td>{{ object.started|annotated_date|placeholder }}</td>
|
<td>{{ object.started|isodatetime|placeholder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Completed" %}</th>
|
<th scope="row">{% trans "Completed" %}</th>
|
||||||
<td>{{ object.completed|annotated_date|placeholder }}</td>
|
<td>{{ object.completed|isodatetime|placeholder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
{% block subtitle %}
|
{% block subtitle %}
|
||||||
<div class="text-secondary fs-5">
|
<div class="text-secondary fs-5">
|
||||||
<span>{% trans "Created" %} {{ job.created_at|annotated_date }}</span>
|
<span>{% trans "Created" %} {{ job.created_at|isodatetime }}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endblock subtitle %}
|
{% endblock subtitle %}
|
||||||
|
|
||||||
@ -71,11 +71,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Created" %}</th>
|
<th scope="row">{% trans "Created" %}</th>
|
||||||
<td>{{ job.created_at|annotated_date }}</td>
|
<td>{{ job.created_at|isodatetime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Queued" %}</th>
|
<th scope="row">{% trans "Queued" %}</th>
|
||||||
<td>{{ job.enqueued_at|annotated_date }}</td>
|
<td>{{ job.enqueued_at|isodatetime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Status" %}</th>
|
<th scope="row">{% trans "Status" %}</th>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
{% block subtitle %}
|
{% block subtitle %}
|
||||||
<div class="text-secondary fs-5">
|
<div class="text-secondary fs-5">
|
||||||
<span>{% trans "Created" %} {{ worker.birth_date|annotated_date }}</span>
|
<span>{% trans "Created" %} {{ worker.birth_date|isodatetime }}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endblock subtitle %}
|
{% endblock subtitle %}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Birth" %}</th>
|
<th scope="row">{% trans "Birth" %}</th>
|
||||||
<td>{{ worker.birth_date|annotated_date }}</td>
|
<td>{{ worker.birth_date|isodatetime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Queues" %}</th>
|
<th scope="row">{% trans "Queues" %}</th>
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
<div class="htmx-container">
|
<div class="htmx-container">
|
||||||
<p>
|
<p>
|
||||||
{% if job.started %}
|
{% if job.started %}
|
||||||
{% trans "Started" %}: <strong>{{ job.started|annotated_date }}</strong>
|
{% trans "Started" %}: <strong>{{ job.started|isodatetime }}</strong>
|
||||||
{% elif job.scheduled %}
|
{% elif job.scheduled %}
|
||||||
{% trans "Scheduled for" %}: <strong>{{ job.scheduled|annotated_date }}</strong> ({{ job.scheduled|naturaltime }})
|
{% trans "Scheduled for" %}: <strong>{{ job.scheduled|isodatetime }}</strong> ({{ job.scheduled|naturaltime }})
|
||||||
{% else %}
|
{% else %}
|
||||||
{% trans "Created" %}: <strong>{{ job.created|annotated_date }}</strong>
|
{% trans "Created" %}: <strong>{{ job.created|isodatetime }}</strong>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if job.completed %}
|
{% if job.completed %}
|
||||||
{% trans "Duration" %}: <strong>{{ job.duration }}</strong>
|
{% trans "Duration" %}: <strong>{{ job.duration }}</strong>
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Created" %}</th>
|
<th scope="row">{% trans "Created" %}</th>
|
||||||
<td>{{ object.created|annotated_date }}</td>
|
<td>{{ object.created|isodatetime:"minutes" }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Created By" %}</th>
|
<th scope="row">{% trans "Created By" %}</th>
|
||||||
|
@ -29,9 +29,7 @@
|
|||||||
<table class="table table-hover attr-table">
|
<table class="table table-hover attr-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Time" %}</th>
|
<th scope="row">{% trans "Time" %}</th>
|
||||||
<td>
|
<td>{{ object.time|isodatetime }}</td>
|
||||||
{{ object.time|annotated_date }}
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "User" %}</th>
|
<th scope="row">{% trans "User" %}</th>
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
<td>{{ script.description|markdown|placeholder }}</td>
|
<td>{{ script.description|markdown|placeholder }}</td>
|
||||||
{% if last_job %}
|
{% if last_job %}
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'extras:script_result' job_pk=last_job.pk %}">{{ last_job.created|annotated_date }}</a>
|
<a href="{% url 'extras:script_result' job_pk=last_job.pk %}">{{ last_job.created|isodatetime }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% badge last_job.get_status_display last_job.get_status_color %}
|
{% badge last_job.get_status_display last_job.get_status_color %}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<li class="breadcrumb-item"><a href="{% url 'extras:script_list' %}">{% trans "Scripts" %}</a></li>
|
<li class="breadcrumb-item"><a href="{% url 'extras:script_list' %}">{% trans "Scripts" %}</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{% url 'extras:script_list' %}#module.{{ script.module }}">{{ script.module|bettertitle }}</a></li>
|
<li class="breadcrumb-item"><a href="{% url 'extras:script_list' %}#module.{{ script.module }}">{{ script.module|bettertitle }}</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{{ script.get_absolute_url }}">{{ script }}</a></li>
|
<li class="breadcrumb-item"><a href="{{ script.get_absolute_url }}">{{ script }}</a></li>
|
||||||
<li class="breadcrumb-item">{{ job.created|annotated_date }}</li>
|
<li class="breadcrumb-item">{{ job.created|isodatetime }}</li>
|
||||||
</ol>
|
</ol>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
@ -48,10 +48,14 @@ Context:
|
|||||||
|
|
||||||
{% block subtitle %}
|
{% block subtitle %}
|
||||||
<div class="text-secondary fs-5">
|
<div class="text-secondary fs-5">
|
||||||
<span>{% trans "Created" %} {{ object.created|annotated_date }}</span>
|
{% trans "Created" %} {{ object.created|isodatetime:"minutes" }}
|
||||||
{% if object.last_updated %}
|
{% if object.last_updated %}
|
||||||
<span class="separator">·</span>
|
<span class="separator">·</span>
|
||||||
<span>{% trans "Updated" %} <span title="{{ object.last_updated }}">{{ object.last_updated|timesince }}</span> {% trans "ago" %}</span>
|
{% trans "Updated" %}
|
||||||
|
<span title="{{ object.last_updated|isodatetime:"minutes" }}">
|
||||||
|
{{ object.last_updated|timesince }}
|
||||||
|
</span>
|
||||||
|
{% trans "ago" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock subtitle %}
|
{% endblock subtitle %}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Date Added" %}</th>
|
<th scope="row">{% trans "Date Added" %}</th>
|
||||||
<td>{{ object.date_added|annotated_date|placeholder }}</td>
|
<td>{{ object.date_added|isodate|placeholder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Description" %}</th>
|
<th scope="row">{% trans "Description" %}</th>
|
||||||
|
@ -33,15 +33,24 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Created" %}</th>
|
<th scope="row">{% trans "Created" %}</th>
|
||||||
<td>{{ object.created|annotated_date }}</td>
|
<td>{{ object.created|isodatetime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Expires" %}</th>
|
<th scope="row">{% trans "Expires" %}</th>
|
||||||
<td>{{ object.expires|placeholder }}</td>
|
<td>{{ object.expires|isodatetime }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Last used" %}</th>
|
<th scope="row">{% trans "Last used" %}</th>
|
||||||
<td>{{ object.last_used|placeholder }}</td>
|
<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>
|
||||||
|
@ -27,11 +27,19 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Account Created" %}</th>
|
<th scope="row">{% trans "Account Created" %}</th>
|
||||||
<td>{{ object.date_joined|annotated_date }}</td>
|
<td>{{ object.date_joined|isodate }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">{% trans "Last Login" %}</th>
|
<th scope="row">{% trans "Last Login" %}</th>
|
||||||
<td>{{ object.last_login|annotated_date }}</td>
|
<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>
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
{% elif customfield.type == 'boolean' and value == False %}
|
{% elif customfield.type == 'boolean' and value == False %}
|
||||||
{% checkmark value false="False" %}
|
{% checkmark value false="False" %}
|
||||||
{% elif customfield.type == 'date' and value %}
|
{% elif customfield.type == 'date' and value %}
|
||||||
{{ value|annotated_date }}
|
{{ value|isodate }}
|
||||||
{% elif customfield.type == 'datetime' and value %}
|
{% elif customfield.type == 'datetime' and value %}
|
||||||
{{ value|annotated_date }}
|
{{ value|isodate }} {{ value|isodatetime }}
|
||||||
{% elif customfield.type == 'url' and value %}
|
{% elif customfield.type == 'url' and value %}
|
||||||
<a href="{{ value }}">{{ value|truncatechars:70 }}</a>
|
<a href="{{ value }}">{{ value|truncatechars:70 }}</a>
|
||||||
{% elif customfield.type == 'json' and value %}
|
{% elif customfield.type == 'json' and value %}
|
||||||
|
@ -20,6 +20,9 @@ __all__ = (
|
|||||||
'content_type',
|
'content_type',
|
||||||
'content_type_id',
|
'content_type_id',
|
||||||
'fgcolor',
|
'fgcolor',
|
||||||
|
'isodate',
|
||||||
|
'isodatetime',
|
||||||
|
'isotime',
|
||||||
'linkify',
|
'linkify',
|
||||||
'meta',
|
'meta',
|
||||||
'placeholder',
|
'placeholder',
|
||||||
@ -202,3 +205,32 @@ def render_yaml(value):
|
|||||||
{{ data_dict|yaml }}
|
{{ data_dict|yaml }}
|
||||||
"""
|
"""
|
||||||
return yaml.dump(json.loads(json.dumps(value)))
|
return yaml.dump(json.loads(json.dumps(value)))
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Time & date
|
||||||
|
#
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def isodate(value):
|
||||||
|
if type(value) is datetime.date:
|
||||||
|
return value.isoformat()
|
||||||
|
if type(value) is datetime.datetime:
|
||||||
|
return value.date().isoformat()
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def isotime(value, spec='seconds'):
|
||||||
|
if type(value) is datetime.time:
|
||||||
|
return value.isoformat(timespec=spec)
|
||||||
|
if type(value) is datetime.datetime:
|
||||||
|
return value.time().isoformat(timespec=spec)
|
||||||
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def isodatetime(value, spec='seconds'):
|
||||||
|
if type(value) is datetime.datetime:
|
||||||
|
return f'{isodate(value)} {isotime(value, spec=spec)}'
|
||||||
|
return ''
|
||||||
|
Loading…
Reference in New Issue
Block a user