Clonage semestre avec poids des évaluation. Closes #221

This commit is contained in:
Emmanuel Viennet 2021-12-16 22:54:24 +01:00
parent 40b31602d2
commit 78c7c1a763
3 changed files with 29 additions and 27 deletions

View File

@ -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"""

View File

@ -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(

View File

@ -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