Browse Source

Konzistentní krátké datum.

okenkove_obalky
parent
commit
5881a9d506
  1. 13
      seminar/templatetags/utils.py

13
seminar/templatetags/utils.py

@ -1,4 +1,5 @@
from django import template from django import template
from django.utils.safestring import mark_safe
from datetime import datetime, timedelta from datetime import datetime, timedelta
from pytz import timezone from pytz import timezone
from mamweb.settings import TIME_ZONE from mamweb.settings import TIME_ZONE
@ -15,13 +16,5 @@ def kratke_datum(dt):
if not isinstance(dt, datetime): if not isinstance(dt, datetime):
logger.warning(f"Špatné volání filtru {__name__}: {dt}") logger.warning(f"Špatné volání filtru {__name__}: {dt}")
return False return False
naive_now = datetime.now() out = f'<span title="{dt.strftime("%d. %m. %Y %H:%M")}">{dt.day}.{dt.month}.<span style="text-decoration:overline">{dt.year%100}</span>'
tz = timezone(TIME_ZONE) return mark_safe(out)
now = tz.localize(naive_now)
delta = now - dt
if delta <= timedelta(days=1):
return dt.strftime("%H:%M")
if delta <= timedelta(days=365): # Timedelta neumí vyjádřit 1 rok
return dt.strftime("%d. %m.")
return dt.strftime("%d. %m. %Y")

Loading…
Cancel
Save