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:
|
||||
|
@ -833,7 +833,7 @@ def tab_absences_html(groups_infos, etat=None):
|
||||
"<li>",
|
||||
form_choix_jour_saisie_hebdo(groups_infos),
|
||||
"</li>",
|
||||
f"""<li><a href="{
|
||||
f"""<li><a class="stdlink" href="{
|
||||
url_for("assiduites.visu_assi_group", scodoc_dept=g.scodoc_dept, group_ids=group_ids, date_debut=formsemestre.date_debut.isoformat(), date_fin=formsemestre.date_fin.isoformat())
|
||||
}">État des assiduités du groupe</a></li>""",
|
||||
"</ul>",
|
||||
@ -890,76 +890,38 @@ def form_choix_jour_saisie_hebdo(groups_infos, moduleimpl_id=None):
|
||||
authuser = current_user
|
||||
if not authuser.has_permission(Permission.ScoAbsChange):
|
||||
return ""
|
||||
sem = groups_infos.formsemestre
|
||||
first_monday = sco_cal.ddmmyyyy(sem["date_debut"]).prev_monday()
|
||||
today_idx = datetime.date.today().weekday()
|
||||
|
||||
FA = [] # formulaire avec menu saisi absences
|
||||
FA.append(
|
||||
# TODO-ASSIDUITE et utiliser url_for... (was Absences/SignaleAbsenceGrSemestre)
|
||||
'<form id="form_choix_jour_saisie_hebdo" action="XXX" method="get">'
|
||||
)
|
||||
FA.append('<input type="hidden" name="datefin" value="%(date_fin)s"/>' % sem)
|
||||
FA.append(groups_infos.get_form_elem())
|
||||
if moduleimpl_id:
|
||||
FA.append(
|
||||
'<input type="hidden" name="moduleimpl_id" value="%s"/>' % moduleimpl_id
|
||||
)
|
||||
FA.append('<input type="hidden" name="destination" value=""/>')
|
||||
|
||||
FA.append(
|
||||
"""<input type="button" onclick="$('#form_choix_jour_saisie_hebdo')[0].destination.value=get_current_url(); $('#form_choix_jour_saisie_hebdo').submit();" value="Saisir absences du (NON DISPONIBLE) "/>"""
|
||||
)
|
||||
FA.append("""<select name="datedebut">""")
|
||||
date = first_monday
|
||||
i = 0
|
||||
for jour in sco_cal.day_names():
|
||||
if i == today_idx:
|
||||
sel = "selected"
|
||||
else:
|
||||
sel = ""
|
||||
i += 1
|
||||
FA.append('<option value="%s" %s>%s</option>' % (date, sel, jour))
|
||||
date = date.next_day()
|
||||
FA.append("</select>")
|
||||
FA.append("</form>")
|
||||
return "\n".join(FA)
|
||||
return f"""
|
||||
<button onclick="window.location='{
|
||||
url_for(
|
||||
"assiduites.signal_assiduites_group",
|
||||
scodoc_dept=g.scodoc_dept,
|
||||
group_ids=",".join(map(str,groups_infos.group_ids)),
|
||||
jour=datetime.date.today().isoformat(),
|
||||
formsemestre_id=groups_infos.formsemestre_id,
|
||||
moduleimpl_id="" if moduleimpl_id is None else moduleimpl_id
|
||||
)
|
||||
}';">Saisie du jour</button>
|
||||
"""
|
||||
|
||||
|
||||
# Ajout Le Havre
|
||||
# Formulaire saisie absences semaine
|
||||
# Saisie de l'assiduité par semaine
|
||||
def form_choix_saisie_semaine(groups_infos):
|
||||
authuser = current_user
|
||||
if not authuser.has_permission(Permission.ScoAbsChange):
|
||||
return ""
|
||||
# construit l'URL "destination"
|
||||
# (a laquelle on revient apres saisie absences)
|
||||
query_args = parse_qs(request.query_string)
|
||||
moduleimpl_id = query_args.get("moduleimpl_id", [""])[0]
|
||||
if "head_message" in query_args:
|
||||
del query_args["head_message"]
|
||||
destination = "%s?%s" % (
|
||||
request.base_url,
|
||||
urllib.parse.urlencode(query_args, True),
|
||||
)
|
||||
destination = destination.replace(
|
||||
"%", "%%"
|
||||
) # car ici utilisee dans un format string !
|
||||
|
||||
DateJour = time.strftime("%d/%m/%Y")
|
||||
datelundi = sco_cal.ddmmyyyy(DateJour).prev_monday()
|
||||
FA = [] # formulaire avec menu saisie hebdo des absences
|
||||
# XXX TODO-ASSIDUITE et utiliser un POST
|
||||
FA.append('<form action="Absences/SignaleAbsenceGrHebdo" method="get">')
|
||||
FA.append('<input type="hidden" name="datelundi" value="%s"/>' % datelundi)
|
||||
FA.append('<input type="hidden" name="moduleimpl_id" value="%s"/>' % moduleimpl_id)
|
||||
FA.append('<input type="hidden" name="destination" value="%s"/>' % destination)
|
||||
FA.append(groups_infos.get_form_elem())
|
||||
FA.append(
|
||||
'<input type="submit" class="button" value="Saisie à la semaine (NON DISPONIBLE)" />'
|
||||
) # XXX
|
||||
FA.append("</form>")
|
||||
return "\n".join(FA)
|
||||
moduleimpl_id = query_args.get("moduleimpl_id", [None])[0]
|
||||
semaine = datetime.date.today().isocalendar().week
|
||||
return f"""
|
||||
<button onclick="window.location='{url_for(
|
||||
"assiduites.signal_assiduites_diff",
|
||||
group_ids=",".join(map(str,groups_infos.group_ids)),
|
||||
semaine=semaine,
|
||||
scodoc_dept=g.scodoc_dept,
|
||||
formsemestre_id=groups_infos.formsemestre_id,
|
||||
moduleimpl_id=moduleimpl_id
|
||||
)}';">Saisie à la semaine</button>
|
||||
"""
|
||||
|
||||
|
||||
def export_groups_as_moodle_csv(formsemestre_id=None):
|
||||
|
@ -331,6 +331,21 @@ def moduleimpl_status(moduleimpl_id=None, partition_id=None):
|
||||
}&formsemestre_id={formsemestre.id}
|
||||
&moduleimpl_id={moduleimpl_id}
|
||||
"
|
||||
>Saisie Absences journée</a></span>
|
||||
"""
|
||||
)
|
||||
|
||||
H.append(
|
||||
f"""
|
||||
<span class="moduleimpl_abs_link"><a class="stdlink" href="{
|
||||
url_for(
|
||||
"assiduites.signal_assiduites_group",
|
||||
scodoc_dept=g.scodoc_dept,
|
||||
group_ids=group_id,
|
||||
jour=datetime.date.today().isoformat(),
|
||||
formsemestre_id=formsemestre.id,
|
||||
moduleimpl_id="" if moduleimpl_id is None else moduleimpl_id
|
||||
)}"
|
||||
>Saisie Absences hebdo</a></span>
|
||||
"""
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -1002,7 +1002,9 @@ def signal_assiduites_diff():
|
||||
"assiduites/pages/signal_assiduites_diff.j2",
|
||||
diff=_differee(
|
||||
etudiants=etudiants,
|
||||
moduleimpl_select=_module_selector(formsemestre),
|
||||
moduleimpl_select=_module_selector(
|
||||
formsemestre, request.args.get("moduleimpl_id", None)
|
||||
),
|
||||
date=date,
|
||||
periode={
|
||||
"deb": formsemestre.date_debut.isoformat(),
|
||||
@ -1162,6 +1164,11 @@ def _module_selector(
|
||||
)
|
||||
modules.append({"moduleimpl_id": modimpl["moduleimpl_id"], "name": modname})
|
||||
|
||||
try:
|
||||
moduleimpl_id = int(moduleimpl_id)
|
||||
except (ValueError, TypeError):
|
||||
moduleimpl_id = None
|
||||
|
||||
return render_template(
|
||||
"assiduites/widgets/moduleimpl_selector.j2",
|
||||
selected=selected,
|
||||
|
Loading…
Reference in New Issue
Block a user