forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -25,8 +25,8 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
"""Evaluations
|
"""Evaluations"""
|
||||||
"""
|
|
||||||
import collections
|
import collections
|
||||||
import datetime
|
import datetime
|
||||||
import operator
|
import operator
|
||||||
@ -50,6 +50,7 @@ from app.scodoc import sco_cal
|
|||||||
from app.scodoc import sco_evaluation_db
|
from app.scodoc import sco_evaluation_db
|
||||||
from app.scodoc import sco_formsemestre_inscriptions
|
from app.scodoc import sco_formsemestre_inscriptions
|
||||||
from app.scodoc import sco_groups
|
from app.scodoc import sco_groups
|
||||||
|
from app.scodoc import sco_gen_cal
|
||||||
from app.scodoc import sco_moduleimpl
|
from app.scodoc import sco_moduleimpl
|
||||||
from app.scodoc import sco_preferences
|
from app.scodoc import sco_preferences
|
||||||
from app.scodoc import sco_users
|
from app.scodoc import sco_users
|
||||||
@ -360,6 +361,103 @@ def do_evaluation_etat_in_mod(nt, modimpl: ModuleImpl):
|
|||||||
return etat
|
return etat
|
||||||
|
|
||||||
|
|
||||||
|
class JourEval(sco_gen_cal.Jour):
|
||||||
|
"""
|
||||||
|
Représentation d'un jour dans un calendrier d'évaluations
|
||||||
|
"""
|
||||||
|
|
||||||
|
COLOR_INCOMPLETE = "#FF6060"
|
||||||
|
COLOR_COMPLETE = "#A0FFA0"
|
||||||
|
COLOR_FUTUR = "#70E0FF"
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
date: datetime.date,
|
||||||
|
evaluations: list[Evaluation],
|
||||||
|
parent: "CalendrierEval",
|
||||||
|
):
|
||||||
|
super().__init__(date)
|
||||||
|
|
||||||
|
self.evaluations: list[Evaluation] = evaluations
|
||||||
|
self.evaluations.sort(key=lambda e: e.date_debut)
|
||||||
|
|
||||||
|
self.parent: "CalendrierEval" = parent
|
||||||
|
|
||||||
|
def get_html(self) -> str:
|
||||||
|
html: str = ""
|
||||||
|
|
||||||
|
for e in self.evaluations:
|
||||||
|
url: str = url_for(
|
||||||
|
"notes.moduleimpl_status",
|
||||||
|
scodoc_dept=g.scodoc_dept,
|
||||||
|
moduleimpl_id=e.moduleimpl_id,
|
||||||
|
)
|
||||||
|
title: str = (
|
||||||
|
e.moduleimpl.module.code or e.moduleimpl.module.abbrev or "éval."
|
||||||
|
)
|
||||||
|
html += f"""<a
|
||||||
|
href="{url}"
|
||||||
|
style="{self._get_eval_style(e)}"
|
||||||
|
title="{self._get_eval_title(e)}"
|
||||||
|
>
|
||||||
|
{title}</a><br>"""
|
||||||
|
|
||||||
|
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
|
# View
|
||||||
def formsemestre_evaluations_cal(formsemestre_id):
|
def formsemestre_evaluations_cal(formsemestre_id):
|
||||||
"""Page avec calendrier de toutes les evaluations de ce semestre"""
|
"""Page avec calendrier de toutes les evaluations de ce semestre"""
|
||||||
@ -369,52 +467,9 @@ def formsemestre_evaluations_cal(formsemestre_id):
|
|||||||
evaluations = formsemestre.get_evaluations()
|
evaluations = formsemestre.get_evaluations()
|
||||||
nb_evals = len(evaluations)
|
nb_evals = len(evaluations)
|
||||||
|
|
||||||
color_incomplete = "#FF6060"
|
|
||||||
color_complete = "#A0FFA0"
|
|
||||||
color_futur = "#70E0FF"
|
|
||||||
|
|
||||||
year = formsemestre.annee_scolaire()
|
year = formsemestre.annee_scolaire()
|
||||||
events_by_day = collections.defaultdict(list) # date_iso : event
|
cal = CalendrierEval(year, evaluations, nt)
|
||||||
for e in evaluations:
|
cal_html = cal.get_html()
|
||||||
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)
|
|
||||||
|
|
||||||
return f"""
|
return f"""
|
||||||
{
|
{
|
||||||
@ -430,15 +485,15 @@ def formsemestre_evaluations_cal(formsemestre_id):
|
|||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>en <span style=
|
<li>en <span style=
|
||||||
"background-color: {color_incomplete}">rouge</span>
|
"background-color: {JourEval.COLOR_INCOMPLETE}">rouge</span>
|
||||||
les évaluations passées auxquelles il manque des notes
|
les évaluations passées auxquelles il manque des notes
|
||||||
</li>
|
</li>
|
||||||
<li>en <span style=
|
<li>en <span style=
|
||||||
"background-color: {color_complete}">vert</span>
|
"background-color: {JourEval.COLOR_COMPLETE}">vert</span>
|
||||||
les évaluations déjà notées
|
les évaluations déjà notées
|
||||||
</li>
|
</li>
|
||||||
<li>en <span style=
|
<li>en <span style=
|
||||||
"background-color: {color_futur}">bleu</span>
|
"background-color: {JourEval.COLOR_FUTUR}">bleu</span>
|
||||||
les évaluations futures
|
les évaluations futures
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user