Payloads are now built with Jinja templates
This commit is contained in:
parent
ccd019eb4c
commit
badced0a30
12 changed files with 222 additions and 175 deletions
59
resa_padel/gestion_sports/payload_builders.py
Normal file
59
resa_padel/gestion_sports/payload_builders.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from exceptions import ArgumentMissing
|
||||
from gestion_sports.gestion_sports_config import LOGIN_TEMPLATE, BOOKING_TEMPLATE
|
||||
from models import User, Club, BookingFilter
|
||||
|
||||
|
||||
class GestionSportsLoginPayloadBuilder:
|
||||
def __init__(self):
|
||||
self._user: User | None = None
|
||||
self._club: Club | None = None
|
||||
self._template = LOGIN_TEMPLATE
|
||||
|
||||
def user(self, user: User):
|
||||
self._user = user
|
||||
return self
|
||||
|
||||
def club(self, club: Club):
|
||||
self._club = club
|
||||
return self
|
||||
|
||||
def build(self):
|
||||
if self._user is None:
|
||||
raise ArgumentMissing("No user was provided")
|
||||
if self._club is None:
|
||||
raise ArgumentMissing("No club was provided")
|
||||
|
||||
environment = Environment(loader=FileSystemLoader(self._template.parent))
|
||||
template = environment.get_template(self._template.name)
|
||||
|
||||
return template.render(club=self._club, user=self._user)
|
||||
|
||||
|
||||
class GestionSportsBookingPayloadBuilder:
|
||||
def __init__(self):
|
||||
self._booking_filter: BookingFilter | None = None
|
||||
self._court_id: int | None = None
|
||||
self._template = BOOKING_TEMPLATE
|
||||
|
||||
def booking_filter(self, booking_filter: BookingFilter):
|
||||
self._booking_filter = booking_filter
|
||||
return self
|
||||
|
||||
def court_id(self, court_id: int):
|
||||
self._court_id = court_id
|
||||
return self
|
||||
|
||||
def build(self):
|
||||
if self._booking_filter is None:
|
||||
raise ArgumentMissing("No booking filter was provided")
|
||||
if self.court_id is None:
|
||||
raise ArgumentMissing("No court id was provided")
|
||||
|
||||
environment = Environment(loader=FileSystemLoader(self._template.parent))
|
||||
template = environment.get_template(self._template.name)
|
||||
|
||||
return template.render(
|
||||
court_id=self._court_id, booking_filter=self._booking_filter
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue