diff --git a/server/myapi/templates/bocal.tex b/server/myapi/templates/bocal.tex index 780dfad..2d1ccac 100644 --- a/server/myapi/templates/bocal.tex +++ b/server/myapi/templates/bocal.tex @@ -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 diff --git a/server/myapi/templatetags/film_tags.py b/server/myapi/templatetags/film_tags.py new file mode 100644 index 0000000..60799ad --- /dev/null +++ b/server/myapi/templatetags/film_tags.py @@ -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)