Remove widgets/relative-time.html fragment

This commit is contained in:
Quantum 2023-02-23 00:42:36 -05:00 committed by Guanzhong Chen
parent 08bcb3c231
commit 9c9a6d556a
2 changed files with 7 additions and 13 deletions

View File

@ -2,6 +2,9 @@ import functools
from django.template.defaultfilters import date, time
from django.templatetags.tz import localtime
from django.utils.html import escape
from django.utils.safestring import mark_safe
from django.utils.timezone import utc
from django.utils.translation import gettext as _
from . import registry
@ -22,11 +25,8 @@ registry.filter(localtime_wrapper(time))
@registry.function
@registry.render_with('widgets/relative-time.html')
def relative_time(time, **kwargs):
return {
'time': time,
'format': kwargs.get('format', _('N j, Y, g:i a')),
'rel_format': kwargs.get('rel', _('{time}')),
'abs_format': kwargs.get('abs', _('on {time}')),
}
abs_time = date(time, kwargs.get('format', _('N j, Y, g:i a')))
return mark_safe(f'<span data-iso="{time.astimezone(utc).isoformat()}" class="time-with-rel"'
f' title="{escape(abs_time)}" data-format="{escape(kwargs.get("rel", _("{time}")))}">'
f'{escape(kwargs.get("abs", _("on {time}")).replace("{time}", abs_time))}</span>')

View File

@ -1,6 +0,0 @@
{% spaceless %}
<span data-iso="{{ time|utc|date('c') }}" class="time-with-rel" title="{{ time|date(format) }}"
data-format="{{ rel_format }}">
{{ abs_format.replace('{time}', time|date(format)) }}
</span>
{% endspaceless %}