From 104b5f2f950ab7a8e76860f70057f580d7295fe5 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 20 Sep 2023 22:38:01 +0200 Subject: [PATCH] =?UTF-8?q?Assiduit=C3=A9:=20ajouts=20de=20commentaires=20?= =?UTF-8?q?et=20tr=C3=A8s=20l=C3=A9ger=20refactoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/config.py | 20 +++++++- app/views/assiduites.py | 101 +++++++++++++++++++++++----------------- 2 files changed, 78 insertions(+), 43 deletions(-) diff --git a/app/models/config.py b/app/models/config.py index e54cda78..865fa517 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 88e9411b..c12eb3dc 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 = """