From 9f8bfd3e2162729dbbd815b807c8b5fc8ab1f496 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 10 Feb 2022 21:55:06 +0100 Subject: [PATCH] refactoring / sco_groups sans nt --- app/models/evaluations.py | 98 +++++++++++++++++++++++++++++++-- app/scodoc/sco_evaluation_db.py | 98 ++------------------------------- app/scodoc/sco_groups.py | 14 ++--- sco_version.py | 3 +- 4 files changed, 108 insertions(+), 105 deletions(-) diff --git a/app/models/evaluations.py b/app/models/evaluations.py index b4e5f4e2f..46244a9a8 100644 --- a/app/models/evaluations.py +++ b/app/models/evaluations.py @@ -2,12 +2,16 @@ """ScoDoc models: evaluations """ +import datetime from app import db -from app.models import UniteEns +from app.models import formsemestre +from app.models.formsemestre import FormSemestre +from app.models.moduleimpls import ModuleImpl +from app.models.ues import UniteEns +from app.scodoc.sco_exceptions import ScoValueError import app.scodoc.notesdb as ndb -from app.scodoc import sco_evaluation_db class Evaluation(db.Model): @@ -51,11 +55,11 @@ class Evaluation(db.Model): e["evaluation_id"] = self.id e["jour"] = ndb.DateISOtoDMY(e["jour"]) e["numero"] = ndb.int_null_is_zero(e["numero"]) - return sco_evaluation_db.evaluation_enrich_dict(e) + return evaluation_enrich_dict(e) def from_dict(self, data): """Set evaluation attributes from given dict values.""" - sco_evaluation_db._check_evaluation_args(data) + check_evaluation_args(data) for k in self.__dict__.keys(): if k != "_sa_instance_state" and k != "id" and k in data: setattr(self, k, data[k]) @@ -145,3 +149,89 @@ class EvaluationUEPoids(db.Model): def __repr__(self): return f"" + + +# Fonction héritée de ScoDoc7 à refactorer +def evaluation_enrich_dict(e): + """add or convert some fileds in an evaluation dict""" + # For ScoDoc7 compat + heure_debut_dt = e["heure_debut"] or datetime.time( + 8, 00 + ) # au cas ou pas d'heure (note externe?) + heure_fin_dt = e["heure_fin"] or datetime.time(8, 00) + e["heure_debut"] = ndb.TimefromISO8601(e["heure_debut"]) + e["heure_fin"] = ndb.TimefromISO8601(e["heure_fin"]) + e["jouriso"] = ndb.DateDMYtoISO(e["jour"]) + heure_debut, heure_fin = e["heure_debut"], e["heure_fin"] + d = ndb.TimeDuration(heure_debut, heure_fin) + if d is not None: + m = d % 60 + e["duree"] = "%dh" % (d / 60) + if m != 0: + e["duree"] += "%02d" % m + else: + e["duree"] = "" + if heure_debut and (not heure_fin or heure_fin == heure_debut): + e["descrheure"] = " à " + heure_debut + elif heure_debut and heure_fin: + e["descrheure"] = " de %s à %s" % (heure_debut, heure_fin) + else: + e["descrheure"] = "" + # matin, apresmidi: utile pour se referer aux absences: + if heure_debut_dt < datetime.time(12, 00): + e["matin"] = 1 + else: + e["matin"] = 0 + if heure_fin_dt > datetime.time(12, 00): + e["apresmidi"] = 1 + else: + e["apresmidi"] = 0 + return e + + +def check_evaluation_args(args): + "Check coefficient, dates and duration, raises exception if invalid" + moduleimpl_id = args["moduleimpl_id"] + # check bareme + note_max = args.get("note_max", None) + if note_max is None: + raise ScoValueError("missing note_max") + try: + note_max = float(note_max) + except ValueError: + raise ScoValueError("Invalid note_max value") + if note_max < 0: + raise ScoValueError("Invalid note_max value (must be positive or null)") + # check coefficient + coef = args.get("coefficient", None) + if coef is None: + raise ScoValueError("missing coefficient") + try: + coef = float(coef) + except ValueError: + raise ScoValueError("Invalid coefficient value") + if coef < 0: + raise ScoValueError("Invalid coefficient value (must be positive or null)") + # check date + jour = args.get("jour", None) + args["jour"] = jour + if jour: + modimpl = ModuleImpl.query.get(moduleimpl_id) + formsemestre = modimpl.formsemestre + y, m, d = [int(x) for x in ndb.DateDMYtoISO(jour).split("-")] + jour = datetime.date(y, m, d) + if (jour > formsemestre.date_fin) or (jour < formsemestre.date_debut): + raise ScoValueError( + "La date de l'évaluation (%s/%s/%s) n'est pas dans le semestre !" + % (d, m, y), + dest_url="javascript:history.back();", + ) + heure_debut = args.get("heure_debut", None) + args["heure_debut"] = heure_debut + heure_fin = args.get("heure_fin", None) + args["heure_fin"] = heure_fin + if jour and ((not heure_debut) or (not heure_fin)): + raise ScoValueError("Les heures doivent être précisées") + d = ndb.TimeDuration(heure_debut, heure_fin) + if d and ((d < 0) or (d > 60 * 12)): + raise ScoValueError("Heures de l'évaluation incohérentes !") diff --git a/app/scodoc/sco_evaluation_db.py b/app/scodoc/sco_evaluation_db.py index 6586ddd09..23bc45790 100644 --- a/app/scodoc/sco_evaluation_db.py +++ b/app/scodoc/sco_evaluation_db.py @@ -36,6 +36,8 @@ from flask import url_for, g from flask_login import current_user from app import log + +from app.models.evaluations import evaluation_enrich_dict, check_evaluation_args import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb from app.scodoc.sco_exceptions import AccessDenied, ScoValueError @@ -81,43 +83,6 @@ _evaluationEditor = ndb.EditableTable( ) -def evaluation_enrich_dict(e): - """add or convert some fileds in an evaluation dict""" - # For ScoDoc7 compat - heure_debut_dt = e["heure_debut"] or datetime.time( - 8, 00 - ) # au cas ou pas d'heure (note externe?) - heure_fin_dt = e["heure_fin"] or datetime.time(8, 00) - e["heure_debut"] = ndb.TimefromISO8601(e["heure_debut"]) - e["heure_fin"] = ndb.TimefromISO8601(e["heure_fin"]) - e["jouriso"] = ndb.DateDMYtoISO(e["jour"]) - heure_debut, heure_fin = e["heure_debut"], e["heure_fin"] - d = ndb.TimeDuration(heure_debut, heure_fin) - if d is not None: - m = d % 60 - e["duree"] = "%dh" % (d / 60) - if m != 0: - e["duree"] += "%02d" % m - else: - e["duree"] = "" - if heure_debut and (not heure_fin or heure_fin == heure_debut): - e["descrheure"] = " à " + heure_debut - elif heure_debut and heure_fin: - e["descrheure"] = " de %s à %s" % (heure_debut, heure_fin) - else: - e["descrheure"] = "" - # matin, apresmidi: utile pour se referer aux absences: - if heure_debut_dt < datetime.time(12, 00): - e["matin"] = 1 - else: - e["matin"] = 0 - if heure_fin_dt > datetime.time(12, 00): - e["apresmidi"] = 1 - else: - e["apresmidi"] = 0 - return e - - def do_evaluation_list(args, sortkey=None): """List evaluations, sorted by numero (or most recent date first). @@ -127,7 +92,7 @@ def do_evaluation_list(args, sortkey=None): 'apresmidi' : 1 (termine après 12:00) ou 0 'descrheure' : ' de 15h00 à 16h30' """ - # Attention: transformation fonction ScoDc7 en SQLAlchemy + # Attention: transformation fonction ScoDoc7 en SQLAlchemy cnx = ndb.GetDBConnexion() evals = _evaluationEditor.list(cnx, args, sortkey=sortkey) # calcule duree (chaine de car.) de chaque evaluation et ajoute jouriso, matin, apresmidi @@ -146,59 +111,6 @@ def do_evaluation_list_in_formsemestre(formsemestre_id): return evals -def _check_evaluation_args(args): - "Check coefficient, dates and duration, raises exception if invalid" - moduleimpl_id = args["moduleimpl_id"] - # check bareme - note_max = args.get("note_max", None) - if note_max is None: - raise ScoValueError("missing note_max") - try: - note_max = float(note_max) - except ValueError: - raise ScoValueError("Invalid note_max value") - if note_max < 0: - raise ScoValueError("Invalid note_max value (must be positive or null)") - # check coefficient - coef = args.get("coefficient", None) - if coef is None: - raise ScoValueError("missing coefficient") - try: - coef = float(coef) - except ValueError: - raise ScoValueError("Invalid coefficient value") - if coef < 0: - raise ScoValueError("Invalid coefficient value (must be positive or null)") - # check date - jour = args.get("jour", None) - args["jour"] = jour - if jour: - M = sco_moduleimpl.moduleimpl_list(moduleimpl_id=moduleimpl_id)[0] - sem = sco_formsemestre.get_formsemestre(M["formsemestre_id"]) - d, m, y = [int(x) for x in sem["date_debut"].split("/")] - date_debut = datetime.date(y, m, d) - d, m, y = [int(x) for x in sem["date_fin"].split("/")] - date_fin = datetime.date(y, m, d) - # passe par ndb.DateDMYtoISO pour avoir date pivot - y, m, d = [int(x) for x in ndb.DateDMYtoISO(jour).split("-")] - jour = datetime.date(y, m, d) - if (jour > date_fin) or (jour < date_debut): - raise ScoValueError( - "La date de l'évaluation (%s/%s/%s) n'est pas dans le semestre !" - % (d, m, y), - dest_url="javascript:history.back();", - ) - heure_debut = args.get("heure_debut", None) - args["heure_debut"] = heure_debut - heure_fin = args.get("heure_fin", None) - args["heure_fin"] = heure_fin - if jour and ((not heure_debut) or (not heure_fin)): - raise ScoValueError("Les heures doivent être précisées") - d = ndb.TimeDuration(heure_debut, heure_fin) - if d and ((d < 0) or (d > 60 * 12)): - raise ScoValueError("Heures de l'évaluation incohérentes !") - - def do_evaluation_create( moduleimpl_id=None, jour=None, @@ -220,7 +132,7 @@ def do_evaluation_create( ) args = locals() log("do_evaluation_create: args=" + str(args)) - _check_evaluation_args(args) + check_evaluation_args(args) # Check numeros module_evaluation_renumber(moduleimpl_id, only_if_unumbered=True) if not "numero" in args or args["numero"] is None: @@ -288,7 +200,7 @@ def do_evaluation_edit(args): "Modification évaluation impossible pour %s" % current_user.get_nomplogin() ) args["moduleimpl_id"] = moduleimpl_id - _check_evaluation_args(args) + check_evaluation_args(args) cnx = ndb.GetDBConnexion() _evaluationEditor.edit(cnx, args) diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index d1cfb47d8..d5d55ea76 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -45,6 +45,9 @@ from flask import g, request from flask import url_for, make_response from app import db +from app.comp import res_sem +from app.comp.res_common import NotesTableCompat +from app.models import FormSemestre from app.models import GROUPNAME_STR_LEN, SHORT_STR_LEN from app.models.groups import Partition import app.scodoc.sco_utils as scu @@ -488,17 +491,14 @@ def XMLgetGroupsInPartition(partition_id): # was XMLgetGroupesTD ... """ - from app.scodoc import sco_formsemestre - - cnx = ndb.GetDBConnexion() - t0 = time.time() partition = get_partition(partition_id) formsemestre_id = partition["formsemestre_id"] - sem = sco_formsemestre.get_formsemestre(formsemestre_id) + formsemestre = FormSemestre.query.get_or_404(formsemestre_id) + etuds_set = {ins.etudid for ins in formsemestre.inscriptions} + + sem = formsemestre.get_infos_dict() # transition TODO groups = get_partition_groups(partition) - nt = sco_cache.NotesTableCache.get(formsemestre_id) # > inscrdict - etuds_set = set(nt.inscrdict) # Build XML: t1 = time.time() doc = Element("ajax-response") diff --git a/sco_version.py b/sco_version.py index a75f9a940..bda50cef4 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,13 +1,14 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.1.50a" +SCOVERSION = "9.1.50" SCONAME = "ScoDoc" SCONEWS = """

Année 2021

    +
  • ScoDoc 9.1.50: nombreuses amélioration gestion BUT
  • ScoDoc 9.1: gestion des formations par compétences, type BUT.
  • ScoDoc 9.0: nouvelle architecture logicielle (Flask/Python3/Debian 11)
  • Version mobile (en test)