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():