diff --git a/app/models/config.py b/app/models/config.py index e54cda781..865fa517d 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -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): diff --git a/app/views/assiduites.py b/app/views/assiduites.py index 88e9411be..c12eb3dcd 100644 --- a/app/views/assiduites.py +++ b/app/views/assiduites.py @@ -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 = """