feat [api]: format tags and filters

This commit is contained in:
Alice 2022-04-03 01:20:54 +02:00
parent a396b5be5b
commit 75d14d6054
2 changed files with 31 additions and 2 deletions

View file

@ -1,13 +1,15 @@
{% load film_tags %}
\centerline{\date{% templatetag openbrace %}{{ film.projection_date|date:"l d F Y" }}, {{ film.projection_date|time:"H\hi" }}}
\centerline{Salle Dussane}
\centerline{\emph{\Large {{ film.title }}}}
\centerline{% templatetag openbrace %}{{ film.director }} ({{ film.release_year }})}
\medskip
\centerline{% templatetag openbrace %}{{ film.actors }}}
\centerline{% templatetag openbrace %}{% list_actors film.actors %}}
\medskip
\centerline{% templatetag openbrace %}{{ film.movie_format }} . {{ film.language_subtitles }}}
\medskip
\centerline{\textit{% templatetag openbrace %}{{ film.duration }} minutes}}
\centerline{\textit{% templatetag openbrace %}{{ film.duration|movie_duration }}}}
\medskip
\medskip

View file

@ -0,0 +1,27 @@
from datetime import timedelta
from django import template
from typing import List
from django.utils.safestring import mark_safe
register = template.Library()
@register.simple_tag
def color_display(in_color: bool) -> str:
res = "Couleur" if in_color else "Noir & Blanc"
return mark_safe(res)
@register.simple_tag
def list_actors(actors: List[str]) -> str:
res = ", ".join(actors[:3])
if len(actors) > 3:
res += "..."
return res
@register.filter
def movie_duration(value: timedelta) -> str:
s = value.total_seconds()
str_duration = f"{int(s // 3600):01d}h{int(s % 3600 // 60):02d}"
return mark_safe(str_duration)