From 10ef59ed8e7bb43a15b97c29e56f06b2aa47093e Mon Sep 17 00:00:00 2001 From: amandine-sahl Date: Thu, 29 Jun 2023 16:47:59 +0200 Subject: [PATCH] Use Geotrek bookable field --- backend/core/models.py | 3 +++ backend/test/fixtures.py | 24 +++++++++++++++++++---- backend/test/test_api.py | 24 +++++++++++++++++++++-- front-vite/src/views/EventListingView.vue | 21 ++++++++++++-------- 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/backend/core/models.py b/backend/core/models.py index a3e9e1ce..fdd8ffa2 100644 --- a/backend/core/models.py +++ b/backend/core/models.py @@ -68,6 +68,7 @@ class GTEvents(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode, nullable=False) description_teaser = db.Column(db.Unicode) + bookable = db.Column(db.Boolean) capacity = db.Column(db.Integer) practical_info_fr = db.Column(db.Unicode) practical_info_en = db.Column(db.Unicode) @@ -155,6 +156,8 @@ def massif(cls): return func.animations.get_secteur_name(cls.id) def is_reservation_possible_for(self, nb_people): + if not self.bookable: + return False if not self.capacity: return True if self.sum_participants + nb_people <= self.capacity: diff --git a/backend/test/fixtures.py b/backend/test/fixtures.py index 8bf25aa6..7a43c407 100644 --- a/backend/test/fixtures.py +++ b/backend/test/fixtures.py @@ -15,7 +15,7 @@ events_data = [ { # id: - "name": "Pytest", + "name": "Pytest bookable", "capacity": 10, "begin_date": "01/07/2023", "end_date": "01/10/2023", @@ -24,7 +24,21 @@ "y": 6365673.938623513, "published_fr": True, "published_en": True, - } + "bookable": True, + }, + { + # id: + "name": "Pytest not bookable", + "capacity": None, + "begin_date": "01/07/2023", + "end_date": "01/10/2023", + "published": True, + "x": 765227.4922990737, + "y": 6365673.938623513, + "published_fr": True, + "published_en": True, + "bookable": False, + }, ] @@ -102,11 +116,13 @@ def events(): ( date_insert, date_update, deleted, structure_id, geom,published,"name",capacity, begin_date, end_date, - published_fr, published_en + published_fr, published_en, + bookable ) VALUES (CURRENT_TIMESTAMP,CURRENT_TIMESTAMP, false, 1, st_setsrid(st_point(:x, :y), 2154), :published, :name, :capacity,:begin_date , :end_date , - :published_fr, :published_en + :published_fr, :published_en, + :bookable ) """ ), diff --git a/backend/test/test_api.py b/backend/test/test_api.py index c306bdb6..59d24c6f 100644 --- a/backend/test/test_api.py +++ b/backend/test/test_api.py @@ -123,7 +123,9 @@ def test_post_reservation_isfull(self, events): login(self.client) # POST event = ( - GTEvents.query.filter_by(name="Pytest").order_by(GTEvents.id.desc()).first() + GTEvents.query.filter_by(name="Pytest bookable") + .order_by(GTEvents.id.desc()) + .first() ) data_resa = TEST_RESERVATION @@ -145,11 +147,29 @@ def test_post_reservation_isfull(self, events): ) assert resp.status_code == 422 + def test_post_reservation_notbookable(self, events): + login(self.client) + event = ( + GTEvents.query.filter_by(name="Pytest not bookable") + .order_by(GTEvents.id.desc()) + .first() + ) + + data_resa = TEST_RESERVATION + data_resa["id_event"] = event.id + resp = post_json( + self.client, url_for("app_routes.post_reservations"), data_resa + ) + + assert resp.status_code == 422 + def test_post_export_and_cancel_one_reservation(self, events): login(self.client) # POST event = ( - GTEvents.query.filter_by(name="Pytest").order_by(GTEvents.id.desc()).first() + GTEvents.query.filter_by(name="Pytest bookable") + .order_by(GTEvents.id.desc()) + .first() ) data_resa = TEST_RESERVATION diff --git a/front-vite/src/views/EventListingView.vue b/front-vite/src/views/EventListingView.vue index 0ab3746a..cf57f1db 100644 --- a/front-vite/src/views/EventListingView.vue +++ b/front-vite/src/views/EventListingView.vue @@ -156,12 +156,14 @@
- {{ formatDateString(data.begin_date) || '?' }} + Sans réservation + {{ formatDateString(data.begin_date) || '?' }} - {{ formatDateString(data.end_date) }} @@ -215,7 +217,7 @@
- + + + Animation sans réservation +
@@ -358,7 +363,7 @@ :error="bilanError" :original-data="selectedEvent.bilan" :summary="selectedEventSummary" - + @submit="onSaveBilan" /> @@ -396,7 +401,7 @@

Merci de sélectioner une animation dans la liste de gauche.

-
+
@@ -521,7 +526,7 @@ async function loadEvents () { if (currentValue instanceof Date) { params[key] = currentValue.toISOString() } - } + } }) try { const data = await getEvents(params) @@ -546,8 +551,8 @@ async function loadReservations (page: number = 0) { resas.value = { results: [], total: 0 } resas.value = await getReservations({ page: page + 1, - event_id: selectedEvent.value.id - }) + event_id: selectedEvent.value.id + }) } function onPageReservations($event: any) { loadReservations($event.page) @@ -712,7 +717,7 @@ onBeforeMount(async () => {