Skip to content

Commit

Permalink
Change export participants list
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Jul 21, 2023
1 parent a4da2d6 commit 1f090ed
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
46 changes: 36 additions & 10 deletions backend/core/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,7 @@ def logout():
@app_routes.route("/export_reservation/<id>", methods=["GET"])
@login_admin_required
def export_reservation(id):
resa = TReservations.query.filter_by(id_event=id).all()

results = TReservationsSchema(many=True).dump(resa)
resa = TReservations.query.filter_by(id_event=id).filter_by(cancelled=False).all()
export_fields = [
"id_reservation",
"id_event",
Expand All @@ -592,15 +590,43 @@ def export_reservation(id):
"nb_9_12_ans",
"nb_plus_12_ans",
"num_departement",
# "numerisateur.identifiant",
# "id_numerisateur",
# "commentaire_numerisateur",
"commentaire",
"meta_create_date",
"meta_update_date",
]
data = transform_obj_to_flat_list(export_fields, results)
return to_csv_resp(f"reservation_{id}", data, export_fields, ";")

export_colums = [
"id_reservation",
"id_event",
"Nom",
"Prénom",
"Email",
"Téléphone",
"Sur liste attente",
"Nombre participants",
"Nombre participants sur liste d’attente",
"Nb adultes",
"Nb enfants moins de 6 ans",
"Nb enfants 6-8 ans",
"Nb enfants 9-12 ans",
"Nb enfants plus de 12 ans",
"Département",
"Commentaire",
]
results = TReservationsSchema(many=True, only=export_fields).dump(resa)

data = []
for res in results:
row = []
for field in export_fields:
value = res[field]
if res[field] is False:
value = "non"
elif res[field] is True:
value = "oui"
row.append(value)
data.append(dict(zip(export_colums, row)))

# data = transform_obj_to_flat_list(export_fields, results)
return to_csv_resp(f"reservation_{id}", data, export_colums, ";")


@app_routes.route("/bilans", methods=["POST"])
Expand Down
31 changes: 29 additions & 2 deletions backend/test/test_api_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from flask import url_for, current_app

import csv
import io
import pytest
import json
import logging
Expand Down Expand Up @@ -175,7 +177,7 @@ def test_post_export_and_cancel_one_reservation(self, events):
# Check is confirm
assert resa.confirmed == True

# EXPORT liste participant
# EXPORT liste participants
resp = self.client.get(
url_for("app_routes.export_reservation", id=resa.id_event)
)
Expand All @@ -185,7 +187,32 @@ def test_post_export_and_cancel_one_reservation(self, events):
in resp.headers["Content-Disposition"]
)

# DELETE
content = resp.data.decode("utf-8")
cvs_reader = csv.reader(io.StringIO(content), delimiter=";")
body = list(cvs_reader)
headers = body.pop(0)

assert len(body) == 1
assert headers == [
"id_reservation",
"id_event",
"Nom",
"Prénom",
"Email",
"Téléphone",
"Sur liste attente",
"Nombre participants",
"Nombre participants sur liste d’attente",
"Nb adultes",
"Nb enfants moins de 6 ans",
"Nb enfants 6-8 ans",
"Nb enfants 9-12 ans",
"Nb enfants plus de 12 ans",
"Département",
"Commentaire",
]

# Cancel
resa = TReservations.query.limit(1).one()

response = self.client.delete(
Expand Down

0 comments on commit 1f090ed

Please sign in to comment.