forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -383,7 +383,7 @@ class ScoDocSiteConfig(db.Model):
|
||||
cls.set("personalized_links", "")
|
||||
raise ScoValueError(
|
||||
"Attention: liens personnalisés erronés: ils ont été effacés."
|
||||
)
|
||||
) from exc
|
||||
return [PersonalizedLink(**item) for item in links_dict]
|
||||
|
||||
@classmethod
|
||||
@ -395,6 +395,24 @@ class ScoDocSiteConfig(db.Model):
|
||||
data_links = json.dumps(links_dict)
|
||||
cls.set("personalized_links", data_links)
|
||||
|
||||
@classmethod
|
||||
def assi_get_rounded_time(cls, label: str, default: str) -> float:
|
||||
"Donne l'heure stockée dans la config globale sous label, en float arrondi au quart d'heure"
|
||||
_round_time_str_to_quarter(cls.get(label, default))
|
||||
|
||||
|
||||
def _round_time_str_to_quarter(string: str) -> float:
|
||||
"""Prend une heure iso '12:20:23', et la converti en un nombre d'heures
|
||||
en arrondissant au quart d'heure: (les secondes sont ignorées)
|
||||
"12:20:00" -> 12.25
|
||||
"12:29:00" -> 12.25
|
||||
"12:30:00" -> 12.5
|
||||
"""
|
||||
parts = [*map(float, string.split(":"))]
|
||||
hour = parts[0]
|
||||
minutes = round(parts[1] / 60 * 4) / 4
|
||||
return hour + minutes
|
||||
|
||||
|
||||
class PersonalizedLink:
|
||||
def __init__(self, title: str = "", url: str = "", with_args: bool = False):
|
||||
|
@ -1,3 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Gestion scolarite IUT
|
||||
#
|
||||
# Copyright (c) 1999 - 2023 Emmanuel Viennet. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
||||
# module codé par Matthias Hartmann, 2023
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import datetime
|
||||
|
||||
from flask import g, request, render_template, flash
|
||||
@ -18,7 +44,6 @@ from app.models import (
|
||||
Assiduite,
|
||||
Justificatif,
|
||||
Departement,
|
||||
FormSemestreInscription,
|
||||
Evaluation,
|
||||
)
|
||||
from app.views import assiduites_bp as bp
|
||||
@ -304,9 +329,11 @@ def signal_assiduites_etud():
|
||||
|
||||
# Gestion des horaires (journée, matin, soir)
|
||||
|
||||
morning = get_time("assi_morning_time", "08:00:00")
|
||||
lunch = get_time("assi_lunch_time", "13:00:00")
|
||||
afternoon = get_time("assi_afternoon_time", "18:00:00")
|
||||
morning = ScoDocSiteConfig.assi_get_rounded_time("assi_morning_time", "08:00:00")
|
||||
lunch = ScoDocSiteConfig.assi_get_rounded_time("assi_lunch_time", "13:00:00")
|
||||
afternoon = ScoDocSiteConfig.assi_get_rounded_time(
|
||||
"assi_afternoon_time", "18:00:00"
|
||||
)
|
||||
|
||||
select = """
|
||||
<select class="dynaSelect">
|
||||
@ -1360,8 +1387,8 @@ def _dynamic_module_selector():
|
||||
def _timeline(formsemestre_id=None) -> HTMLElement:
|
||||
return render_template(
|
||||
"assiduites/widgets/timeline.j2",
|
||||
t_start=get_time("assi_morning_time", "08:00:00"),
|
||||
t_end=get_time("assi_afternoon_time", "18:00:00"),
|
||||
t_start=ScoDocSiteConfig.assi_get_rounded_time("assi_morning_time", "08:00:00"),
|
||||
t_end=ScoDocSiteConfig.assi_get_rounded_time("assi_afternoon_time", "18:00:00"),
|
||||
tick_time=ScoDocSiteConfig.get("assi_tick_time", 15),
|
||||
periode_defaut=sco_preferences.get_preference(
|
||||
"periode_defaut", formsemestre_id
|
||||
@ -1372,49 +1399,39 @@ def _timeline(formsemestre_id=None) -> HTMLElement:
|
||||
def _mini_timeline() -> HTMLElement:
|
||||
return render_template(
|
||||
"assiduites/widgets/minitimeline.j2",
|
||||
t_start=get_time("assi_morning_time", "08:00:00"),
|
||||
t_end=get_time("assi_afternoon_time", "18:00:00"),
|
||||
t_start=ScoDocSiteConfig.assi_get_rounded_time("assi_morning_time", "08:00:00"),
|
||||
t_end=ScoDocSiteConfig.assi_get_rounded_time("assi_afternoon_time", "18:00:00"),
|
||||
)
|
||||
|
||||
|
||||
def _non_work_days():
|
||||
non_travail = sco_preferences.get_preference("non_travail", None)
|
||||
def _non_work_days() -> str:
|
||||
"""Abbréviation des jours non travaillés: "'sam','dim'".
|
||||
donnés par les préférences du département
|
||||
"""
|
||||
non_travail = sco_preferences.get_preference("non_travail")
|
||||
non_travail = non_travail.replace(" ", "").split(",")
|
||||
return ",".join([f"'{i.lower()}'" for i in non_travail])
|
||||
|
||||
|
||||
def _str_to_num(string: str):
|
||||
parts = [*map(float, string.split(":"))]
|
||||
hour = parts[0]
|
||||
minutes = round(parts[1] / 60 * 4) / 4
|
||||
return hour + minutes
|
||||
|
||||
|
||||
def get_time(label: str, default: str):
|
||||
return _str_to_num(ScoDocSiteConfig.get(label, default))
|
||||
|
||||
|
||||
def _get_seuil():
|
||||
def _get_seuil() -> int:
|
||||
"""Seuil d'alerte des absences (en unité de la métrique),
|
||||
tel que fixé dans les préférences du département."""
|
||||
return sco_preferences.get_preference("assi_seuil", dept_id=g.scodoc_dept_id)
|
||||
|
||||
|
||||
def _get_etuds_dem_def(formsemestre):
|
||||
etuds_dem_def = [
|
||||
(f.etudid, f.etat)
|
||||
for f in FormSemestreInscription.query.filter(
|
||||
FormSemestreInscription.formsemestre_id == formsemestre.id,
|
||||
FormSemestreInscription.etat != "I",
|
||||
).all()
|
||||
]
|
||||
|
||||
template: str = '"£" : "$",'
|
||||
|
||||
json_str: str = "{"
|
||||
|
||||
for etud in etuds_dem_def:
|
||||
json_str += template.replace("£", str(etud[0])).replace("$", etud[1])
|
||||
|
||||
if json_str != "{":
|
||||
json_str = json_str[:-1]
|
||||
|
||||
return json_str + "}"
|
||||
def _get_etuds_dem_def(formsemestre) -> str:
|
||||
"""Une chaine json donnant les étudiants démissionnaires ou défaillants
|
||||
du formsemestre, sous la forme
|
||||
'{"516" : "D", ... }'
|
||||
"""
|
||||
return (
|
||||
"{"
|
||||
+ ", ".join(
|
||||
[
|
||||
f'"{ins.etudid}" : "{ins.etat}"'
|
||||
for ins in formsemestre.inscriptions
|
||||
if ins.etat != scu.INSCRIT
|
||||
]
|
||||
)
|
||||
+ "}"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user