From 78c7c1a7631ef754d5638e8123c64dde9cb2c6f7 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 16 Dec 2021 22:54:24 +0100 Subject: [PATCH] =?UTF-8?q?Clonage=20semestre=20avec=20poids=20des=20?= =?UTF-8?q?=C3=A9valuation.=20Closes=20#221?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/evaluations.py | 37 +++++++++++++++-------------- app/scodoc/sco_formsemestre_edit.py | 17 ++++++------- app/scodoc/sco_groups.py | 2 +- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/app/models/evaluations.py b/app/models/evaluations.py index 1870607a7..9a237c5c9 100644 --- a/app/models/evaluations.py +++ b/app/models/evaluations.py @@ -56,24 +56,25 @@ class Evaluation(db.Model): e["numero"] = ndb.int_null_is_zero(e["numero"]) return sco_evaluation_db.evaluation_enrich_dict(e) - # def from_dict(self, data): - # """Set evaluation attributes from given dict values.""" - # sco_evaluation_db._check_evaluation_args(data) - # for field in [ - # "moduleimpl_id", - # "jour", - # "heure_debut", - # "heure_fin", - # "description", - # "note_max", - # "coefficient", - # "visibulletin", - # "publish_incomplete", - # "evaluation_type", - # "numero", - # ]: - # if field in data: - # setattr(self, field, data[field] or None) + def from_dict(self, data): + """Set evaluation attributes from given dict values.""" + sco_evaluation_db._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]) + + def clone(self, not_copying=()): + """Clone, not copying the given attrs + Attention: la copie n'a pas d'id avant le prochain commit + """ + d = dict(self.__dict__) + d.pop("id") # get rid of id + d.pop("_sa_instance_state") # get rid of SQLAlchemy special attr + for k in not_copying: + d.pop(k) + copy = self.__class__(**d) + db.session.add(copy) + return copy def set_ue_poids(self, ue, poids: float): """Set poids évaluation vers cette UE""" diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index 8618542dd..2f9308f7e 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -1033,14 +1033,15 @@ def do_formsemestre_clone( sco_moduleimpl.do_ens_create(args) # optionally, copy evaluations if clone_evaluations: - evals = sco_evaluation_db.do_evaluation_list( - args={"moduleimpl_id": mod_orig["moduleimpl_id"]} - ) - for e in evals: - args = e.copy() - del args["jour"] # erase date - args["moduleimpl_id"] = mid - _ = sco_evaluation_db.do_evaluation_create(**args) + for e in Evaluation.query.filter_by( + moduleimpl_id=mod_orig["moduleimpl_id"] + ): + # copie en enlevant la date + new_eval = e.clone(not_copying=("jour", "moduleimpl_id")) + new_eval.moduleimpl_id = mid + # Copie les poids APC de l'évaluation + new_eval.set_ue_poids_dict(e.get_ue_poids_dict()) + db.session.commit() # 3- copy uecoefs objs = sco_formsemestre.formsemestre_uecoef_list( diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 3f3f167f5..7a7414012 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -45,7 +45,7 @@ import flask from flask import g, request from flask import url_for, make_response -from app.models import Partition +from app.models.groups import Partition import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb from app import log, cache