seminar/templatetags

This commit is contained in:
Jonas Havelka 2024-08-04 19:21:46 +02:00
parent 18364eb531
commit 85c3969c50
5 changed files with 0 additions and 20 deletions

View file

@ -1,6 +1,5 @@
{% extends "base.html" %}
{% load utils %} {# Možná by mohlo být někde výš v hierarchii templatů... #}
{% load barvy_reseni %}
{% block content %}

View file

@ -1,19 +0,0 @@
from django import template
from django.utils.safestring import mark_safe
from datetime import datetime, timedelta
from mamweb.settings import TIME_ZONE
import logging
register = template.Library()
logger = logging.getLogger(__name__)
@register.filter(name='kratke_datum', expects_localtime=True)
def kratke_datum(dt):
# None dává None, ne-datum dává False, aby se daly použít filtry typu "default".
if dt is None:
return None
if not isinstance(dt, datetime):
logger.warning(f"Špatné volání filtru {__name__}: {dt}")
return False
out = f'<time datetime="{dt.isoformat()}" title="{dt.strftime("%d. %m. %Y %H:%M")}">{dt.day}.{dt.month}.<span style="text-decoration:overline">{dt.year%100}</time>'
return mark_safe(out)