forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -4,9 +4,9 @@ Ecrit par Matthias Hartmann.
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from pytz import UTC
|
||||
|
||||
from app import log
|
||||
from app import log, db
|
||||
import app.scodoc.sco_utils as scu
|
||||
from app.models.assiduites import Assiduite, Justificatif
|
||||
from app.models.assiduites import Assiduite, Justificatif, compute_assiduites_justified
|
||||
from app.models.etudiants import Identite
|
||||
from app.models.formsemestre import FormSemestre, FormSemestreInscription
|
||||
from app.scodoc import sco_formsemestre_inscriptions
|
||||
@ -141,11 +141,11 @@ class CountCalculator:
|
||||
self.hours += finish_hours.total_seconds() / 3600
|
||||
self.hours += self.hour_per_day - (start_hours.total_seconds() / 3600)
|
||||
|
||||
def compute_assiduites(self, assiduites: Assiduite):
|
||||
def compute_assiduites(self, assiduites: Query or list):
|
||||
"""Calcule les métriques pour la collection d'assiduité donnée"""
|
||||
assi: Assiduite
|
||||
assiduites: list[Assiduite] = (
|
||||
assiduites.all() if isinstance(assiduites, Assiduite) else assiduites
|
||||
assiduites.all() if isinstance(assiduites, Query) else assiduites
|
||||
)
|
||||
for assi in assiduites:
|
||||
self.count += 1
|
||||
@ -408,6 +408,42 @@ def get_all_justified(
|
||||
return after
|
||||
|
||||
|
||||
def create_absence(
|
||||
date_debut: datetime,
|
||||
date_fin: datetime,
|
||||
etudid: int,
|
||||
description: str = None,
|
||||
est_just: bool = False,
|
||||
) -> int:
|
||||
etud: Identite = Identite.query.filter_by(etudid=etudid).first_or_404()
|
||||
assiduite_unique: Assiduite = Assiduite.create_assiduite(
|
||||
etud=etud,
|
||||
date_debut=date_debut,
|
||||
date_fin=date_fin,
|
||||
etat=scu.EtatAssiduite.ABSENT,
|
||||
description=description,
|
||||
)
|
||||
db.session.add(assiduite_unique)
|
||||
|
||||
db.session.commit()
|
||||
if est_just:
|
||||
justi = Justificatif.create_justificatif(
|
||||
etud=etud,
|
||||
date_debut=date_debut,
|
||||
date_fin=date_fin,
|
||||
etat=scu.EtatJustificatif.VALIDE,
|
||||
raison=description,
|
||||
)
|
||||
db.session.add(justi)
|
||||
db.session.commit()
|
||||
|
||||
compute_assiduites_justified(etud.id, [justi])
|
||||
|
||||
calculator: CountCalculator = CountCalculator()
|
||||
calculator.compute_assiduites([assiduite_unique])
|
||||
return calculator.to_dict()["demi"]
|
||||
|
||||
|
||||
# Gestion du cache
|
||||
def get_assiduites_count(etudid: int, sem: dict) -> tuple[int, int]:
|
||||
"""Les comptes d'absences de cet étudiant dans ce semestre:
|
||||
|
@ -56,6 +56,7 @@ from app.scodoc.sco_exceptions import ScoValueError
|
||||
from app.scodoc.TrivialFormulator import TrivialFormulator
|
||||
from app.scodoc import html_sco_header
|
||||
from app.scodoc import sco_cal
|
||||
from app.scodoc import sco_assiduites as scass
|
||||
from app.scodoc import sco_abs_billets
|
||||
from app.scodoc import sco_etud
|
||||
from app.scodoc import sco_preferences
|
||||
@ -312,54 +313,16 @@ def _ProcessBilletAbsence(
|
||||
n = 0 # nombre de demi-journées d'absence ajoutées
|
||||
|
||||
# 1-- Ajout des absences (et justifs)
|
||||
datedebut = billet.abs_begin.strftime("%d/%m/%Y")
|
||||
datefin = billet.abs_end.strftime("%d/%m/%Y")
|
||||
dates = sco_cal.DateRangeISO(datedebut, datefin)
|
||||
# commence après-midi ?
|
||||
if dates and billet.abs_begin.hour > 11:
|
||||
# XXX TODO-ASSIDUITE
|
||||
raise ScoValueError("Fonction non disponible")
|
||||
sco_abs.add_absence(
|
||||
billet.etudid,
|
||||
dates[0],
|
||||
0,
|
||||
estjust,
|
||||
description=description,
|
||||
)
|
||||
n += 1
|
||||
dates = dates[1:]
|
||||
# termine matin ?
|
||||
if dates and billet.abs_end.hour < 12:
|
||||
# XXX TODO-ASSIDUITE
|
||||
raise ScoValueError("Fonction non disponible")
|
||||
sco_abs.add_absence(
|
||||
billet.etudid,
|
||||
dates[-1],
|
||||
1,
|
||||
estjust,
|
||||
description=description,
|
||||
)
|
||||
n += 1
|
||||
dates = dates[:-1]
|
||||
|
||||
for jour in dates:
|
||||
raise ScoValueError("Fonction non disponible")
|
||||
sco_abs.add_absence(
|
||||
billet.etudid,
|
||||
jour,
|
||||
0,
|
||||
estjust,
|
||||
description=description,
|
||||
)
|
||||
# XXX TODO-ASSIDUITE
|
||||
sco_abs.add_absence(
|
||||
billet.etudid,
|
||||
jour,
|
||||
1,
|
||||
estjust,
|
||||
description=description,
|
||||
)
|
||||
n += 2
|
||||
datedebut = billet.abs_begin
|
||||
datefin = billet.abs_end
|
||||
log(f"Gestion du billet n°{billet.id}")
|
||||
n = scass.create_absence(
|
||||
date_debut=datedebut,
|
||||
date_fin=datefin,
|
||||
etudid=billet.etudid,
|
||||
description=description,
|
||||
est_just=estjust,
|
||||
)
|
||||
|
||||
# 2- Change état du billet
|
||||
billet.etat = True
|
||||
|
Loading…
Reference in New Issue
Block a user