Feuilles de poste : ajouter la photo des bénévoles affectés
Vignette carrée (14 mm, proportions préservées) à côté du nom de chaque bénévole affecté, à côté de son téléphone — case vide si le bénévole n'a pas de photo. Complète l'affichage déjà en place sur l'écran référent et l'écran bénévole (étape 22). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
15109acfe5
commit
f6fbfaf82a
@@ -1,8 +1,16 @@
|
||||
"""Feuilles de poste (PDF) — API."""
|
||||
|
||||
import base64
|
||||
|
||||
from app.models import Assignment, Role
|
||||
from tests.factories import dt_at, make_position, make_shift, make_volunteer
|
||||
|
||||
# PNG 1×1 valide (transparent), le plus petit possible.
|
||||
_PNG = base64.b64decode(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY"
|
||||
"42YAAAAASUVORK5CYII="
|
||||
)
|
||||
|
||||
|
||||
def _url(edition):
|
||||
return f"/editions/{edition.id}/position-sheets/generate"
|
||||
@@ -70,6 +78,29 @@ def test_generates_a_pdf_with_a_referent(client, edition, session, make_account)
|
||||
assert resp.content.startswith(b"%PDF")
|
||||
|
||||
|
||||
def test_includes_a_volunteer_photo_when_present(client, edition, session):
|
||||
position = make_position(session, edition, name="Bar central")
|
||||
shift = make_shift(
|
||||
session, edition, position, start=dt_at(9, 19), end=dt_at(9, 22),
|
||||
min_staff=1, ideal_staff=2,
|
||||
)
|
||||
with_photo = make_volunteer(session, edition, first_name="Alex", last_name="Martin")
|
||||
with_photo.photo = _PNG
|
||||
with_photo.photo_content_type = "image/png"
|
||||
without_photo = make_volunteer(session, edition, first_name="Sam", last_name="Nuit")
|
||||
session.add_all(
|
||||
[
|
||||
Assignment(edition_id=edition.id, volunteer_id=with_photo.id, shift_id=shift.id),
|
||||
Assignment(edition_id=edition.id, volunteer_id=without_photo.id, shift_id=shift.id),
|
||||
]
|
||||
)
|
||||
session.commit()
|
||||
|
||||
resp = client.post(_url(edition), json={})
|
||||
assert resp.status_code == 200
|
||||
assert resp.content.startswith(b"%PDF")
|
||||
|
||||
|
||||
def test_position_ids_filter_scopes_the_sheets(client, edition, session):
|
||||
bar = make_position(session, edition, name="Bar central")
|
||||
welcome = make_position(session, edition, name="Accueil")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Génération des feuilles de poste (module pur, sans base)."""
|
||||
|
||||
import base64
|
||||
import datetime as dt
|
||||
|
||||
from app.sheets.pdf import (
|
||||
@@ -9,6 +10,12 @@ from app.sheets.pdf import (
|
||||
generate_position_sheets_pdf,
|
||||
)
|
||||
|
||||
# PNG 1×1 valide (transparent), le plus petit possible.
|
||||
_PNG = base64.b64decode(
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY"
|
||||
"42YAAAAASUVORK5CYII="
|
||||
)
|
||||
|
||||
|
||||
def _sheet(volunteers=(), min_staff=1, ideal_staff=2) -> PositionDaySheet:
|
||||
return PositionDaySheet(
|
||||
@@ -88,3 +95,26 @@ def test_generates_a_valid_pdf_without_a_referent():
|
||||
assert sheet.referent_name is None
|
||||
pdf = generate_position_sheets_pdf([sheet])
|
||||
assert pdf.startswith(b"%PDF")
|
||||
|
||||
|
||||
def test_generates_a_valid_pdf_with_volunteer_photos():
|
||||
sheet = _sheet(
|
||||
volunteers=(
|
||||
SheetVolunteer(name="Alex Martin", phone="0600000000", photo=_PNG),
|
||||
SheetVolunteer(name="Sam Nuit", phone=None, photo=None),
|
||||
)
|
||||
)
|
||||
assert sheet.shifts[0].volunteers[0].photo == _PNG
|
||||
assert sheet.shifts[0].volunteers[1].photo is None
|
||||
pdf = generate_position_sheets_pdf([sheet])
|
||||
assert pdf.startswith(b"%PDF")
|
||||
|
||||
|
||||
def test_a_volunteer_photo_makes_the_pdf_larger():
|
||||
without_photo = generate_position_sheets_pdf(
|
||||
[_sheet(volunteers=(SheetVolunteer(name="Alex Martin", phone=None, photo=None),))]
|
||||
)
|
||||
with_photo = generate_position_sheets_pdf(
|
||||
[_sheet(volunteers=(SheetVolunteer(name="Alex Martin", phone=None, photo=_PNG),))]
|
||||
)
|
||||
assert len(with_photo) > len(without_photo)
|
||||
|
||||
Reference in New Issue
Block a user