forked from ScoDoc/ScoDoc
Fix change group/import etud admission
This commit is contained in:
parent
41a791282a
commit
d88e41b83e
@ -119,11 +119,12 @@ class Partition(db.Model):
|
||||
.first()
|
||||
)
|
||||
|
||||
def set_etud_group(self, etudid: int, group: "GroupDescr"):
|
||||
def set_etud_group(self, etudid: int, group: "GroupDescr") -> bool:
|
||||
"""Affect etudid to group_id in given partition.
|
||||
Raises IntegrityError si conflit,
|
||||
or ValueError si ce group_id n'est pas dans cette partition
|
||||
ou que l'étudiant n'est pas inscrit au semestre.
|
||||
Return True si changement, False s'il était déjà dans ce groupe.
|
||||
"""
|
||||
if not group.id in (g.id for g in self.groups):
|
||||
raise ScoValueError(
|
||||
@ -141,8 +142,19 @@ class Partition(db.Model):
|
||||
.filter_by(partition_id=self.id)
|
||||
.first()
|
||||
)
|
||||
existing_group_id = existing_row[1]
|
||||
if existing_row:
|
||||
existing_row.update({"group_id": group.id})
|
||||
if group.id == existing_group_id:
|
||||
return False
|
||||
update_row = (
|
||||
group_membership.update()
|
||||
.where(
|
||||
group_membership.c.etudid == etudid,
|
||||
group_membership.c.group_id == existing_group_id,
|
||||
)
|
||||
.values(group_id=group.id)
|
||||
)
|
||||
db.session.execute(update_row)
|
||||
else:
|
||||
new_row = group_membership.insert().values(
|
||||
etudid=etudid, group_id=group.id
|
||||
@ -152,6 +164,7 @@ class Partition(db.Model):
|
||||
except IntegrityError:
|
||||
db.session.rollback()
|
||||
raise
|
||||
return True
|
||||
|
||||
|
||||
class GroupDescr(db.Model):
|
||||
|
@ -664,16 +664,17 @@ def set_group(etudid: int, group_id: int) -> bool: # OBSOLETE !
|
||||
return True
|
||||
|
||||
|
||||
def change_etud_group_in_partition(etudid: int, group: GroupDescr):
|
||||
def change_etud_group_in_partition(etudid: int, group: GroupDescr) -> bool:
|
||||
"""Inscrit etud au groupe
|
||||
(et le desinscrit d'autres groupes de cette partition.)
|
||||
(et le désinscrit d'autres groupes de cette partition)
|
||||
Return True si changement, False s'il était déjà dans ce groupe.
|
||||
"""
|
||||
log(f"change_etud_group_in_partition: etudid={etudid} group={group}")
|
||||
|
||||
group.partition.set_etud_group(etudid, group)
|
||||
if not group.partition.set_etud_group(etudid, group):
|
||||
return # pas de changement
|
||||
|
||||
# - log
|
||||
formsemestre: FormSemestre = group.partition.formsemestre
|
||||
log(f"change_etud_group_in_partition: etudid={etudid} group={group}")
|
||||
Scolog.logdb(
|
||||
method="changeGroup",
|
||||
etudid=etudid,
|
||||
|
@ -639,10 +639,10 @@ def scolars_import_admission(datafile, formsemestre_id=None, type_admission=None
|
||||
fields = adm_get_fields(titles, formsemestre_id)
|
||||
idx_nom = None
|
||||
idx_prenom = None
|
||||
for idx in fields:
|
||||
if fields[idx][0] == "nom":
|
||||
for idx, field in fields.items():
|
||||
if field[0] == "nom":
|
||||
idx_nom = idx
|
||||
if fields[idx][0] == "prenom":
|
||||
if field[0] == "prenom":
|
||||
idx_prenom = idx
|
||||
if (idx_nom is None) or (idx_prenom is None):
|
||||
log("fields indices=" + ", ".join([str(x) for x in fields]))
|
||||
@ -664,21 +664,20 @@ def scolars_import_admission(datafile, formsemestre_id=None, type_admission=None
|
||||
# Retrouve l'étudiant parmi ceux du semestre par (nom, prenom)
|
||||
nom = adm_normalize_string(line[idx_nom])
|
||||
prenom = adm_normalize_string(line[idx_prenom])
|
||||
if not (nom, prenom) in etuds_by_nomprenom:
|
||||
log(
|
||||
"unable to find %s %s among members" % (line[idx_nom], line[idx_prenom])
|
||||
)
|
||||
if (nom, prenom) not in etuds_by_nomprenom:
|
||||
msg = f"""Étudiant <b>{line[idx_nom]} {line[idx_prenom]} inexistant</b>"""
|
||||
diag.append(msg)
|
||||
else:
|
||||
etud = etuds_by_nomprenom[(nom, prenom)]
|
||||
cur_adm = sco_etud.admission_list(cnx, args={"etudid": etud["etudid"]})[0]
|
||||
# peuple les champs presents dans le tableau
|
||||
args = {}
|
||||
for idx in fields:
|
||||
field_name, convertor = fields[idx]
|
||||
for idx, field in fields.items():
|
||||
field_name, convertor = field
|
||||
if field_name in modifiable_fields:
|
||||
try:
|
||||
val = convertor(line[idx])
|
||||
except ValueError:
|
||||
except ValueError as exc:
|
||||
raise ScoFormatError(
|
||||
'scolars_import_admission: valeur invalide, ligne %d colonne %s: "%s"'
|
||||
% (nline, field_name, line[idx]),
|
||||
@ -687,7 +686,7 @@ def scolars_import_admission(datafile, formsemestre_id=None, type_admission=None
|
||||
scodoc_dept=g.scodoc_dept,
|
||||
formsemestre_id=formsemestre_id,
|
||||
),
|
||||
)
|
||||
) from exc
|
||||
if val is not None: # note: ne peut jamais supprimer une valeur
|
||||
args[field_name] = val
|
||||
if args:
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- mode: python -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
SCOVERSION = "9.4.98"
|
||||
SCOVERSION = "9.4.99"
|
||||
|
||||
SCONAME = "ScoDoc"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user