From a4db8c4ff8458a113792794ec5d86458ac9bf9d3 Mon Sep 17 00:00:00 2001
From: Iziram
"""
+
+ return html
+
+ def _get_eval_style(self, e: Evaluation) -> str:
+ color: str = ""
+ # Etat (notes completes) de l'évaluation:
+ modimpl_result = self.parent.nt.modimpls_results[e.moduleimpl.id]
+ if modimpl_result.evaluations_etat[e.id].is_complete:
+ color = JourEval.COLOR_COMPLETE
+ else:
+ color = JourEval.COLOR_INCOMPLETE
+ if e.date_debut > datetime.datetime.now(scu.TIME_ZONE):
+ color = JourEval.COLOR_FUTUR
+
+ return f"background-color: {color};"
+
+ def _get_eval_title(self, e: Evaluation) -> str:
+ heure_debut_txt, heure_fin_txt = "", ""
+ if e.date_debut != e.date_fin:
+ heure_debut_txt = (
+ e.date_debut.strftime(scu.TIME_FMT) if e.date_debut else ""
+ )
+ heure_fin_txt = e.date_fin.strftime(scu.TIME_FMT) if e.date_fin else ""
+
+ title = f"{e.description or e.moduleimpl.module.titre_str()}"
+ if heure_debut_txt:
+ title += f" de {heure_debut_txt} à {heure_fin_txt}"
+
+ return title
+
+
+class CalendrierEval(sco_gen_cal.Calendrier):
+ """
+ Représentation des évaluations d'un semestre dans un calendrier
+ """
+
+ def __init__(self, year: int, evals: list[Evaluation], nt: NotesTableCompat):
+ # On prend du 01/09 au 31/08
+ date_debut: datetime.datetime = datetime.datetime(year, 9, 1, 0, 0)
+ date_fin: datetime.datetime = datetime.datetime(year + 1, 8, 31, 23, 59)
+ super().__init__(date_debut, date_fin)
+
+ # évalutions du semestre
+ self.evals: dict[datetime.date, list[Evaluation]] = {}
+ for e in evals:
+ if e.date_debut is not None:
+ day = e.date_debut.date()
+ if day not in self.evals:
+ self.evals[day] = []
+ self.evals[day].append(e)
+
+ self.nt: NotesTableCompat = nt
+
+ def instanciate_jour(self, date: datetime.date) -> JourEval:
+ return JourEval(date, self.evals.get(date, []), parent=self)
+
+
# View
def formsemestre_evaluations_cal(formsemestre_id):
"""Page avec calendrier de toutes les evaluations de ce semestre"""
@@ -369,52 +467,9 @@ def formsemestre_evaluations_cal(formsemestre_id):
evaluations = formsemestre.get_evaluations()
nb_evals = len(evaluations)
- color_incomplete = "#FF6060"
- color_complete = "#A0FFA0"
- color_futur = "#70E0FF"
-
year = formsemestre.annee_scolaire()
- events_by_day = collections.defaultdict(list) # date_iso : event
- for e in evaluations:
- if e.date_debut is None:
- continue # éval. sans date
- if e.date_debut == e.date_fin:
- heure_debut_txt, heure_fin_txt = "", ""
- else:
- heure_debut_txt = (
- e.date_debut.strftime(scu.TIME_FMT) if e.date_debut else ""
- )
- heure_fin_txt = e.date_fin.strftime(scu.TIME_FMT) if e.date_fin else ""
-
- # Etat (notes completes) de l'évaluation:
- modimpl_result = nt.modimpls_results[e.moduleimpl.id]
- if modimpl_result.evaluations_etat[e.id].is_complete:
- color = color_complete
- else:
- color = color_incomplete
- if e.date_debut > datetime.datetime.now(scu.TIME_ZONE):
- color = color_futur
- day = e.date_debut.date().isoformat() # yyyy-mm-dd
- event = {
- "color": color,
- "date_iso": day,
- "title": e.moduleimpl.module.code or e.moduleimpl.module.abbrev or "éval.",
- "description": f"""{e.description or e.moduleimpl.module.titre_str()}"""
- + (
- f""" de {heure_debut_txt} à {heure_fin_txt}"""
- if heure_debut_txt
- else ""
- ),
- "href": url_for(
- "notes.moduleimpl_status",
- scodoc_dept=g.scodoc_dept,
- moduleimpl_id=e.moduleimpl_id,
- ),
- "modimpl": e.moduleimpl,
- }
- events_by_day[day].append(event)
-
- cal_html = sco_cal.YearTable(year, events_by_day=events_by_day)
+ cal = CalendrierEval(year, evaluations, nt)
+ cal_html = cal.get_html()
return f"""
{
@@ -430,15 +485,15 @@ def formsemestre_evaluations_cal(formsemestre_id):