ajout absences aléatoires pour la base de test (pas encore fonctionnel)

This commit is contained in:
leonard_montalbano 2022-06-20 16:10:39 +02:00
parent 457a5a8b06
commit 809d98df0a
2 changed files with 34 additions and 0 deletions

View File

@ -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,

View File

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