diff --git a/app/models/formations.py b/app/models/formations.py index a73e6b8345..bb0c5d6a73 100644 --- a/app/models/formations.py +++ b/app/models/formations.py @@ -51,7 +51,7 @@ class NotesUE(db.Model): nullable=False, ) ects = db.Column(db.Float) # nombre de credits ECTS - is_external = db.Column(db.Boolean(), nullable=False, default=False) + is_external = db.Column(db.Boolean(), default=False) # id de l'element pedagogique Apogee correspondant: code_apogee = db.Column(db.String(APO_CODE_STR_LEN)) # coef UE, utilise seulement si l'option use_ue_coefs est activée: @@ -88,7 +88,7 @@ class NotesModule(db.Model): heures_td = db.Column(db.Float) heures_tp = db.Column(db.Float) coefficient = db.Column(db.Float) # coef PPN - ue_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id")) + ue_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"), index=True) formation_id = db.Column(db.Integer, db.ForeignKey("notes_formations.id")) matiere_id = db.Column(db.Integer, db.ForeignKey("notes_matieres.id")) # pas un id mais le numéro du semestre: 1, 2, ... diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index 7e89ba7fbd..372582924a 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -206,6 +206,7 @@ class NotesModuleImpl(db.Model): formsemestre_id = db.Column( db.Integer, db.ForeignKey("notes_formsemestre.id"), + index=True, ) responsable_id = db.Column("responsable_id", db.Integer, db.ForeignKey("user.id")) # formule de calcul moyenne: @@ -232,12 +233,12 @@ class NotesModuleImplInscription(db.Model): id = db.Column(db.Integer, primary_key=True) moduleimpl_inscription_id = db.synonym("id") - db.Column( - "moduleimpl_id", + moduleimpl_id = db.Column( db.Integer, - db.ForeignKey("notes_moduleimpl.moduleimpl_id"), + db.ForeignKey("notes_moduleimpl.id"), + index=True, ) - etudid = db.Column(db.Integer, db.ForeignKey("identite.id")) + etudid = db.Column(db.Integer, db.ForeignKey("identite.id"), index=True) class NotesEvaluation(db.Model): @@ -247,6 +248,9 @@ class NotesEvaluation(db.Model): id = db.Column(db.Integer, primary_key=True) evaluation_id = db.synonym("id") + moduleimpl_id = db.Column( + db.Integer, db.ForeignKey("notes_moduleimpl.moduleimpl_id"), index=True + ) jour = db.Column(db.Date) heure_debut = db.Column(db.Time) heure_fin = db.Column(db.Time) diff --git a/app/models/groups.py b/app/models/groups.py index 312c1d00f7..0092208a25 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -20,6 +20,7 @@ class Partition(db.Model): formsemestre_id = db.Column( db.Integer, db.ForeignKey("notes_formsemestre.id"), + index=True, ) # "TD", "TP", ... (NULL for 'all') partition_name = db.Column(db.String(SHORT_STR_LEN)) diff --git a/app/scodoc/sco_abs_notification.py b/app/scodoc/sco_abs_notification.py index 9b92563c57..7e74c191fe 100644 --- a/app/scodoc/sco_abs_notification.py +++ b/app/scodoc/sco_abs_notification.py @@ -271,9 +271,11 @@ def retreive_current_formsemestre(context, etudid, cur_date): """Get formsemestre dans lequel etudid est (ou était) inscrit a la date indiquée date est une chaine au format ISO (yyyy-mm-dd) """ - req = """SELECT i.formsemestre_id FROM notes_formsemestre_inscription i, notes_formsemestre sem - WHERE sem.formsemestre_id = i.formsemestre_id AND i.etudid=%(etudid)s - AND (%(cur_date)s >= sem.date_debut) AND (%(cur_date)s <= sem.date_fin)""" + req = """SELECT i.formsemestre_id + FROM notes_formsemestre_inscription i, notes_formsemestre sem + WHERE sem.id = i.formsemestre_id AND i.etudid = %(etudid)s + AND (%(cur_date)s >= sem.date_debut) AND (%(cur_date)s <= sem.date_fin) + """ r = ndb.SimpleDictFetch(req, {"etudid": etudid, "cur_date": cur_date}) if not r: @@ -284,9 +286,10 @@ def retreive_current_formsemestre(context, etudid, cur_date): def mod_with_evals_at_date(context, date_abs, etudid): - """Liste des moduleimpls avec des evaluations a la date indiquée""" - req = """SELECT m.* FROM notes_moduleimpl m, notes_evaluation e, notes_moduleimpl_inscription i - WHERE m.moduleimpl_id = e.moduleimpl_id AND e.moduleimpl_id = i.moduleimpl_id + """Liste des moduleimpls avec des evaluations à la date indiquée""" + req = """SELECT m.id AS moduleimpl_id, m.* + FROM notes_moduleimpl m, notes_evaluation e, notes_moduleimpl_inscription i + WHERE m.id = e.moduleimpl_id AND e.moduleimpl_id = i.moduleimpl_id AND i.etudid = %(etudid)s AND e.jour = %(date_abs)s""" r = ndb.SimpleDictFetch(req, {"etudid": etudid, "date_abs": date_abs}) return r diff --git a/app/scodoc/sco_debouche.py b/app/scodoc/sco_debouche.py index fba445ec56..f7294896e1 100644 --- a/app/scodoc/sco_debouche.py +++ b/app/scodoc/sco_debouche.py @@ -93,10 +93,10 @@ def get_etudids_with_debouche(context, start_year): r = ndb.SimpleDictFetch( """SELECT DISTINCT i.etudid - FROM notes_formsemestre_inscription i, notes_formsemestre s, itemsuivi it - WHERE i.etudid = it.etudid - AND i.formsemestre_id = s.formsemestre_id AND s.date_fin >= %(start_date)s - """, + FROM notes_formsemestre_inscription i, notes_formsemestre s, itemsuivi it + WHERE i.etudid = it.etudid + AND i.formsemestre_id = s.id AND s.date_fin >= %(start_date)s + """, {"start_date": start_date}, ) @@ -321,7 +321,7 @@ def itemsuivi_tag_list(context, itemsuivi_id): r = ndb.SimpleDictFetch( """SELECT t.title FROM itemsuivi_tags_assoc a, itemsuivi_tags t - WHERE a.tag_id = t.tag_id + WHERE a.tag_id = t.id AND a.itemsuivi_id = %(itemsuivi_id)s """, {"itemsuivi_id": itemsuivi_id}, diff --git a/app/scodoc/sco_edit_matiere.py b/app/scodoc/sco_edit_matiere.py index cd80bf8736..b3af967efb 100644 --- a/app/scodoc/sco_edit_matiere.py +++ b/app/scodoc/sco_edit_matiere.py @@ -320,9 +320,13 @@ def matiere_is_locked(context, matiere_id): (contains modules used in a locked formsemestre) """ r = ndb.SimpleDictFetch( - """SELECT ma.* from notes_matieres ma, notes_modules mod, notes_formsemestre sem, notes_moduleimpl mi - WHERE ma.matiere_id = mod.matiere_id AND mi.module_id = mod.module_id AND mi.formsemestre_id = sem.formsemestre_id - AND ma.matiere_id = %(matiere_id)s AND sem.etat = 0 + """SELECT ma.id + FROM notes_matieres ma, notes_modules mod, notes_formsemestre sem, notes_moduleimpl mi + WHERE ma.id = mod.matiere_id + AND mi.module_id = mod.id + AND mi.formsemestre_id = sem.id + AND ma.id = %(matiere_id)s + AND sem.etat = false """, {"matiere_id": matiere_id}, ) diff --git a/app/scodoc/sco_edit_module.py b/app/scodoc/sco_edit_module.py index ae15dad960..f087cd1e5c 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/scodoc/sco_edit_module.py @@ -360,7 +360,12 @@ def module_edit(context, module_id=None, REQUEST=None): )[0] parcours = sco_codes_parcours.get_parcours_from_code(Fo["type_parcours"]) M = ndb.SimpleDictFetch( - "SELECT ue.acronyme, mat.* FROM notes_matieres mat, notes_ue ue WHERE mat.ue_id = ue.ue_id AND ue.formation_id = %(formation_id)s ORDER BY ue.numero, mat.numero", + """SELECT ue.acronyme, mat.*, mat.id AS matiere_id + FROM notes_matieres mat, notes_ue ue + WHERE mat.ue_id = ue.id + AND ue.formation_id = %(formation_id)s + ORDER BY ue.numero, mat.numero + """, {"formation_id": Mod["formation_id"]}, ) Mnames = ["%s / %s" % (x["acronyme"], x["titre"]) for x in M] @@ -567,9 +572,12 @@ def module_is_locked(context, module_id): (used in a locked formsemestre) """ r = ndb.SimpleDictFetch( - """SELECT mi.* from notes_modules mod, notes_formsemestre sem, notes_moduleimpl mi - WHERE mi.module_id = mod.module_id AND mi.formsemestre_id = sem.formsemestre_id - AND mi.module_id = %(module_id)s AND sem.etat = 0 + """SELECT mi.id + FROM notes_modules mod, notes_formsemestre sem, notes_moduleimpl mi + WHERE mi.module_id = mod.id + AND mi.formsemestre_id = sem.id + AND mi.module_id = %(module_id)s + AND sem.etat = false """, {"module_id": module_id}, ) diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index 7f04bcf896..70b44152ea 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -942,10 +942,11 @@ def ue_is_locked(context, ue_id): (contains modules used in a locked formsemestre) """ r = ndb.SimpleDictFetch( - """SELECT ue.* FROM notes_ue ue, notes_modules mod, notes_formsemestre sem, notes_moduleimpl mi - WHERE ue.ue_id = mod.ue_id - AND mi.module_id = mod.module_id AND mi.formsemestre_id = sem.formsemestre_id - AND ue.ue_id = %(ue_id)s AND sem.etat = 0 + """SELECT ue.id + FROM notes_ue ue, notes_modules mod, notes_formsemestre sem, notes_moduleimpl mi + WHERE ue.id = mod.ue_id + AND mi.module_id = mod.id AND mi.formsemestre_id = sem.id + AND ue.id = %(ue_id)s AND sem.etat = false """, {"ue_id": ue_id}, ) diff --git a/app/scodoc/sco_export_results.py b/app/scodoc/sco_export_results.py index d1e6fc2126..7292e313ee 100644 --- a/app/scodoc/sco_export_results.py +++ b/app/scodoc/sco_export_results.py @@ -205,10 +205,13 @@ def _build_results_list(context, dpv_by_sem, etuds_infos): def get_set_formsemestre_id_dates(context, start_date, end_date): """Ensemble des formsemestre_id entre ces dates""" s = ndb.SimpleDictFetch( - "SELECT formsemestre_id FROM notes_formsemestre WHERE date_debut >= %(start_date)s AND date_fin <= %(end_date)s", + """SELECT id + FROM notes_formsemestre + WHERE date_debut >= %(start_date)s AND date_fin <= %(end_date)s + """, {"start_date": start_date, "end_date": end_date}, ) - return {x["formsemestre_id"] for x in s} + return {x["id"] for x in s} def scodoc_table_results( diff --git a/app/scodoc/sco_find_etud.py b/app/scodoc/sco_find_etud.py index ba6d80ada4..4efbae7cbe 100644 --- a/app/scodoc/sco_find_etud.py +++ b/app/scodoc/sco_find_etud.py @@ -219,7 +219,11 @@ def search_etud_by_name(context, term, REQUEST=None): else: if may_be_nip: r = ndb.SimpleDictFetch( - "SELECT nom, prenom, code_nip FROM identite WHERE code_nip LIKE %(beginning)s ORDER BY nom", + """SELECT nom, prenom, code_nip + FROM identite + WHERE code_nip + LIKE %(beginning)s ORDER BY nom + """, {"beginning": term + "%"}, ) data = [ @@ -232,7 +236,11 @@ def search_etud_by_name(context, term, REQUEST=None): ] else: r = ndb.SimpleDictFetch( - "SELECT etudid, nom, prenom FROM identite WHERE nom LIKE %(beginning)s ORDER BY nom", + """SELECT id AS etudid, nom, prenom + FROM identite + WHERE nom LIKE %(beginning)s + ORDER BY nom + """, {"beginning": term + "%"}, ) diff --git a/app/scodoc/sco_formsemestre.py b/app/scodoc/sco_formsemestre.py index 529421dcdf..8cd91cd58c 100644 --- a/app/scodoc/sco_formsemestre.py +++ b/app/scodoc/sco_formsemestre.py @@ -277,7 +277,10 @@ def read_formsemestre_responsables(context, formsemestre_id): :returns: liste de chaines """ r = ndb.SimpleDictFetch( - "SELECT responsable_id FROM notes_formsemestre_responsables WHERE formsemestre_id = %(formsemestre_id)s", + """SELECT responsable_id + FROM notes_formsemestre_responsables + WHERE formsemestre_id = %(formsemestre_id)s + """, {"formsemestre_id": formsemestre_id}, ) return [x["responsable_id"] for x in r] @@ -339,7 +342,10 @@ def read_formsemestre_etapes(context, formsemestre_id): :returns: liste d'instance de ApoEtapeVDI """ r = ndb.SimpleDictFetch( - "SELECT etape_apo FROM notes_formsemestre_etapes WHERE formsemestre_id = %(formsemestre_id)s", + """SELECT etape_apo + FROM notes_formsemestre_etapes + WHERE formsemestre_id = %(formsemestre_id)s + """, {"formsemestre_id": formsemestre_id}, ) return [ApoEtapeVDI(x["etape_apo"]) for x in r if x["etape_apo"]] diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index 0da5be2a62..e10ab0fa7e 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -1343,7 +1343,10 @@ def formsemestre_has_decisions_or_compensations(context, formsemestre_id): ou bien compensation de ce semestre par d'autre ssemestres. """ r = ndb.SimpleDictFetch( - "SELECT v.* FROM scolar_formsemestre_validation v WHERE v.formsemestre_id = %(formsemestre_id)s OR v.compense_formsemestre_id = %(formsemestre_id)s", + """SELECT v.id AS formsemestre_validation_id, v.* + FROM scolar_formsemestre_validation v + WHERE v.formsemestre_id = %(formsemestre_id)s + OR v.compense_formsemestre_id = %(formsemestre_id)s""", {"formsemestre_id": formsemestre_id}, ) return r diff --git a/app/scodoc/sco_formsemestre_validation.py b/app/scodoc/sco_formsemestre_validation.py index 50c2f09814..8395b6bab7 100644 --- a/app/scodoc/sco_formsemestre_validation.py +++ b/app/scodoc/sco_formsemestre_validation.py @@ -1160,15 +1160,15 @@ def do_formsemestre_validate_previous_ue( def _invalidate_etud_formation_caches(context, etudid, formation_id): "Invalide tous les semestres de cette formation où l'etudiant est inscrit..." r = ndb.SimpleDictFetch( - """SELECT sem.* + """SELECT sem.id FROM notes_formsemestre sem, notes_formsemestre_inscription i WHERE sem.formation_id = %(formation_id)s - AND i.formsemestre_id = sem.formsemestre_id + AND i.formsemestre_id = sem.id AND i.etudid = %(etudid)s """, {"etudid": etudid, "formation_id": formation_id}, ) - for fsid in [s["formsemestre_id"] for s in r]: + for fsid in [s["id"] for s in r]: sco_cache.invalidate_formsemestre( formsemestre_id=fsid ) # > modif decision UE (inval tous semestres avec cet etudiant, ok mais conservatif) @@ -1177,8 +1177,10 @@ def _invalidate_etud_formation_caches(context, etudid, formation_id): def get_etud_ue_cap_html(context, etudid, formsemestre_id, ue_id, REQUEST=None): """Ramene bout de HTML pour pouvoir supprimer une validation de cette UE""" valids = ndb.SimpleDictFetch( - """SELECT SFV.* FROM scolar_formsemestre_validation SFV - WHERE ue_id=%(ue_id)s AND etudid=%(etudid)s""", + """SELECT SFV.* + FROM scolar_formsemestre_validation SFV + WHERE ue_id=%(ue_id)s + AND etudid=%(etudid)s""", {"etudid": etudid, "ue_id": ue_id}, ) if not valids: @@ -1239,12 +1241,13 @@ def check_formation_ues(context, formation_id): for ue in ues: # formsemestres utilisant cette ue ? sems = ndb.SimpleDictFetch( - """SELECT DISTINCT sem.* + """SELECT DISTINCT sem.id AS formsemestre_id, sem.* FROM notes_formsemestre sem, notes_modules mod, notes_moduleimpl mi WHERE sem.formation_id = %(formation_id)s - AND mod.module_id = mi.module_id - AND mi.formsemestre_id = sem.formsemestre_id - AND mod.ue_id = %(ue_id)s""", + AND mod.id = mi.module_id + AND mi.formsemestre_id = sem.id + AND mod.ue_id = %(ue_id)s + """, {"ue_id": ue["ue_id"], "formation_id": formation_id}, ) semestre_ids = set([x["semestre_id"] for x in sems]) diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 4a00115324..798ede77ba 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -98,7 +98,11 @@ group_list = groupEditor.list def get_group(context, group_id): """Returns group object, with partition""" r = ndb.SimpleDictFetch( - "SELECT gd.*, p.* FROM group_descr gd, partition p WHERE gd.group_id=%(group_id)s AND p.partition_id = gd.partition_id", + """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 + AND p.id = gd.partition_id + """, {"group_id": group_id}, ) if not r: @@ -118,7 +122,10 @@ def group_delete(context, group, force=False): def get_partition(context, partition_id): r = ndb.SimpleDictFetch( - "SELECT p.* FROM partition p WHERE p.partition_id = %(partition_id)s", + """SELECT p.id AS partition_id, p.* + FROM partition p + WHERE p.id = %(partition_id)s + """, {"partition_id": partition_id}, ) if not r: @@ -129,7 +136,10 @@ def get_partition(context, partition_id): def get_partitions_list(context, formsemestre_id, with_default=True): """Liste des partitions pour ce semestre (list of dicts)""" partitions = ndb.SimpleDictFetch( - "SELECT * FROM partition WHERE formsemestre_id=%(formsemestre_id)s order by numero", + """SELECT p.id AS partition_id, p.* + FROM partition p + WHERE formsemestre_id=%(formsemestre_id)s + ORDER BY numero""", {"formsemestre_id": formsemestre_id}, ) # Move 'all' at end of list (for menus) @@ -142,7 +152,10 @@ def get_partitions_list(context, formsemestre_id, with_default=True): def get_default_partition(context, formsemestre_id): """Get partition for 'all' students (this one always exists, with NULL name)""" r = ndb.SimpleDictFetch( - "SELECT * FROM partition WHERE formsemestre_id=%(formsemestre_id)s AND partition_name is NULL", + """SELECT p.id AS partition_id, p.* FROM partition p + WHERE formsemestre_id=%(formsemestre_id)s + AND partition_name is NULL + """, {"formsemestre_id": formsemestre_id}, ) if len(r) != 1: @@ -169,7 +182,12 @@ def get_partition_groups(context, partition): """List of groups in this partition (list of dicts). Some groups may be empty.""" return ndb.SimpleDictFetch( - "SELECT gd.*, p.* FROM group_descr gd, partition p WHERE gd.partition_id=%(partition_id)s AND gd.partition_id=p.partition_id ORDER BY group_name", + """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.partition_id + ORDER BY group_name + """, partition, ) @@ -178,7 +196,12 @@ def get_default_group(formsemestre_id, fix_if_missing=False): """Returns group_id for default ('tous') group""" context = None # #context r = ndb.SimpleDictFetch( - "SELECT gd.group_id FROM group_descr gd, partition p WHERE p.formsemestre_id=%(formsemestre_id)s AND p.partition_name is NULL AND p.partition_id = gd.partition_id", + """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 + AND p.partition_id = gd.partition_id + """, {"formsemestre_id": formsemestre_id}, ) if len(r) == 0 and fix_if_missing: @@ -207,7 +230,11 @@ def get_default_group(formsemestre_id, fix_if_missing=False): def get_sem_groups(context, formsemestre_id): """Returns groups for this sem (in all partitions).""" return ndb.SimpleDictFetch( - "SELECT gd.*, p.* FROM group_descr gd, partition p WHERE p.formsemestre_id=%(formsemestre_id)s AND p.partition_id = gd.partition_id", + """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 + AND p.partition_id = gd.partition_id + """, {"formsemestre_id": formsemestre_id}, ) @@ -217,7 +244,17 @@ def get_group_members(context, group_id, etat=None): Si etat, filtre selon l'état de l'inscription Trié par nom_usuel (ou nom) puis prénom """ - req = "SELECT i.*, a.*, gm.*, ins.etat FROM identite i, adresse a, group_membership gm, group_descr gd, partition p, notes_formsemestre_inscription ins WHERE i.etudid = gm.etudid and a.etudid = i.etudid and ins.etudid = i.etudid and ins.formsemestre_id = p.formsemestre_id and p.partition_id = gd.partition_id and gd.group_id = gm.group_id and gm.group_id=%(group_id)s" + req = """SELECT i.id as etudid, i.*, a.*, gm.*, ins.etat + FROM identite i, adresse a, group_membership gm, + group_descr gd, partition p, notes_formsemestre_inscription ins + WHERE i.id = gm.etudid + and a.etudid = i.id + and ins.etudid = i.id + and ins.formsemestre_id = p.formsemestre_id + and p.id = gd.partition_id + and gd.id = gm.group_id + and gm.group_id=%(group_id)s + """ if etat is not None: req += " and ins.etat = %(etat)s" @@ -316,7 +353,13 @@ def get_etud_groups(context, etudid, sem, exclude_default=False): """Infos sur groupes de l'etudiant dans ce semestre [ group + partition_name ] """ - req = "SELECT p.*, g.* from group_descr g, partition p, group_membership gm WHERE gm.etudid=%(etudid)s and gm.group_id = g.group_id and g.partition_id = p.partition_id and p.formsemestre_id = %(formsemestre_id)s" + 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 + and g.partition_id = p.id + and p.formsemestre_id = %(formsemestre_id)s + """ if exclude_default: req += " and p.partition_name is not NULL" groups = ndb.SimpleDictFetch( @@ -347,7 +390,16 @@ def formsemestre_get_etud_groupnames(context, formsemestre_id, attr="group_name" { etudid : { partition_id : group_name }} (attr=group_name or group_id) """ infos = ndb.SimpleDictFetch( - "select i.etudid, p.partition_id, gd.group_name, gd.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.partition_id=gd.partition_id and gm.etudid=i.etudid and gm.group_id = gd.group_id and p.partition_name is not NULL", + """SELECT i.id AS etudid, p.is 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 + and gm.etudid=i.etudid + and gm.group_id = gd.group_id + and p.partition_name is not NULL + """, {"formsemestre_id": formsemestre_id}, ) R = {} @@ -369,7 +421,13 @@ def etud_add_group_infos(context, etud, sem, sep=" "): return etud infos = ndb.SimpleDictFetch( - "SELECT p.partition_name, g.* from group_descr g, partition p, group_membership gm WHERE gm.etudid=%(etudid)s and gm.group_id = g.group_id and g.partition_id = p.partition_id and p.formsemestre_id = %(formsemestre_id)s ORDER BY p.numero", + """SELECT p.partition_name, g.*, g.id AS group_id + 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 + ORDER BY p.numero + """, {"etudid": etud["etudid"], "formsemestre_id": sem["formsemestre_id"]}, ) @@ -395,7 +453,11 @@ def etud_add_group_infos(context, etud, sem, sep=" "): def get_etud_groups_in_partition(context, partition_id): """Returns { etudid : group }, with all students in this partition""" infos = ndb.SimpleDictFetch( - "SELECT gd.*, etudid from group_descr gd, group_membership gm where gd.partition_id = %(partition_id)s and gm.group_id = gd.group_id", + """SELECT gd.id as group_id, gd.*, etudid + FROM group_descr gd, group_membership gm + WHERE gd.partition_id = %(partition_id)s + AND gm.group_id = gd.group_id + """, {"partition_id": partition_id}, ) R = {} @@ -1063,7 +1125,10 @@ def partition_set_name(context, partition_id, partition_name, REQUEST=None, redi # check unicity r = ndb.SimpleDictFetch( - "SELECT p.* FROM partition p WHERE p.partition_name = %(partition_name)s AND formsemestre_id = %(formsemestre_id)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): diff --git a/app/scodoc/sco_moduleimpl_inscriptions.py b/app/scodoc/sco_moduleimpl_inscriptions.py index c3e6b6b7b8..f0a196a71e 100644 --- a/app/scodoc/sco_moduleimpl_inscriptions.py +++ b/app/scodoc/sco_moduleimpl_inscriptions.py @@ -518,14 +518,14 @@ def is_inscrit_ue(context, etudid, formsemestre_id, ue_id): auxquels l'étudiant est inscrit. """ r = ndb.SimpleDictFetch( - """SELECT mod.* + """SELECT mod.id AS module_id, mod.* FROM notes_moduleimpl mi, notes_modules mod, notes_formsemestre sem, notes_moduleimpl_inscription i WHERE sem.formsemestre_id = %(formsemestre_id)s - AND mi.formsemestre_id = sem.formsemestre_id - AND mod.module_id = mi.module_id + AND mi.formsemestre_id = sem.id + AND mod.id = mi.module_id AND mod.ue_id = %(ue_id)s - AND i.moduleimpl_id = mi.moduleimpl_id + AND i.moduleimpl_id = mi.id AND i.etudid = %(etudid)s ORDER BY mod.numero """, diff --git a/app/scodoc/sco_ue_external.py b/app/scodoc/sco_ue_external.py index 3a82d6ba05..b039d6218a 100644 --- a/app/scodoc/sco_ue_external.py +++ b/app/scodoc/sco_ue_external.py @@ -196,9 +196,9 @@ def get_external_moduleimpl_id(context, formsemestre_id, ue_id): "moduleimpl correspondant à l'UE externe indiquée de ce formsemestre" r = ndb.SimpleDictFetch( """ - SELECT moduleimpl_id FROM notes_moduleimpl mi, notes_modules mo - WHERE mi.formsemestre_id = %(formsemestre_id)s - AND mi.module_id = mo.module_id + SELECT mi.id AS moduleimpl_id FROM notes_moduleimpl mi, notes_modules mo + WHERE mi.id = %(formsemestre_id)s + AND mi.module_id = mo.id AND mo.ue_id = %(ue_id)s """, {"ue_id": ue_id, "formsemestre_id": formsemestre_id}, diff --git a/app/scodoc/sco_undo_notes.py b/app/scodoc/sco_undo_notes.py index a72df0c695..e8a52deb7e 100644 --- a/app/scodoc/sco_undo_notes.py +++ b/app/scodoc/sco_undo_notes.py @@ -173,10 +173,21 @@ def evaluation_list_operations(context, REQUEST, evaluation_id): def formsemestre_list_saisies_notes( context, formsemestre_id, format="html", REQUEST=None ): - """Table listant toutes les operations de saisies de notes, dans toutes les evaluations du semestre.""" + """Table listant toutes les opérations de saisies de notes, dans toutes + les évaluations du semestre. + """ sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) r = ndb.SimpleDictFetch( - """select i.nom, n.*, mod.titre, e.description, e.jour from notes_notes n, notes_evaluation e, notes_moduleimpl m, notes_modules mod, identite i where m.moduleimpl_id = e.moduleimpl_id and m.module_id = mod.module_id and e.evaluation_id=n.evaluation_id and i.etudid=n.etudid and m.formsemestre_id=%(formsemestre_id)s order by date desc""", + """SELECT i.nom, n.*, mod.titre, e.description, e.jour + FROM notes_notes n, notes_evaluation e, notes_moduleimpl mi, + notes_modules mod, identite i + WHERE mi.id = e.moduleimpl_id + and m.module_id = mod.id + and e.id=n.evaluation_id + and i.etudid=n.etudid + and mi.formsemestre_id=%(formsemestre_id)s + ORDER BY date desc + """, {"formsemestre_id": formsemestre_id}, ) columns_ids = (