mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-18 19:32:24 -06:00
* Introduce the isodate(), isotime(), and isodatetime() template filters * Display the relative time on mouse hover * Render journal entry times in ISO 8601 format * Use ISO 8601 format when displaying dates & times in a table * Standardize the use of DateTimeColumn across all tables
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
{% elif customfield.type == 'boolean' and value == False %}
|
||||
{% checkmark value false="False" %}
|
||||
{% elif customfield.type == 'date' and value %}
|
||||
{{ value|annotated_date }}
|
||||
{{ value|isodate }}
|
||||
{% elif customfield.type == 'datetime' and value %}
|
||||
{{ value|annotated_date }}
|
||||
{{ value|isodate }} {{ value|isodatetime }}
|
||||
{% elif customfield.type == 'url' and value %}
|
||||
<a href="{{ value }}">{{ value|truncatechars:70 }}</a>
|
||||
{% elif customfield.type == 'json' and value %}
|
||||
|
||||
@@ -5,6 +5,7 @@ import re
|
||||
import yaml
|
||||
from django import template
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
from markdown import markdown
|
||||
@@ -20,6 +21,9 @@ __all__ = (
|
||||
'content_type',
|
||||
'content_type_id',
|
||||
'fgcolor',
|
||||
'isodate',
|
||||
'isodatetime',
|
||||
'isotime',
|
||||
'linkify',
|
||||
'meta',
|
||||
'placeholder',
|
||||
@@ -202,3 +206,36 @@ def render_yaml(value):
|
||||
{{ data_dict|yaml }}
|
||||
"""
|
||||
return yaml.dump(json.loads(json.dumps(value)))
|
||||
|
||||
|
||||
#
|
||||
# Time & date
|
||||
#
|
||||
|
||||
@register.filter()
|
||||
def isodate(value):
|
||||
if type(value) is datetime.date:
|
||||
text = value.isoformat()
|
||||
elif type(value) is datetime.datetime:
|
||||
text = value.date().isoformat()
|
||||
else:
|
||||
return ''
|
||||
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
|
||||
|
||||
|
||||
@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:
|
||||
text = f'{isodate(value)} {isotime(value, spec=spec)}'
|
||||
else:
|
||||
return ''
|
||||
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
|
||||
|
||||
Reference in New Issue
Block a user