diff --git a/app/__init__.py b/app/__init__.py index 07160ecd..41d2b38f 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -187,6 +187,8 @@ def initialize_scodoc_database(erase=False): user_db_init() # - Insert some constant values (modalites, ...) sco_db_init() + # - Flush cache + clear_scodoc_cache() def truncate_database(): @@ -202,6 +204,18 @@ def truncate_database(): raise +def clear_scodoc_cache(): + """Clear ScoDoc cache + This cache (currently Redis) is persistent between invocation + and it may be necessary to clear it during developement or tests. + """ + # attaque directement redis, court-circuite ScoDoc: + import redis + + r = redis.Redis() + r.flushall() + + # admin_role = Role.query.filter_by(name="SuperAdmin").first() # if admin_role: # admin = ( diff --git a/app/models/events.py b/app/models/events.py index cd95e492..b2c9ca79 100644 --- a/app/models/events.py +++ b/app/models/events.py @@ -16,6 +16,8 @@ class Scolog(db.Model): id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) + method = db.Column(db.Text) + msg = db.Column(db.Text) etudid = db.Column(db.Integer) # sans contrainte pour garder logs après suppression authenticated_user = db.Column(db.Text) # login, sans contrainte # zope_remote_addr suppressed diff --git a/app/scodoc/sco_abs.py b/app/scodoc/sco_abs.py index 8e866285..0e137710 100644 --- a/app/scodoc/sco_abs.py +++ b/app/scodoc/sco_abs.py @@ -1028,7 +1028,7 @@ def get_abs_count(etudid, sem): """ date_debut = sem["date_debut_iso"] date_fin = sem["date_fin_iso"] - key = etudid + "_" + date_debut + "_" + date_fin + key = str(etudid) + "_" + date_debut + "_" + date_fin r = sco_cache.AbsSemEtudCache.get(key) if not r: nb_abs = count_abs( # was CountAbs XXX @@ -1052,7 +1052,7 @@ def invalidate_abs_count(etudid, sem): """Invalidate (clear) cached counts""" date_debut = sem["date_debut_iso"] date_fin = sem["date_fin_iso"] - key = etudid + "_" + date_debut + "_" + date_fin + key = str(etudid) + "_" + date_debut + "_" + date_fin sco_cache.AbsSemEtudCache.delete(key) diff --git a/app/scodoc/sco_dept.py b/app/scodoc/sco_dept.py index e723139b..5c377f9f 100644 --- a/app/scodoc/sco_dept.py +++ b/app/scodoc/sco_dept.py @@ -67,7 +67,7 @@ def index_html(context, REQUEST=None, showcodes=0, showsemtable=0): lockicon = scu.icontag("lock32_img", title="verrouillé", border="0") # Sélection sur l'etat du semestre for sem in sems: - if sem["etat"] == "1" and sem["modalite"] != "EXT": + if sem["etat"] and sem["modalite"] != "EXT": sem["lockimg"] = "" cursems.append(sem) else: diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index 13896270..5a0b4f0d 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -805,7 +805,7 @@ Si vous souhaitez modifier cette formation (par exemple pour y ajouter un module '
%sCe semestre est verrouillé.
""" % scu.icontag("lock_img", border="0", title="Semestre verrouillé") @@ -1483,7 +1483,7 @@ def formsemestre_change_lock( if not ok: return err sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) - etat = 1 - int(sem["etat"]) + etat = not sem["etat"] if REQUEST and not dialog_confirmed: if etat: @@ -1500,11 +1500,9 @@ def formsemestre_change_lock( """, dest_url="", cancel_url="formsemestre_status?formsemestre_id=%s" % formsemestre_id, - parameters={"etat": etat, "formsemestre_id": formsemestre_id}, + parameters={"formsemestre_id": formsemestre_id}, ) - if etat not in (0, 1): - raise ScoValueError("formsemestre_lock: invalid value for etat (%s)" % etat) args = {"formsemestre_id": formsemestre_id, "etat": etat} sco_formsemestre.do_formsemestre_edit(context, args) if REQUEST: diff --git a/app/scodoc/sco_formsemestre_inscriptions.py b/app/scodoc/sco_formsemestre_inscriptions.py index 44a2e3e6..4ff2068e 100644 --- a/app/scodoc/sco_formsemestre_inscriptions.py +++ b/app/scodoc/sco_formsemestre_inscriptions.py @@ -87,7 +87,7 @@ def do_formsemestre_inscription_create(context, args, REQUEST, method=None): raise ScoValueError("code de semestre invalide: %s" % args["formsemestre_id"]) sem = sems[0] # check lock - if sem["etat"] != "1": + if not sem["etat"]: raise ScoValueError("inscription: semestre verrouille") # r = _formsemestre_inscriptionEditor.create(cnx, args) @@ -143,7 +143,7 @@ def do_formsemestre_desinscription(context, etudid, formsemestre_id, REQUEST=Non sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) # -- check lock - if sem["etat"] != "1": + if not sem["etat"]: raise ScoValueError("desinscription impossible: semestre verrouille") # -- Si decisions de jury, desinscription interdite @@ -444,7 +444,7 @@ def formsemestre_inscription_with_modules( def formsemestre_inscription_option(context, etudid, formsemestre_id, REQUEST=None): """Dialogue pour (dés)inscription à des modules optionnels.""" sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) - if sem["etat"] != "1": + if not sem["etat"]: raise ScoValueError("Modification impossible: semestre verrouille") etud = sco_etud.get_etud_info(etudid=etudid, filled=1)[0] diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 9e2c0eb1..7d688087 100644 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -163,7 +163,7 @@ def formsemestre_status_menubar(context, sem): and sem["resp_can_edit"] ) ) - and (sem["etat"] == "1"), + and (sem["etat"]), "helpmsg": "Modifie le contenu du semestre (modules)", }, { @@ -177,7 +177,7 @@ def formsemestre_status_menubar(context, sem): and sem["resp_can_edit"] ) ) - and (sem["etat"] == "1"), + and (sem["etat"]), "helpmsg": "Préférences du semestre", }, { @@ -229,7 +229,7 @@ def formsemestre_status_menubar(context, sem): "endpoint": "notes.formsemestre_associate_new_version", "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoChangeFormation) - and (sem["etat"] == "1"), + and (sem["etat"]), "helpmsg": "", }, { @@ -264,7 +264,7 @@ def formsemestre_status_menubar(context, sem): "endpoint": "notes.formsemestre_inscr_passage", "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoEtudInscrit) - and (sem["etat"] == "1"), + and (sem["etat"]), }, { "title": "Synchroniser avec étape Apogée", @@ -272,21 +272,21 @@ def formsemestre_status_menubar(context, sem): "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoView) and sco_preferences.get_preference("portal_url") - and (sem["etat"] == "1"), + and (sem["etat"]), }, { "title": "Inscrire un étudiant", "endpoint": "notes.formsemestre_inscription_with_modules_etud", "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoEtudInscrit) - and (sem["etat"] == "1"), + and (sem["etat"]), }, { "title": "Importer des étudiants dans ce semestre (table Excel)", "endpoint": "scolar.form_students_import_excel", "args": {"formsemestre_id": formsemestre_id}, "enabled": current_user.has_permission(Permission.ScoEtudInscrit) - and (sem["etat"] == "1"), + and (sem["etat"]), }, { "title": "Import/export des données admission", @@ -539,7 +539,7 @@ def fill_formsemestre(sem): notes_url = scu.NotesURL() sem["notes_url"] = notes_url formsemestre_id = sem["formsemestre_id"] - if sem["etat"] != "1": + if not sem["etat"]: sem[ "locklink" ] = """%s""" % ( diff --git a/app/scodoc/sco_formsemestre_validation.py b/app/scodoc/sco_formsemestre_validation.py index 8395b6ba..84238907 100644 --- a/app/scodoc/sco_formsemestre_validation.py +++ b/app/scodoc/sco_formsemestre_validation.py @@ -102,7 +102,7 @@ def formsemestre_validation_etud_form( etud = sco_etud.get_etud_info(etudid=etudid, filled=True)[0] Se = sco_parcours_dut.SituationEtudParcours(context, etud, formsemestre_id) - if Se.sem["etat"] != "1": + if not Se.sem["etat"]: raise ScoValueError("validation: semestre verrouille") H = [ @@ -599,7 +599,7 @@ def formsemestre_recap_parcours_table( default_sem_info = '[sem. précédent]' else: default_sem_info = "" - if sem["etat"] != "1": # locked + if not sem["etat"]: # locked lockicon = scu.icontag("lock32_img", title="verrouillé", border="0") default_sem_info += lockicon if sem["formation_code"] != Se.formation["formation_code"]: diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 24a12e04..fbbb3c7d 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -453,10 +453,10 @@ 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.id as group_id, gd.*, etudid + """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 + AND gm.group_id = gd.id """, {"partition_id": partition_id}, ) @@ -670,7 +670,7 @@ def setGroups( log("groupsToCreate=%s" % groupsToCreate) log("groupsToDelete=%s" % groupsToDelete) sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) - if sem["etat"] != "1": + if not sem["etat"]: raise AccessDenied("Modification impossible: semestre verrouillé") groupsToDelete = [g for g in groupsToDelete.split(";") if g] @@ -1410,7 +1410,12 @@ def do_evaluation_listeetuds_groups( req = ( "SELECT distinct Im.etudid FROM " + ", ".join(fromtables) - + " WHERE Isem.etudid=Im.etudid and Im.moduleimpl_id=M.moduleimpl_id and Isem.formsemestre_id=M.formsemestre_id and E.moduleimpl_id=M.moduleimpl_id and E.evaluation_id = %(evaluation_id)s" + + """ WHERE Isem.etudid = Im.etudid + and Im.moduleimpl_id = M.id + and Isem.formsemestre_id = M.formsemestre_id + and E.moduleimpl_id = M.id + and E.id = %(evaluation_id)s + """ ) if not include_dems: req += " and Isem.etat='I'" @@ -1418,8 +1423,6 @@ def do_evaluation_listeetuds_groups( cnx = ndb.GetDBConnexion() cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor.execute(req, {"evaluation_id": evaluation_id}) - # log('listeetuds_groups: getallstudents=%s groups=%s' % (getallstudents,groups)) - # log('req=%s' % (req % { 'evaluation_id' : "'"+evaluation_id+"'" })) res = cursor.fetchall() return [x[0] for x in res] diff --git a/app/scodoc/sco_inscr_passage.py b/app/scodoc/sco_inscr_passage.py index e5f6f87f..c4b9ef0d 100644 --- a/app/scodoc/sco_inscr_passage.py +++ b/app/scodoc/sco_inscr_passage.py @@ -285,7 +285,7 @@ def formsemestre_inscr_passage( inscrit_groupes = int(inscrit_groupes) sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) # -- check lock - if sem["etat"] != "1": + if not sem["etat"]: raise ScoValueError("opération impossible: semestre verrouille") header = html_sco_header.sco_header(page_title="Passage des étudiants") footer = html_sco_header.sco_footer() diff --git a/app/scodoc/sco_moduleimpl.py b/app/scodoc/sco_moduleimpl.py index 5e1ed9bb..6c65cf09 100644 --- a/app/scodoc/sco_moduleimpl.py +++ b/app/scodoc/sco_moduleimpl.py @@ -182,7 +182,14 @@ def do_moduleimpl_inscription_list( def do_moduleimpl_listeetuds(context, moduleimpl_id): "retourne liste des etudids inscrits a ce module" - req = "select distinct Im.etudid from notes_moduleimpl_inscription Im, notes_formsemestre_inscription Isem, notes_moduleimpl M where Isem.etudid=Im.etudid and Im.moduleimpl_id=M.moduleimpl_id and M.moduleimpl_id = %(moduleimpl_id)s" + req = """SELECT DISTINCT Im.etudid + FROM notes_moduleimpl_inscription Im, + notes_formsemestre_inscription Isem, + notes_moduleimpl M + WHERE Isem.etudid = Im.etudid + and Im.moduleimpl_id = M.id + and M.id = %(moduleimpl_id)s + """ cnx = ndb.GetDBConnexion() cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor) cursor.execute(req, {"moduleimpl_id": moduleimpl_id}) @@ -199,7 +206,8 @@ def do_moduleimpl_inscrit_tout_semestre(context, moduleimpl_id, formsemestre_id) (moduleimpl_id, etudid) SELECT %(moduleimpl_id)s, I.etudid FROM notes_formsemestre_inscription I - WHERE I.formsemestre_id=%(formsemestre_id)s""" + WHERE I.formsemestre_id=%(formsemestre_id)s + """ args = {"moduleimpl_id": moduleimpl_id, "formsemestre_id": formsemestre_id} cursor.execute(req, args) @@ -322,7 +330,7 @@ def can_change_module_resp(context, REQUEST, moduleimpl_id): M = do_moduleimpl_withmodule_list(context, moduleimpl_id=moduleimpl_id)[0] # -- check lock sem = sco_formsemestre.get_formsemestre(context, M["formsemestre_id"]) - if sem["etat"] != "1": + if not sem["etat"]: raise ScoValueError("Modification impossible: semestre verrouille") # -- check access authuser = REQUEST.AUTHENTICATED_USER @@ -340,7 +348,7 @@ def can_change_ens(context, REQUEST, moduleimpl_id, raise_exc=True): M = do_moduleimpl_withmodule_list(context, moduleimpl_id=moduleimpl_id)[0] # -- check lock sem = sco_formsemestre.get_formsemestre(context, M["formsemestre_id"]) - if sem["etat"] != "1": + if not sem["etat"]: if raise_exc: raise ScoValueError("Modification impossible: semestre verrouille") else: diff --git a/app/scodoc/sco_moduleimpl_inscriptions.py b/app/scodoc/sco_moduleimpl_inscriptions.py index f0a196a7..8e873ee6 100644 --- a/app/scodoc/sco_moduleimpl_inscriptions.py +++ b/app/scodoc/sco_moduleimpl_inscriptions.py @@ -69,7 +69,7 @@ def moduleimpl_inscriptions_edit( mod = sco_edit_module.do_module_list(context, args={"module_id": M["module_id"]})[0] sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) # -- check lock - if sem["etat"] != "1": + if not sem["etat"]: raise ScoValueError("opération impossible: semestre verrouille") header = html_sco_header.sco_header( page_title="Inscription au module", @@ -261,9 +261,7 @@ def moduleimpl_inscriptions_stats(context, formsemestre_id, REQUEST=None): context, formsemestre_id ) - can_change = ( - authuser.has_permission(Permission.ScoEtudInscrit) and sem["etat"] == "1" - ) + can_change = authuser.has_permission(Permission.ScoEtudInscrit) and sem["etat"] # Liste des modules Mlist = sco_moduleimpl.do_moduleimpl_withmodule_list( diff --git a/app/scodoc/sco_moduleimpl_status.py b/app/scodoc/sco_moduleimpl_status.py index bd4a8b1d..6037a59f 100644 --- a/app/scodoc/sco_moduleimpl_status.py +++ b/app/scodoc/sco_moduleimpl_status.py @@ -223,7 +223,7 @@ def moduleimpl_status(context, moduleimpl_id=None, partition_id=None, REQUEST=No H.append("""Semestre: