From 66d443944ab2dc7f4d8ffbf8f86cc88f13305ffb Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 24 Oct 2021 18:28:01 +0200 Subject: [PATCH] Fix: partition_rename error message --- app/scodoc/sco_groups.py | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 120db6a43..14410977a 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -89,8 +89,8 @@ def get_group(group_id): """Returns group object, with partition""" r = ndb.SimpleDictFetch( """SELECT gd.id AS group_id, gd.*, p.id AS partition_id, p.* - FROM group_descr gd, partition p - WHERE gd.id=%(group_id)s + FROM group_descr gd, partition p + WHERE gd.id=%(group_id)s AND p.id = gd.partition_id """, {"group_id": group_id}, @@ -112,8 +112,8 @@ def group_delete(group, force=False): def get_partition(partition_id): r = ndb.SimpleDictFetch( - """SELECT p.id AS partition_id, p.* - FROM partition p + """SELECT p.id AS partition_id, p.* + FROM partition p WHERE p.id = %(partition_id)s """, {"partition_id": partition_id}, @@ -126,7 +126,7 @@ def get_partition(partition_id): def get_partitions_list(formsemestre_id, with_default=True): """Liste des partitions pour ce semestre (list of dicts)""" partitions = ndb.SimpleDictFetch( - """SELECT p.id AS partition_id, p.* + """SELECT p.id AS partition_id, p.* FROM partition p WHERE formsemestre_id=%(formsemestre_id)s ORDER BY numero""", @@ -143,7 +143,7 @@ def get_default_partition(formsemestre_id): """Get partition for 'all' students (this one always exists, with NULL name)""" r = ndb.SimpleDictFetch( """SELECT p.id AS partition_id, p.* FROM partition p - WHERE formsemestre_id=%(formsemestre_id)s + WHERE formsemestre_id=%(formsemestre_id)s AND partition_name is NULL """, {"formsemestre_id": formsemestre_id}, @@ -170,10 +170,10 @@ def get_partition_groups(partition): """List of groups in this partition (list of dicts). Some groups may be empty.""" return ndb.SimpleDictFetch( - """SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.* - FROM group_descr gd, partition p - WHERE gd.partition_id=%(partition_id)s - AND gd.partition_id=p.id + """SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.* + FROM group_descr gd, partition p + WHERE gd.partition_id=%(partition_id)s + AND gd.partition_id=p.id ORDER BY group_name """, partition, @@ -184,9 +184,9 @@ def get_default_group(formsemestre_id, fix_if_missing=False): """Returns group_id for default ('tous') group""" r = ndb.SimpleDictFetch( """SELECT gd.id AS group_id - FROM group_descr gd, partition p - WHERE p.formsemestre_id=%(formsemestre_id)s - AND p.partition_name is NULL + FROM group_descr gd, partition p + WHERE p.formsemestre_id=%(formsemestre_id)s + AND p.partition_name is NULL AND p.id = gd.partition_id """, {"formsemestre_id": formsemestre_id}, @@ -218,8 +218,8 @@ def get_sem_groups(formsemestre_id): """Returns groups for this sem (in all partitions).""" return ndb.SimpleDictFetch( """SELECT gd.id AS group_id, p.id AS partition_id, gd.*, p.* - FROM group_descr gd, partition p - WHERE p.formsemestre_id=%(formsemestre_id)s + FROM group_descr gd, partition p + WHERE p.formsemestre_id=%(formsemestre_id)s AND p.id = gd.partition_id """, {"formsemestre_id": formsemestre_id}, @@ -340,7 +340,7 @@ def get_etud_groups(etudid, sem, exclude_default=False): """Infos sur groupes de l'etudiant dans ce semestre [ group + partition_name ] """ - req = """SELECT p.id AS partition_id, p.*, g.id AS group_id, g.* + req = """SELECT p.id AS partition_id, p.*, g.id AS group_id, g.* FROM group_descr g, partition p, group_membership gm WHERE gm.etudid=%(etudid)s and gm.group_id = g.id @@ -377,10 +377,10 @@ def formsemestre_get_etud_groupnames(formsemestre_id, attr="group_name"): { etudid : { partition_id : group_name }} (attr=group_name or group_id) """ infos = ndb.SimpleDictFetch( - """SELECT i.id AS etudid, p.id AS partition_id, - gd.group_name, gd.id AS group_id - FROM notes_formsemestre_inscription i, partition p, - group_descr gd, group_membership gm + """SELECT i.id AS etudid, p.id AS partition_id, + gd.group_name, gd.id AS group_id + FROM notes_formsemestre_inscription i, partition p, + group_descr gd, group_membership gm WHERE i.formsemestre_id=%(formsemestre_id)s and i.formsemestre_id = p.formsemestre_id and p.id = gd.partition_id @@ -413,7 +413,7 @@ def etud_add_group_infos(etud, sem, sep=" "): FROM group_descr g, partition p, group_membership gm WHERE gm.etudid=%(etudid)s and gm.group_id = g.id and g.partition_id = p.id - and p.formsemestre_id = %(formsemestre_id)s + and p.formsemestre_id = %(formsemestre_id)s ORDER BY p.numero """, {"etudid": etud["etudid"], "formsemestre_id": sem["formsemestre_id"]}, @@ -1141,13 +1141,13 @@ def partition_set_name(partition_id, partition_name, redirect=1): # check unicity r = ndb.SimpleDictFetch( - """SELECT p.* FROM partition p - WHERE p.partition_name = %(partition_name)s + """SELECT p.* FROM partition p + WHERE p.partition_name = %(partition_name)s AND formsemestre_id = %(formsemestre_id)s """, {"partition_name": partition_name, "formsemestre_id": formsemestre_id}, ) - if len(r) > 1 or (len(r) == 1 and r[0]["partition_id"] != partition_id): + if len(r) > 1 or (len(r) == 1 and r[0]["id"] != partition_id): raise ScoValueError( "Partition %s déjà existante dans ce semestre !" % partition_name ) @@ -1494,9 +1494,9 @@ def listgroups(group_ids): groups = [] for group_id in group_ids: cursor.execute( - """SELECT gd.id AS group_id, gd.*, p.id AS partition_id, p.* - FROM group_descr gd, partition p - WHERE p.id = gd.partition_id + """SELECT gd.id AS group_id, gd.*, p.id AS partition_id, p.* + FROM group_descr gd, partition p + WHERE p.id = gd.partition_id AND gd.id = %(group_id)s """, {"group_id": group_id},