From 3ac46234219f607608cf2751b61744c3bca49dfe Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 31 Aug 2021 08:21:30 +0200 Subject: [PATCH] =?UTF-8?q?fix=20route=20recherche=20=C3=A9tudiant=20via?= =?UTF-8?q?=20JS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_edit_ue.py | 4 +--- app/scodoc/sco_find_etud.py | 14 +++++++------- app/views/scolar.py | 16 +++++++++++----- sco_version.py | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index b717daea..e2a40ed4 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -403,9 +403,7 @@ def next_ue_numero(formation_id, semestre_id=None): return ue_list[-1]["numero"] + 1000 -def ue_delete( - ue_id=None, delete_validations=False, dialog_confirmed=False, REQUEST=None -): +def ue_delete(ue_id=None, delete_validations=False, dialog_confirmed=False): """Delete an UE""" ue = do_ue_list(args={"ue_id": ue_id}) if not ue: diff --git a/app/scodoc/sco_find_etud.py b/app/scodoc/sco_find_etud.py index 027276d9..2d828ee6 100644 --- a/app/scodoc/sco_find_etud.py +++ b/app/scodoc/sco_find_etud.py @@ -231,10 +231,11 @@ def search_etuds_infos(expnom=None, code_nip=None): return etuds -def search_etud_by_name(term, REQUEST=None): +def search_etud_by_name(term: str) -> list: """Recherche noms étudiants par début du nom, pour autocomplete Accepte aussi un début de code NIP (au moins 6 caractères) - Renvoie une liste de nom en JSON + Renvoie une liste de dicts + { "label" : " ", "value" : etudid } """ may_be_nip = scu.is_valid_code_nip(term) # term = term.upper() # conserve les accents @@ -264,9 +265,9 @@ def search_etud_by_name(term, REQUEST=None): ] else: r = ndb.SimpleDictFetch( - """SELECT id AS etudid, nom, prenom - FROM identite - WHERE nom LIKE %(beginning)s + """SELECT id AS etudid, nom, prenom + FROM identite + WHERE nom LIKE %(beginning)s ORDER BY nom """, {"beginning": term + "%"}, @@ -279,8 +280,7 @@ def search_etud_by_name(term, REQUEST=None): } for x in r ] - # log(data) - return scu.sendJSON(REQUEST, data) + return data # ---------- Recherche sur plusieurs département diff --git a/app/views/scolar.py b/app/views/scolar.py index 7d817cc3..54640bea 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -40,8 +40,8 @@ from zipfile import ZipFile import psycopg2 import flask -from flask import g, url_for -from flask import current_app +from flask import jsonify, url_for +from flask import current_app, g, request from flask_login import current_user from config import Config @@ -320,9 +320,15 @@ sco_publish( methods=["GET", "POST"], ) -sco_publish( - "/search_etud_by_name", sco_find_etud.search_etud_by_name, Permission.ScoView -) + +@bp.route("/search_etud_by_name") +@bp.route("/Notes/search_etud_by_name") # for JS apis +@scodoc +@permission_required(Permission.ScoView) +def search_etud_by_name(): + term = request.args["term"] + data = sco_find_etud.search_etud_by_name(term) + return jsonify(data) # XMLgetEtudInfos était le nom dans l'ancienne API ScoDoc 6 diff --git a/sco_version.py b/sco_version.py index ae606040..1ad26613 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.0.6" +SCOVERSION = "9.0.7" SCONAME = "ScoDoc"