From 809d98df0aa98ca68b84ea1e4adf528592681b31 Mon Sep 17 00:00:00 2001 From: leonard_montalbano Date: Mon, 20 Jun 2022 16:10:39 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20absences=20al=C3=A9atoires=20pour=20la?= =?UTF-8?q?=20base=20de=20test=20(pas=20encore=20fonctionnel)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/absences.py | 9 +++++++ .../fakedatabase/create_test_api_database.py | 25 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/models/absences.py b/app/models/absences.py index 830d46f9e..d3ea00356 100644 --- a/app/models/absences.py +++ b/app/models/absences.py @@ -27,6 +27,15 @@ class Absence(db.Model): # XXX TODO: contrainte ajoutée: vérifier suppression du module # (mettre à NULL sans supprimer) + def __init__(self, id, etudid, jour, estabs, estjust, matin, description): + self.id = id, + self.etudid = etudid, + self.jour = jour, + self.estabs = estabs, + self.estjust = estjust, + self.matin = matin, + self.description = description + def to_dict(self): data = { "id": self.id, diff --git a/tools/fakedatabase/create_test_api_database.py b/tools/fakedatabase/create_test_api_database.py index a7f6a11d4..9820e8871 100644 --- a/tools/fakedatabase/create_test_api_database.py +++ b/tools/fakedatabase/create_test_api_database.py @@ -436,7 +436,32 @@ def create_ref_comp(formation: Formation): db.session.commit() +def add_absences(formsemestre: FormSemestre): + """ + Ajoute des absences en base + """ + date_debut = formsemestre.date_debut + date_fin = formsemestre.date_fin + etuds = formsemestre.etuds + # list_etuds = [] + for etu in etuds: + id_db = 1 + aleatoire = random.randint(0, 1) + if aleatoire == 1: + nb_absences = random.randint(1, 5) + for absence in range(0, nb_absences): + id = id_db + etudid = etu.id + jour = date_debut + random.random() * (date_fin - date_debut) + estabs = True + estjust = True if random.randint(0, 1) == 1 else False + matin = True if random.randint(0, 1) == 1 else False + description = "" + abs = Absence(id, etudid, jour, estabs, estjust, matin, description) + db.session.add(abs) + db.session.commit() + id_db += 1 def init_test_database():