# -*- mode: python -*- # -*- coding: utf-8 -*- ############################################################################## # # Gestion scolarite IUT # # Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Emmanuel Viennet emmanuel.viennet@viennet.net # ############################################################################## """Opérations d'inscriptions aux modules (interface pour gérer options ou parcours) """ from operator import itemgetter import flask from flask import url_for, g, request from flask_login import current_user from app.comp import res_sem from app.comp.res_compat import NotesTableCompat from app.models import FormSemestre import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu from app import log from app.scodoc.scolog import logdb from app.scodoc import html_sco_header from app.scodoc import htmlutils from app.scodoc import sco_cache from app.scodoc import sco_edit_module from app.scodoc import sco_edit_ue from app.scodoc import sco_formsemestre from app.scodoc import sco_formsemestre_inscriptions from app.scodoc import sco_groups from app.scodoc import sco_moduleimpl from app.scodoc import sco_etud from app.scodoc.sco_exceptions import ScoValueError from app.scodoc.sco_permissions import Permission def moduleimpl_inscriptions_edit(moduleimpl_id, etuds=[], submitted=False): """Formulaire inscription des etudiants a ce module * Gestion des inscriptions Nom TD TA TP (triable) [x] M. XXX YYY - - - ajouter TD A, TD B, TP 1, TP 2 ... supprimer TD A, TD B, TP 1, TP 2 ... * Si pas les droits: idem en readonly """ M = sco_moduleimpl.moduleimpl_list(moduleimpl_id=moduleimpl_id)[0] formsemestre_id = M["formsemestre_id"] mod = sco_edit_module.module_list(args={"module_id": M["module_id"]})[0] sem = sco_formsemestre.get_formsemestre(formsemestre_id) # -- check lock if not sem["etat"]: raise ScoValueError("opération impossible: semestre verrouille") header = html_sco_header.sco_header( page_title="Inscription au module", init_qtip=True, javascripts=["js/etud_info.js"], ) footer = html_sco_header.sco_footer() H = [ header, """
Cette page permet d'éditer les étudiants inscrits à ce module (ils doivent évidemment être inscrits au semestre). Les étudiants cochés sont (ou seront) inscrits. Vous pouvez facilement inscrire ou désinscrire tous les étudiants d'un groupe à l'aide des menus "Ajouter" et "Enlever".
Aucune modification n'est prise en compte tant que l'on n'appuie pas sur le bouton "Appliquer les modifications".
""" % ( moduleimpl_id, mod["titre"] or "(module sans titre)", mod["code"] or "(module sans code)", ), ] # Liste des inscrits à ce semestre inscrits = sco_formsemestre_inscriptions.do_formsemestre_inscription_listinscrits( formsemestre_id ) for ins in inscrits: etuds_info = sco_etud.get_etud_info(etudid=ins["etudid"], filled=1) if not etuds_info: log( "moduleimpl_inscriptions_edit: incoherency for etudid=%s !" % ins["etudid"] ) raise ScoValueError( "Etudiant %s inscrit mais inconnu dans la base !!!!!" % ins["etudid"] ) ins["etud"] = etuds_info[0] inscrits.sort(key=lambda x: x["etud"]["nom"]) in_m = sco_moduleimpl.do_moduleimpl_inscription_list( moduleimpl_id=M["moduleimpl_id"] ) in_module = set([x["etudid"] for x in in_m]) # partitions = sco_groups.get_partitions_list(formsemestre_id) # if not submitted: H.append( """""" ) H.append("""""") else: # SUBMISSION # inscrit a ce module tous les etuds selectionnes sco_moduleimpl.do_moduleimpl_inscrit_etuds( moduleimpl_id, formsemestre_id, etuds, reset=True ) return flask.redirect("moduleimpl_status?moduleimpl_id=%s" % (moduleimpl_id)) # H.append(footer) return "\n".join(H) def _make_menu(partitions, title="", check="true"): """Menu with list of all groups""" items = [{"title": "Tous", "attr": "onclick=\"group_select('', -1, %s)\"" % check}] p_idx = 0 for partition in partitions: if partition["partition_name"] != None: p_idx += 1 for group in sco_groups.get_partition_groups(partition): items.append( { "title": "%s %s" % (partition["partition_name"], group["group_name"]), "attr": "onclick=\"group_select('%s', %s, %s)\"" % (group["group_name"], p_idx, check), } ) return ( 'UE | Code | Inscrits | |
---|---|---|---|
%s | %s | %s | %s |
UE | Code | Module |
---|---|---|
%s | %s | %s |
Cette page décrit les inscriptions actuelles. Vous pouvez changer (si vous en avez le droit) les inscrits dans chaque module en cliquant sur la ligne du module.
Note: la déinscription d'un module ne perd pas les notes. Ainsi, si l'étudiant est ensuite réinscrit au même module, il retrouvera ses notes.
""" ) H.append(html_sco_header.sco_footer()) return "\n".join(H) def descr_inscrs_module( sem, moduleimpl_id, set_all, partitions, partitions_etud_groups ): """returns tous_inscrits, nb_inscrits, descr""" ins = sco_moduleimpl.do_moduleimpl_inscription_list(moduleimpl_id=moduleimpl_id) set_m = set([x["etudid"] for x in ins]) # ens. des inscrits au module non_inscrits = set_all - set_m if len(non_inscrits) == 0: return True, len(ins), "" # tous inscrits if len(non_inscrits) <= 7: # seuil arbitraire return False, len(ins), "tous sauf " + _fmt_etud_set(non_inscrits) # Cherche les groupes: gr = [] # [ ( partition_name , [ group_names ] ) ] for partition in partitions: grp = [] # groupe de cette partition for group in sco_groups.get_partition_groups(partition): members = sco_groups.get_group_members(group["group_id"]) set_g = set([m["etudid"] for m in members]) if set_g.issubset(set_m): grp.append(group["group_name"]) set_m = set_m - set_g gr.append((partition["partition_name"], grp)) # d = [] for (partition_name, grp) in gr: if grp: d.append("groupes de %s: %s" % (partition_name, ", ".join(grp))) r = [] if d: r.append(", ".join(d)) if set_m: r.append(_fmt_etud_set(set_m)) # return False, len(ins), " et ".join(r) def _fmt_etud_set(ins, max_list_size=7): # max_list_size est le nombre max de noms d'etudiants listés # au delà, on indique juste le nombre, sans les noms. if len(ins) > max_list_size: return "%d étudiants" % len(ins) etuds = [] for etudid in ins: etuds.append(sco_etud.get_etud_info(etudid=etudid, filled=True)[0]) etuds.sort(key=itemgetter("nom")) return ", ".join( [ '%s' % ( url_for( "scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etud["etudid"] ), etud["nomprenom"], ) for etud in etuds ] ) def get_etuds_with_capitalized_ue(formsemestre_id): """For each UE, computes list of students capitalizing the UE. returns { ue_id : [ { infos } ] } """ UECaps = scu.DictDefault(defaultvalue=[]) formsemestre = FormSemestre.query.get_or_404(formsemestre_id) nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre) inscrits = sco_formsemestre_inscriptions.do_formsemestre_inscription_list( args={"formsemestre_id": formsemestre_id} ) ues = nt.get_ues_stat_dict() for ue in ues: for etud in inscrits: ue_status = nt.get_etud_ue_status(etud["etudid"], ue["ue_id"]) if ue_status and ue_status["was_capitalized"]: UECaps[ue["ue_id"]].append( { "etudid": etud["etudid"], "ue_status": ue_status, "is_ins": is_inscrit_ue( etud["etudid"], formsemestre_id, ue["ue_id"] ), } ) return UECaps def is_inscrit_ue(etudid, formsemestre_id, ue_id): """Modules de cette UE dans ce semestre auxquels l'étudiant est inscrit. """ r = ndb.SimpleDictFetch( """SELECT mod.id AS module_id, mod.* FROM notes_moduleimpl mi, notes_modules mod, notes_formsemestre sem, notes_moduleimpl_inscription i WHERE sem.id = %(formsemestre_id)s AND mi.formsemestre_id = sem.id AND mod.id = mi.module_id AND mod.ue_id = %(ue_id)s AND i.moduleimpl_id = mi.id AND i.etudid = %(etudid)s ORDER BY mod.numero """, {"etudid": etudid, "formsemestre_id": formsemestre_id, "ue_id": ue_id}, ) return r def do_etud_desinscrit_ue(etudid, formsemestre_id, ue_id): """Desincrit l'etudiant de tous les modules de cette UE dans ce semestre.""" cnx = ndb.GetDBConnexion() cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor.execute( """DELETE FROM notes_moduleimpl_inscription WHERE id IN ( SELECT i.id FROM notes_moduleimpl mi, notes_modules mod, notes_formsemestre sem, notes_moduleimpl_inscription i WHERE sem.id = %(formsemestre_id)s AND mi.formsemestre_id = sem.id AND mod.id = mi.module_id AND mod.ue_id = %(ue_id)s AND i.moduleimpl_id = mi.id AND i.etudid = %(etudid)s ) """, {"etudid": etudid, "formsemestre_id": formsemestre_id, "ue_id": ue_id}, ) logdb( cnx, method="etud_desinscrit_ue", etudid=etudid, msg="desinscription UE %s" % ue_id, commit=False, ) sco_cache.invalidate_formsemestre( formsemestre_id=formsemestre_id ) # > desinscription etudiant des modules def do_etud_inscrit_ue(etudid, formsemestre_id, ue_id): """Incrit l'etudiant de tous les modules de cette UE dans ce semestre.""" # Verifie qu'il est bien inscrit au semestre insem = sco_formsemestre_inscriptions.do_formsemestre_inscription_list( args={"formsemestre_id": formsemestre_id, "etudid": etudid} ) if not insem: raise ScoValueError("%s n'est pas inscrit au semestre !" % etudid) cnx = ndb.GetDBConnexion() cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor.execute( """SELECT mi.id FROM notes_moduleimpl mi, notes_modules mod, notes_formsemestre sem WHERE sem.id = %(formsemestre_id)s AND mi.formsemestre_id = sem.id AND mod.id = mi.module_id AND mod.ue_id = %(ue_id)s """, {"formsemestre_id": formsemestre_id, "ue_id": ue_id}, ) res = cursor.dictfetchall() for moduleimpl_id in [x["id"] for x in res]: sco_moduleimpl.do_moduleimpl_inscription_create( {"moduleimpl_id": moduleimpl_id, "etudid": etudid}, formsemestre_id=formsemestre_id, )