feat [api]: bocal template and view
This commit is contained in:
parent
67fd010e10
commit
4f3549daeb
6 changed files with 63 additions and 2 deletions
14
server/myapi/renderers.py
Normal file
14
server/myapi/renderers.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
from django.utils.encoding import smart_str
|
||||||
|
from rest_framework import renderers
|
||||||
|
|
||||||
|
|
||||||
|
class PlainTextRenderer(renderers.BaseRenderer):
|
||||||
|
media_type = 'text/plain'
|
||||||
|
format = 'txt'
|
||||||
|
|
||||||
|
def render(self, data, media_type=None, renderer_context=None):
|
||||||
|
return smart_str(data, encoding=self.charset)
|
||||||
|
|
||||||
|
class LatexRenderer(PlainTextRenderer):
|
||||||
|
media_type = 'text/x-tex'
|
||||||
|
format = 'tex'
|
0
server/myapi/services/__init__.py
Normal file
0
server/myapi/services/__init__.py
Normal file
18
server/myapi/services/com_service.py
Normal file
18
server/myapi/services/com_service.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
|
from myapi.models import Film
|
||||||
|
|
||||||
|
prices = {
|
||||||
|
'one_cof': 4,
|
||||||
|
'one_exte': 5,
|
||||||
|
'card_cof': 30,
|
||||||
|
'card_exte': 35
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def render_com(template_name, film: Film) -> str:
|
||||||
|
return render_to_string(template_name, {"film": film, "prices": prices})
|
||||||
|
|
||||||
|
|
||||||
|
def bocal(film: Film) -> str:
|
||||||
|
return render_com('bocal.tex', film)
|
20
server/myapi/templates/bocal.tex
Normal file
20
server/myapi/templates/bocal.tex
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
\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 }}}
|
||||||
|
\medskip
|
||||||
|
\centerline{% templatetag openbrace %}{{ film.movie_format }} . {{ film.language_subtitles }}}
|
||||||
|
\medskip
|
||||||
|
\centerline{\textit{% templatetag openbrace %}{{ film.duration }} minutes}}
|
||||||
|
|
||||||
|
\medskip
|
||||||
|
\medskip
|
||||||
|
\centerline{~{{ prices.one_exte }}€~/~{{ prices.one_cof }}~€ COF}
|
||||||
|
\medskip
|
||||||
|
|
||||||
|
\centerline{\includegraphics[width=5cm]{cine}}
|
||||||
|
|
||||||
|
\medskip \medskip
|
||||||
|
{{ film.synopsis }}
|
|
@ -1,12 +1,21 @@
|
||||||
# from django.shortcuts import render
|
# from django.shortcuts import render
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from myapi.renderers import LatexRenderer
|
||||||
from myapi.serializers import FilmSerializer
|
from myapi.serializers import FilmSerializer
|
||||||
from myapi.models import Film
|
from myapi.models import Film
|
||||||
|
import myapi.services.com_service as com
|
||||||
|
|
||||||
|
|
||||||
class FilmViewSet(viewsets.ModelViewSet):
|
class FilmViewSet(viewsets.ModelViewSet):
|
||||||
queryset = Film.objects.all().order_by('projection_date')
|
queryset = Film.objects.all().order_by('projection_date')
|
||||||
serializer_class = FilmSerializer
|
serializer_class = FilmSerializer
|
||||||
|
|
||||||
# Create your views here.
|
# TODO confirm that latex renderer is not a problem
|
||||||
|
@action(detail=True, renderer_classes=[LatexRenderer], methods=['GET'])
|
||||||
|
def bocal(self, request, pk=None):
|
||||||
|
film: Film = self.get_object()
|
||||||
|
bocal_text = com.bocal(film)
|
||||||
|
return Response(bocal_text)
|
||||||
|
|
|
@ -105,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'fr-fr'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue