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 @@
Merci de sélectioner une animation dans la liste de gauche.
-