diff --git a/app/scodoc/sco_archives.py b/app/scodoc/sco_archives.py index 3d80b46a4..469bf0609 100644 --- a/app/scodoc/sco_archives.py +++ b/app/scodoc/sco_archives.py @@ -52,6 +52,8 @@ import re import shutil import glob +import flask + import app.scodoc.sco_utils as scu from config import Config from app.scodoc.notes_log import log diff --git a/app/scodoc/sco_edit_formation.py b/app/scodoc/sco_edit_formation.py index 0f7c13af2..4f6e0123b 100644 --- a/app/scodoc/sco_edit_formation.py +++ b/app/scodoc/sco_edit_formation.py @@ -28,6 +28,8 @@ """Ajout/Modification/Supression formations (portage from DTML) """ +import flask + import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu from app.scodoc.notes_log import log @@ -114,6 +116,7 @@ def do_formation_delete(context, oid): typ=sco_news.NEWS_FORM, object=oid, text="Suppression de la formation %(acronyme)s" % F, + max_frequency=3, ) @@ -271,6 +274,7 @@ def do_formation_create(context, args): sco_news.add( typ=sco_news.NEWS_FORM, text="Création de la formation %(titre)s (%(acronyme)s)" % args, + max_frequency=3, ) return r diff --git a/app/scodoc/sco_edit_matiere.py b/app/scodoc/sco_edit_matiere.py index bb337e5b0..cd80bf873 100644 --- a/app/scodoc/sco_edit_matiere.py +++ b/app/scodoc/sco_edit_matiere.py @@ -28,6 +28,8 @@ """Ajout/Modification/Supression matieres (portage from DTML) """ +import flask + import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu from app.scodoc.notes_log import log @@ -88,6 +90,7 @@ def do_matiere_create(context, args): typ=sco_news.NEWS_FORM, object=ue["formation_id"], text="Modification de la formation %(acronyme)s" % F, + max_frequency=3, ) return r @@ -185,6 +188,7 @@ def do_matiere_delete(context, oid): typ=sco_news.NEWS_FORM, object=ue["formation_id"], text="Modification de la formation %(acronyme)s" % F, + max_frequency=3, ) diff --git a/app/scodoc/sco_edit_module.py b/app/scodoc/sco_edit_module.py index f98beb494..ae15dad96 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/scodoc/sco_edit_module.py @@ -115,6 +115,7 @@ def do_module_create(context, args): typ=sco_news.NEWS_FORM, object=args["formation_id"], text="Modification de la formation %(acronyme)s" % F, + max_frequency=3, ) return r @@ -280,6 +281,7 @@ def do_module_delete(context, oid): typ=sco_news.NEWS_FORM, object=mod["formation_id"], text="Modification de la formation %(acronyme)s" % F, + max_frequency=3, ) diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index 4a517d598..43c372121 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -109,6 +109,7 @@ def do_ue_create(context, args): typ=sco_news.NEWS_FORM, object=args["formation_id"], text="Modification de la formation %(acronyme)s" % F, + max_frequency=3, ) return r @@ -170,6 +171,7 @@ def do_ue_delete(context, ue_id, delete_validations=False, REQUEST=None, force=F typ=sco_news.NEWS_FORM, object=ue["formation_id"], text="Modification de la formation %(acronyme)s" % F, + max_frequency=3, ) # if not force: diff --git a/app/scodoc/sco_etape_apogee_view.py b/app/scodoc/sco_etape_apogee_view.py index 9f750c91d..f886e5804 100644 --- a/app/scodoc/sco_etape_apogee_view.py +++ b/app/scodoc/sco_etape_apogee_view.py @@ -31,6 +31,7 @@ from io import StringIO from zipfile import ZipFile +import flask from flask import url_for, g import app.scodoc.sco_utils as scu diff --git a/app/scodoc/sco_find_etud.py b/app/scodoc/sco_find_etud.py index 50a850756..ba6d80ada 100644 --- a/app/scodoc/sco_find_etud.py +++ b/app/scodoc/sco_find_etud.py @@ -27,6 +27,7 @@ """Recherche d'étudiants """ +import flask from flask import url_for, g from flask_login import current_user diff --git a/app/scodoc/sco_formations.py b/app/scodoc/sco_formations.py index f4c376684..62c17505e 100644 --- a/app/scodoc/sco_formations.py +++ b/app/scodoc/sco_formations.py @@ -30,6 +30,8 @@ from operator import itemgetter import xml.dom.minidom +import flask + import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb @@ -134,13 +136,22 @@ def formation_export( ) -def formation_import_xml(context, REQUEST, doc, import_tags=True): +def formation_import_xml(context, doc, import_tags=True): """Create a formation from XML representation (format dumped by formation_export( format='xml' )) + XML may contain object (UE, modules) ids: this function returns two + dicts mapping these ids to the created ids. + + Args: + doc: str, xml data + import_tags: if false, does not import tags on modules. + + Returns: + formation_id, modules_old2new, ues_old2new """ from app.scodoc import sco_edit_formation - log("formation_import_xml: doc=%s" % doc) + # log("formation_import_xml: doc=%s" % doc) try: dom = xml.dom.minidom.parseString(doc) except: @@ -341,7 +352,7 @@ def formation_list_table(context, formation_id=None, args={}, REQUEST=None): def formation_create_new_version(context, formation_id, redirect=True, REQUEST=None): "duplicate formation, with new version number" xml = formation_export(context, formation_id, export_ids=True, format="xml") - new_id, modules_old2new, ues_old2new = formation_import_xml(context, REQUEST, xml) + new_id, modules_old2new, ues_old2new = formation_import_xml(context, xml) # news F = formation_list(context, args={"formation_id": new_id})[0] sco_news.add( diff --git a/app/scodoc/sco_formsemestre_custommenu.py b/app/scodoc/sco_formsemestre_custommenu.py index d3856a720..4bd042e7d 100644 --- a/app/scodoc/sco_formsemestre_custommenu.py +++ b/app/scodoc/sco_formsemestre_custommenu.py @@ -27,7 +27,7 @@ """Menu "custom" (défini par l'utilisateur) dans les semestres """ - +import flask import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index e52a63973..6258a65f2 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -27,6 +27,7 @@ """Form choix modules / responsables et creation formsemestre """ +import flask from flask import url_for, g from app.auth.models import User diff --git a/app/scodoc/sco_formsemestre_exterieurs.py b/app/scodoc/sco_formsemestre_exterieurs.py index 4047b641b..a46ce8050 100644 --- a/app/scodoc/sco_formsemestre_exterieurs.py +++ b/app/scodoc/sco_formsemestre_exterieurs.py @@ -33,6 +33,7 @@ Ces semestres n'auront qu'un seul inscrit ! """ import time +import flask from flask import url_for, g import app.scodoc.sco_utils as scu diff --git a/app/scodoc/sco_formsemestre_inscriptions.py b/app/scodoc/sco_formsemestre_inscriptions.py index a5469db58..44a2e3e66 100644 --- a/app/scodoc/sco_formsemestre_inscriptions.py +++ b/app/scodoc/sco_formsemestre_inscriptions.py @@ -29,6 +29,7 @@ """ import time +import flask from flask import url_for, g import app.scodoc.sco_utils as scu diff --git a/app/scodoc/sco_formsemestre_validation.py b/app/scodoc/sco_formsemestre_validation.py index ecb0feb6f..50c2f0981 100644 --- a/app/scodoc/sco_formsemestre_validation.py +++ b/app/scodoc/sco_formsemestre_validation.py @@ -29,6 +29,7 @@ """ import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error, time, datetime +import flask from flask import url_for, g import app.scodoc.notesdb as ndb diff --git a/app/scodoc/sco_liste_notes.py b/app/scodoc/sco_liste_notes.py index f9b3dd245..0fddd3704 100644 --- a/app/scodoc/sco_liste_notes.py +++ b/app/scodoc/sco_liste_notes.py @@ -30,6 +30,7 @@ import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error from operator import itemgetter +import flask from flask import url_for, g import app.scodoc.sco_utils as scu diff --git a/app/scodoc/sco_moduleimpl_inscriptions.py b/app/scodoc/sco_moduleimpl_inscriptions.py index 936028f5b..c3e6b6b7b 100644 --- a/app/scodoc/sco_moduleimpl_inscriptions.py +++ b/app/scodoc/sco_moduleimpl_inscriptions.py @@ -29,6 +29,7 @@ """ from operator import itemgetter +import flask from flask import url_for, g import app.scodoc.notesdb as ndb diff --git a/app/scodoc/sco_news.py b/app/scodoc/sco_news.py index b487921a5..2ba48132a 100644 --- a/app/scodoc/sco_news.py +++ b/app/scodoc/sco_news.py @@ -97,15 +97,15 @@ def add(typ, object=None, text="", url=None, max_frequency=False): "text": text, "url": url, } - - log("news: %s" % args) t = time.time() if max_frequency: last_news_time = _LAST_NEWS.get((authuser_name, typ, object), False) if last_news_time and (t - last_news_time < max_frequency): - log("not recording") + # log("not recording") return + log("news: %s" % args) + _LAST_NEWS[(authuser_name, typ, object)] = t _send_news_by_mail(args) diff --git a/app/scodoc/sco_placement.py b/app/scodoc/sco_placement.py index 1bd260df9..30705498b 100644 --- a/app/scodoc/sco_placement.py +++ b/app/scodoc/sco_placement.py @@ -33,6 +33,8 @@ Contribution M. Salomon, UFC / IUT DE BELFORT-MONTBÉLIARD, 2016 import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error import random +import flask + import app.scodoc.sco_utils as scu import app.scodoc.notesdb as ndb from app.scodoc.notes_log import log diff --git a/app/scodoc/sco_preferences.py b/app/scodoc/sco_preferences.py index 1ae6d5c3a..be89c03b1 100644 --- a/app/scodoc/sco_preferences.py +++ b/app/scodoc/sco_preferences.py @@ -110,6 +110,7 @@ get_base_preferences(formsemestre_id) Return base preferences for current scodoc_dept (instance BasePreferences) """ +import flask from flask import g from app.scodoc import sco_cache diff --git a/app/scodoc/sco_pvjury.py b/app/scodoc/sco_pvjury.py index 3ea8853a0..e925c8f2a 100644 --- a/app/scodoc/sco_pvjury.py +++ b/app/scodoc/sco_pvjury.py @@ -51,6 +51,7 @@ from operator import itemgetter from reportlab.platypus import Paragraph from reportlab.lib import styles +import flask from flask import url_for, g import app.scodoc.sco_utils as scu diff --git a/app/scodoc/sco_saisie_notes.py b/app/scodoc/sco_saisie_notes.py index bb9bf24a2..b6cb13208 100644 --- a/app/scodoc/sco_saisie_notes.py +++ b/app/scodoc/sco_saisie_notes.py @@ -33,6 +33,7 @@ import time import datetime import psycopg2 +import flask from flask_login import current_user import app.scodoc.sco_utils as scu diff --git a/app/scodoc/sco_semset.py b/app/scodoc/sco_semset.py index 08dd9460b..3bef77409 100644 --- a/app/scodoc/sco_semset.py +++ b/app/scodoc/sco_semset.py @@ -39,6 +39,8 @@ sem_set_list(context) """ +import flask + from app.scodoc import html_sco_header from app.scodoc import sco_cache from app.scodoc import sco_etape_apogee diff --git a/app/scodoc/sco_tag_module.py b/app/scodoc/sco_tag_module.py index 2cfaf566f..b11123b27 100644 --- a/app/scodoc/sco_tag_module.py +++ b/app/scodoc/sco_tag_module.py @@ -80,7 +80,7 @@ class ScoTag(object): self.tag_id = r[0]["tag_id"] else: # Create new tag: - log("creating new tag: %s" % self.title) + # log("creating new tag: %s" % self.title) cnx = ndb.GetDBConnexion() oid = ndb.DBInsertDict( cnx, self.tag_table, {"title": self.title}, commit=True @@ -121,7 +121,7 @@ class ScoTag(object): args, ) if not r: - log("tag %s with %s" % (object_id, self.title)) + # log("tag %s with %s" % (object_id, self.title)) cnx = ndb.GetDBConnexion() ndb.DBInsertDict(cnx, self.assoc_table, args, commit=True) @@ -130,7 +130,7 @@ class ScoTag(object): If no more modules tagged with this tag, delete it. Return True if Tag still exists. """ - log("removing tag %s from %s" % (self.title, object_id)) + # log("removing tag %s from %s" % (self.title, object_id)) args = {"object_id": object_id, "tag_id": self.tag_id} ndb.SimpleQuery( self.context, @@ -225,26 +225,17 @@ def module_tag_list(context, module_id=""): return [x["title"] for x in r] -def module_tag_set(context, module_id="", taglist=[], REQUEST=None): +def module_tag_set(context, module_id="", taglist=None): """taglist may either be: a string with tag names separated by commas ("un;deux") or a list of strings (["un", "deux"]) """ - # We check permission here to allow old Admins (with only ScoChangeFormation perm) - if REQUEST: # called from Web - authuser = REQUEST.AUTHENTICATED_USER - tag_editable = authuser.has_permission( - Permission.ScoEditFormationTags - ) or authuser.has_permission(Permission.ScoChangeFormation) - if not tag_editable: - raise AccessDenied("Modification des tags impossible pour %s" % authuser) - # if not taglist: taglist = [] elif isinstance(taglist, str): taglist = taglist.split(",") taglist = [t.strip() for t in taglist] - log("module_tag_set: module_id=%s taglist=%s" % (module_id, taglist)) + # log("module_tag_set: module_id=%s taglist=%s" % (module_id, taglist)) # Sanity check: Mod = sco_edit_module.do_module_list(context, args={"module_id": module_id}) if not Mod: diff --git a/app/scodoc/sco_trombino.py b/app/scodoc/sco_trombino.py index 12b0c5790..d72dce233 100644 --- a/app/scodoc/sco_trombino.py +++ b/app/scodoc/sco_trombino.py @@ -43,6 +43,7 @@ from reportlab.lib.colors import Color from reportlab.lib import colors from PIL import Image as PILImage +import flask from flask import url_for, g from app.scodoc.notes_log import log diff --git a/app/scodoc/sco_ue_external.py b/app/scodoc/sco_ue_external.py index 2758a171b..3a82d6ba0 100644 --- a/app/scodoc/sco_ue_external.py +++ b/app/scodoc/sco_ue_external.py @@ -53,6 +53,7 @@ Solution proposée (nov 2014): - seront aussi présentées (à part) sur la page "Voir les inscriptions aux modules" """ +import flask import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu diff --git a/app/views/absences.py b/app/views/absences.py index 509f49898..9ac72583b 100644 --- a/app/views/absences.py +++ b/app/views/absences.py @@ -57,6 +57,7 @@ import string import time from xml.etree import ElementTree +import flask from flask import g from flask import url_for from flask import current_app diff --git a/app/views/notes.py b/app/views/notes.py index e55ac2e17..dcf11b3fd 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -37,6 +37,7 @@ import pprint from operator import itemgetter from xml.etree import ElementTree +import flask from flask import url_for, g from flask import current_app @@ -449,11 +450,11 @@ def formation_export( @bp.route("/formation_import_xml") @permission_required(Permission.ScoChangeFormation) @scodoc7func(context) -def formation_import_xml(context, file, REQUEST): +def formation_import_xml(context, file): "import d'une formation en XML" log("formation_import_xml") doc = file.read() - return sco_formations.formation_import_xml(context, REQUEST, doc) + return sco_formations.formation_import_xml(context, doc) @bp.route("/formation_import_xml_form", methods=["GET", "POST"]) @@ -482,7 +483,7 @@ def formation_import_xml_form(context, REQUEST): return flask.redirect(scu.NotesURL()) else: formation_id, _, _ = sco_formations.formation_import_xml( - context, tf[2]["xmlfile"], REQUEST + context, tf[2]["xmlfile"] ) return ( diff --git a/app/views/scolar.py b/app/views/scolar.py index dad402fa1..883fd7600 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -40,6 +40,7 @@ from io import StringIO from zipfile import ZipFile import psycopg2 +import flask from flask import g, url_for from flask import current_app diff --git a/app/views/users.py b/app/views/users.py index 48ad70880..a705f809f 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -37,6 +37,7 @@ import datetime import re from xml.etree import ElementTree +import flask from flask import g from flask_login import current_user diff --git a/scotests/test_api7doc.py b/scotests/test_api7doc.py index 0a3596e92..564eb08d1 100644 --- a/scotests/test_api7doc.py +++ b/scotests/test_api7doc.py @@ -20,7 +20,7 @@ file.close() # --- Création de la formation -f = sco_formations.formation_import_xml(REQUEST=REQUEST, doc=doc, context=context.Notes) +f = sco_formations.formation_import_xml(doc=doc, context=context.Notes) # --- Création des semestres diff --git a/scotests/test_formation_export_xml.py b/scotests/test_formation_export_xml.py index 591774513..f33fee54e 100644 --- a/scotests/test_formation_export_xml.py +++ b/scotests/test_formation_export_xml.py @@ -1,5 +1,6 @@ import sco_formations import random + # La variable context est définie par le script de lancement # l'affecte ainsi pour évietr les warnins pylint: context = context # pylint: disable=undefined-variable @@ -18,10 +19,10 @@ print(doc) print("\n \n \n") # --- Création de la formation -f = sco_formations.formation_import_xml(REQUEST=REQUEST, doc=doc, context=context.Notes) +f = sco_formations.formation_import_xml(doc=doc, context=context.Notes) -# --- Création des semestres +# --- Création des semestres sem1 = G.create_formsemestre( formation_id=f[0], @@ -56,24 +57,26 @@ sem4 = G.create_formsemestre( li_module = context.Notes.do_module_list() mods_imp = [] -for mod in li_module : - if mod["semestre_id"] == 1 : +for mod in li_module: + if mod["semestre_id"] == 1: formsemestre_id = sem1["formsemestre_id"] - elif mod["semestre_id"] == 2 : + elif mod["semestre_id"] == 2: formsemestre_id = sem2["formsemestre_id"] - elif mod["semestre_id"] == 3 : + elif mod["semestre_id"] == 3: formsemestre_id = sem3["formsemestre_id"] - else : + else: formsemestre_id = sem4["formsemestre_id"] mi = G.create_moduleimpl( - module_id=mod["module_id"], - formsemestre_id=formsemestre_id, - responsable_id="bach", + module_id=mod["module_id"], + formsemestre_id=formsemestre_id, + responsable_id="bach", ) mods_imp.append(mi) # --- Test de export_formation format xml -form_exp = context.Notes.formation_export(formation_id=f[0], format="xml", REQUEST=REQUEST) +form_exp = context.Notes.formation_export( + formation_id=f[0], format="xml", REQUEST=REQUEST +) print(form_exp[39:]) diff --git a/scotests/test_scenario1_formation.py b/scotests/test_scenario1_formation.py index 6adf1bd86..564b3e1ab 100644 --- a/scotests/test_scenario1_formation.py +++ b/scotests/test_scenario1_formation.py @@ -1,5 +1,6 @@ import sco_formations import random + # La variable context est définie par le script de lancement # l'affecte ainsi pour évietr les warnins pylint: context = context # pylint: disable=undefined-variable @@ -17,9 +18,9 @@ file.close() # --- Création de la formation -f = sco_formations.formation_import_xml(REQUEST=REQUEST, doc=doc, context=context.Notes) +f = sco_formations.formation_import_xml(doc=doc, context=context.Notes) -# --- Création des semestres +# --- Création des semestres sem1 = G.create_formsemestre( formation_id=f[0], @@ -54,19 +55,19 @@ sem4 = G.create_formsemestre( li_module = context.Notes.do_module_list() mods_imp = [] -for mod in li_module : - if mod["semestre_id"] == 1 : +for mod in li_module: + if mod["semestre_id"] == 1: formsemestre_id = sem1["formsemestre_id"] - elif mod["semestre_id"] == 2 : + elif mod["semestre_id"] == 2: formsemestre_id = sem2["formsemestre_id"] - elif mod["semestre_id"] == 3 : + elif mod["semestre_id"] == 3: formsemestre_id = sem3["formsemestre_id"] - else : + else: formsemestre_id = sem4["formsemestre_id"] mi = G.create_moduleimpl( - module_id=mod["module_id"], - formsemestre_id=formsemestre_id, - responsable_id="bach", + module_id=mod["module_id"], + formsemestre_id=formsemestre_id, + responsable_id="bach", ) mods_imp.append(mi) \ No newline at end of file diff --git a/scotests/test_scenario2_formation.py b/scotests/test_scenario2_formation.py index b2a1bd63a..92a68530a 100644 --- a/scotests/test_scenario2_formation.py +++ b/scotests/test_scenario2_formation.py @@ -1,5 +1,6 @@ import sco_formations import random + # La variable context est définie par le script de lancement # l'affecte ainsi pour évietr les warnins pylint: context = context # pylint: disable=undefined-variable @@ -17,9 +18,9 @@ file.close() # --- Création de la formation -f = sco_formations.formation_import_xml(REQUEST=REQUEST, doc=doc, context=context.Notes) +f = sco_formations.formation_import_xml(doc=doc, context=context.Notes) -# --- Création des semestres +# --- Création des semestres sem1 = G.create_formsemestre( formation_id=f[0], @@ -54,26 +55,26 @@ sem4 = G.create_formsemestre( li_module = context.Notes.do_module_list() mods_imp = [] -for mod in li_module : - if mod["semestre_id"] == 1 : +for mod in li_module: + if mod["semestre_id"] == 1: formsemestre_id = sem1["formsemestre_id"] - elif mod["semestre_id"] == 2 : + elif mod["semestre_id"] == 2: formsemestre_id = sem2["formsemestre_id"] - elif mod["semestre_id"] == 3 : + elif mod["semestre_id"] == 3: formsemestre_id = sem3["formsemestre_id"] - else : + else: formsemestre_id = sem4["formsemestre_id"] mi = G.create_moduleimpl( - module_id=mod["module_id"], - formsemestre_id=formsemestre_id, - responsable_id="bach", + module_id=mod["module_id"], + formsemestre_id=formsemestre_id, + responsable_id="bach", ) mods_imp.append(mi) # --- Création des étudiants -etuds=[] +etuds = [] for nom, prenom in [ ("Semestre11", "EtudiantNumero1"), ("Semestre12", "EtudiantNumero2"), @@ -82,8 +83,8 @@ for nom, prenom in [ ("Semestre35", "EtudiantNumero5"), ("Semestre36", "EtudiantNumero6"), ("Semestre47", "EtudiantNumero7"), - ("Semestre48", "EtudiantNumero8") -] : + ("Semestre48", "EtudiantNumero8"), +]: etud = G.create_etud( nom=nom, prenom=prenom, diff --git a/scotests/test_scenario3_formation.py b/scotests/test_scenario3_formation.py index b814690cb..074ab0be8 100644 --- a/scotests/test_scenario3_formation.py +++ b/scotests/test_scenario3_formation.py @@ -1,6 +1,7 @@ import sco_formations import json import random + # La variable context est définie par le script de lancement # l'affecte ainsi pour évietr les warnins pylint: context = context # pylint: disable=undefined-variable @@ -18,9 +19,9 @@ file.close() # --- Création de la formation -f = sco_formations.formation_import_xml(REQUEST=REQUEST, doc=doc, context=context.Notes) +f = sco_formations.formation_import_xml(doc=doc, context=context.Notes) -# --- Création des semestres +# --- Création des semestres sem1 = G.create_formsemestre( formation_id=f[0], @@ -55,26 +56,26 @@ sem4 = G.create_formsemestre( li_module = context.Notes.do_module_list() mods_imp = [] -for mod in li_module : - if mod["semestre_id"] == 1 : +for mod in li_module: + if mod["semestre_id"] == 1: formsemestre_id = sem1["formsemestre_id"] - elif mod["semestre_id"] == 2 : + elif mod["semestre_id"] == 2: formsemestre_id = sem2["formsemestre_id"] - elif mod["semestre_id"] == 3 : + elif mod["semestre_id"] == 3: formsemestre_id = sem3["formsemestre_id"] - else : + else: formsemestre_id = sem4["formsemestre_id"] mi = G.create_moduleimpl( - module_id=mod["module_id"], - formsemestre_id=formsemestre_id, - responsable_id="bach", + module_id=mod["module_id"], + formsemestre_id=formsemestre_id, + responsable_id="bach", ) mods_imp.append(mi) # --- Création des étudiants -etuds=[] +etuds = [] for nom, prenom in [ ("Semestre11", "EtudiantNumero1"), ("Semestre12", "EtudiantNumero2"), @@ -83,8 +84,8 @@ for nom, prenom in [ ("Semestre35", "EtudiantNumero5"), ("Semestre36", "EtudiantNumero6"), ("Semestre47", "EtudiantNumero7"), - ("Semestre48", "EtudiantNumero8") -] : + ("Semestre48", "EtudiantNumero8"), +]: etud = G.create_etud( nom=nom, prenom=prenom, @@ -107,16 +108,24 @@ for etud in etuds[6:]: # --- Création d'une évaluation pour chaque UE -lim_sem1 = sco_moduleimpl.do_moduleimpl_list(context.Notes, formsemestre_id=sem1["formsemestre_id"], REQUEST=REQUEST) +lim_sem1 = sco_moduleimpl.do_moduleimpl_list( + context.Notes, formsemestre_id=sem1["formsemestre_id"], REQUEST=REQUEST +) load_lim_sem1 = json.loads(lim_sem1) -lim_sem2 = sco_moduleimpl.do_moduleimpl_list(context.Notes, formsemestre_id=sem2["formsemestre_id"], REQUEST=REQUEST) +lim_sem2 = sco_moduleimpl.do_moduleimpl_list( + context.Notes, formsemestre_id=sem2["formsemestre_id"], REQUEST=REQUEST +) load_lim_sem2 = json.loads(lim_sem2) -lim_sem3 = sco_moduleimpl.do_moduleimpl_list(context.Notes, formsemestre_id=sem3["formsemestre_id"], REQUEST=REQUEST) +lim_sem3 = sco_moduleimpl.do_moduleimpl_list( + context.Notes, formsemestre_id=sem3["formsemestre_id"], REQUEST=REQUEST +) load_lim_sem3 = json.loads(lim_sem3) -lim_sem4 = sco_moduleimpl.do_moduleimpl_list(context.Notes, formsemestre_id=sem4["formsemestre_id"], REQUEST=REQUEST) +lim_sem4 = sco_moduleimpl.do_moduleimpl_list( + context.Notes, formsemestre_id=sem4["formsemestre_id"], REQUEST=REQUEST +) load_lim_sem4 = json.loads(lim_sem4) @@ -131,5 +140,10 @@ for moduleimpl_id, jour, description, coefficient in [ (load_lim_sem4[3]["moduleimpl_id"], "03/02/2021", "InterroTestSemestre4", 1.0), (load_lim_sem4[9]["moduleimpl_id"], "04/02/2021", "InterroTestSemestre4", 1.0), (load_lim_sem4[13]["moduleimpl_id"], "05/02/2021", "InterroTestSemestre4", 1.0), -] : - e = G.create_evaluation(moduleimpl_id=moduleimpl_id, jour=jour, description=description, coefficient=coefficient) \ No newline at end of file +]: + e = G.create_evaluation( + moduleimpl_id=moduleimpl_id, + jour=jour, + description=description, + coefficient=coefficient, + ) diff --git a/scotests/test_scenario4_formation.py b/scotests/test_scenario4_formation.py index 17f917949..0f3f29baf 100644 --- a/scotests/test_scenario4_formation.py +++ b/scotests/test_scenario4_formation.py @@ -1,6 +1,7 @@ import sco_formations import json import random + # La variable context est définie par le script de lancement # l'affecte ainsi pour évietr les warnins pylint: context = context # pylint: disable=undefined-variable @@ -16,12 +17,11 @@ doc = file.read() file.close() - # --- Création de la formation -f = sco_formations.formation_import_xml(REQUEST=REQUEST, doc=doc, context=context.Notes) +f = sco_formations.formation_import_xml(doc=doc, context=context.Notes) -# --- Création des semestres +# --- Création des semestres sem1 = G.create_formsemestre( formation_id=f[0], @@ -56,26 +56,26 @@ sem4 = G.create_formsemestre( li_module = context.Notes.do_module_list() mods_imp = [] -for mod in li_module : - if mod["semestre_id"] == 1 : +for mod in li_module: + if mod["semestre_id"] == 1: formsemestre_id = sem1["formsemestre_id"] - elif mod["semestre_id"] == 2 : + elif mod["semestre_id"] == 2: formsemestre_id = sem2["formsemestre_id"] - elif mod["semestre_id"] == 3 : + elif mod["semestre_id"] == 3: formsemestre_id = sem3["formsemestre_id"] - else : + else: formsemestre_id = sem4["formsemestre_id"] mi = G.create_moduleimpl( - module_id=mod["module_id"], - formsemestre_id=formsemestre_id, - responsable_id="bach", + module_id=mod["module_id"], + formsemestre_id=formsemestre_id, + responsable_id="bach", ) mods_imp.append(mi) # --- Création des étudiants -etuds=[] +etuds = [] for nom, prenom in [ ("Semestre11", "EtudiantNumero1"), ("Semestre12", "EtudiantNumero2"), @@ -84,8 +84,8 @@ for nom, prenom in [ ("Semestre35", "EtudiantNumero5"), ("Semestre36", "EtudiantNumero6"), ("Semestre47", "EtudiantNumero7"), - ("Semestre48", "EtudiantNumero8") -] : + ("Semestre48", "EtudiantNumero8"), +]: etud = G.create_etud( nom=nom, prenom=prenom, @@ -108,16 +108,24 @@ for etud in etuds[6:]: # --- Création d'une évaluation pour chaque UE -lim_sem1 = sco_moduleimpl.do_moduleimpl_list(context.Notes, formsemestre_id=sem1["formsemestre_id"], REQUEST=REQUEST) +lim_sem1 = sco_moduleimpl.do_moduleimpl_list( + context.Notes, formsemestre_id=sem1["formsemestre_id"], REQUEST=REQUEST +) load_lim_sem1 = json.loads(lim_sem1) -lim_sem2 = sco_moduleimpl.do_moduleimpl_list(context.Notes, formsemestre_id=sem2["formsemestre_id"], REQUEST=REQUEST) +lim_sem2 = sco_moduleimpl.do_moduleimpl_list( + context.Notes, formsemestre_id=sem2["formsemestre_id"], REQUEST=REQUEST +) load_lim_sem2 = json.loads(lim_sem2) -lim_sem3 = sco_moduleimpl.do_moduleimpl_list(context.Notes, formsemestre_id=sem3["formsemestre_id"], REQUEST=REQUEST) +lim_sem3 = sco_moduleimpl.do_moduleimpl_list( + context.Notes, formsemestre_id=sem3["formsemestre_id"], REQUEST=REQUEST +) load_lim_sem3 = json.loads(lim_sem3) -lim_sem4 = sco_moduleimpl.do_moduleimpl_list(context.Notes, formsemestre_id=sem4["formsemestre_id"], REQUEST=REQUEST) +lim_sem4 = sco_moduleimpl.do_moduleimpl_list( + context.Notes, formsemestre_id=sem4["formsemestre_id"], REQUEST=REQUEST +) load_lim_sem4 = json.loads(lim_sem4) @@ -132,42 +140,71 @@ for moduleimpl_id, jour, description, coefficient in [ (load_lim_sem4[3]["moduleimpl_id"], "03/02/2021", "InterroTestSemestre4", 1.0), (load_lim_sem4[9]["moduleimpl_id"], "04/02/2021", "InterroTestSemestre4", 1.0), (load_lim_sem4[13]["moduleimpl_id"], "05/02/2021", "InterroTestSemestre4", 1.0), -] : - e = G.create_evaluation(moduleimpl_id=moduleimpl_id, jour=jour, description=description, coefficient=coefficient) +]: + e = G.create_evaluation( + moduleimpl_id=moduleimpl_id, + jour=jour, + description=description, + coefficient=coefficient, + ) # --- Saisie des notes des étudiants (un élève a 12, un autre a 7 pour chaque semestre) -lie1 = context.Notes.do_evaluation_list_in_formsemestre(formsemestre_id=sem1["formsemestre_id"]) -lie2 = context.Notes.do_evaluation_list_in_formsemestre(formsemestre_id=sem2["formsemestre_id"]) -lie3 = context.Notes.do_evaluation_list_in_formsemestre(formsemestre_id=sem3["formsemestre_id"]) -lie4 = context.Notes.do_evaluation_list_in_formsemestre(formsemestre_id=sem4["formsemestre_id"]) +lie1 = context.Notes.do_evaluation_list_in_formsemestre( + formsemestre_id=sem1["formsemestre_id"] +) +lie2 = context.Notes.do_evaluation_list_in_formsemestre( + formsemestre_id=sem2["formsemestre_id"] +) +lie3 = context.Notes.do_evaluation_list_in_formsemestre( + formsemestre_id=sem3["formsemestre_id"] +) +lie4 = context.Notes.do_evaluation_list_in_formsemestre( + formsemestre_id=sem4["formsemestre_id"] +) -for eval in lie1 : - for etud in etuds[:2] : - if etud == etuds[0] : - nb_changed, nb_suppress, existing_decisions = G.create_note(evaluation=eval, etud=etud, note=12.0) - else : - nb_changed, nb_suppress, existing_decisions = G.create_note(evaluation=eval, etud=etud, note=7.0) +for eval in lie1: + for etud in etuds[:2]: + if etud == etuds[0]: + nb_changed, nb_suppress, existing_decisions = G.create_note( + evaluation=eval, etud=etud, note=12.0 + ) + else: + nb_changed, nb_suppress, existing_decisions = G.create_note( + evaluation=eval, etud=etud, note=7.0 + ) -for eval in lie2 : - for etud in etuds[2:4] : - if etud == etuds[2] : - nb_changed, nb_suppress, existing_decisions = G.create_note(evaluation=eval, etud=etud, note=12.0) - else : - nb_changed, nb_suppress, existing_decisions = G.create_note(evaluation=eval, etud=etud, note=7.0) +for eval in lie2: + for etud in etuds[2:4]: + if etud == etuds[2]: + nb_changed, nb_suppress, existing_decisions = G.create_note( + evaluation=eval, etud=etud, note=12.0 + ) + else: + nb_changed, nb_suppress, existing_decisions = G.create_note( + evaluation=eval, etud=etud, note=7.0 + ) -for eval in lie3 : - for etud in etuds[4:6] : - if etud == etuds[4] : - nb_changed, nb_suppress, existing_decisions = G.create_note(evaluation=eval, etud=etud, note=12.0) - else : - nb_changed, nb_suppress, existing_decisions = G.create_note(evaluation=eval, etud=etud, note=7.0) +for eval in lie3: + for etud in etuds[4:6]: + if etud == etuds[4]: + nb_changed, nb_suppress, existing_decisions = G.create_note( + evaluation=eval, etud=etud, note=12.0 + ) + else: + nb_changed, nb_suppress, existing_decisions = G.create_note( + evaluation=eval, etud=etud, note=7.0 + ) -for eval in lie4 : - for etud in etuds[6:] : - if etud == etuds[6] : - nb_changed, nb_suppress, existing_decisions = G.create_note(evaluation=eval, etud=etud, note=12.0) - else : - nb_changed, nb_suppress, existing_decisions = G.create_note(evaluation=eval, etud=etud, note=7.0) \ No newline at end of file +for eval in lie4: + for etud in etuds[6:]: + if etud == etuds[6]: + nb_changed, nb_suppress, existing_decisions = G.create_note( + evaluation=eval, etud=etud, note=12.0 + ) + else: + nb_changed, nb_suppress, existing_decisions = G.create_note( + evaluation=eval, etud=etud, note=7.0 + ) diff --git a/tests/unit/test_formations.py b/tests/unit/test_formations.py index e37330414..a3af8c9b9 100644 --- a/tests/unit/test_formations.py +++ b/tests/unit/test_formations.py @@ -53,7 +53,6 @@ from app.scodoc import sco_edit_module from app.scodoc import sco_edit_ue from app.scodoc import sco_formations from app.scodoc import sco_formsemestre_edit -from app.scodoc import sco_formsemestre_status from app.scodoc import sco_moduleimpl from app.views import notes @@ -343,4 +342,40 @@ def test_formations(test_client): lif3 = notes.formation_list(context, format="json") assert isinstance(lif3, str) load_lif3 = json.loads(lif3) - assert len(load_lif3) == 1 \ No newline at end of file + assert len(load_lif3) == 1 + + +def test_import_formation(test_client): + """Test import/export formations""" + G = sco_fake_gen.ScoFake(verbose=False) + # Lecture fichier XML local: + with open("tests/unit/formation-exemple-1.xml") as f: + doc = f.read() + + # --- Création de la formation + f = sco_formations.formation_import_xml(context, doc) + assert len(f) == 3 # 3-uple + formation_id = f[0] + # --- Mise en place de 4 semestres + sems = [ + G.create_formsemestre( + formation_id=formation_id, + semestre_id=x[0], + date_debut=x[1], + date_fin=x[2], + ) + for x in ( + (1, "05/09/2019", "05/01/2020"), + (2, "06/01/2020", "30/06/2020"), + (3, "01/09/2020", "05/01/2021"), + (4, "06/01/2021", "30/06/2021"), + ) + ] + # et les modules + modules = sco_edit_module.do_module_list(context, {"formation_id": formation_id}) + for mod in modules: + mi = G.create_moduleimpl( + module_id=mod["module_id"], + formsemestre_id=sems[mod["semestre_id"] - 1], + responsable_id="bach", + )