fix route recherche étudiant via JS

This commit is contained in:
Emmanuel Viennet 2021-08-31 08:21:30 +02:00
parent dca51d1ce4
commit 3ac4623421
4 changed files with 20 additions and 16 deletions

View File

@ -403,9 +403,7 @@ def next_ue_numero(formation_id, semestre_id=None):
return ue_list[-1]["numero"] + 1000 return ue_list[-1]["numero"] + 1000
def ue_delete( def ue_delete(ue_id=None, delete_validations=False, dialog_confirmed=False):
ue_id=None, delete_validations=False, dialog_confirmed=False, REQUEST=None
):
"""Delete an UE""" """Delete an UE"""
ue = do_ue_list(args={"ue_id": ue_id}) ue = do_ue_list(args={"ue_id": ue_id})
if not ue: if not ue:

View File

@ -231,10 +231,11 @@ def search_etuds_infos(expnom=None, code_nip=None):
return etuds 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 """Recherche noms étudiants par début du nom, pour autocomplete
Accepte aussi un début de code NIP (au moins 6 caractères) 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" : "<nip> <nom> <prenom>", "value" : etudid }
""" """
may_be_nip = scu.is_valid_code_nip(term) may_be_nip = scu.is_valid_code_nip(term)
# term = term.upper() # conserve les accents # term = term.upper() # conserve les accents
@ -264,9 +265,9 @@ def search_etud_by_name(term, REQUEST=None):
] ]
else: else:
r = ndb.SimpleDictFetch( r = ndb.SimpleDictFetch(
"""SELECT id AS etudid, nom, prenom """SELECT id AS etudid, nom, prenom
FROM identite FROM identite
WHERE nom LIKE %(beginning)s WHERE nom LIKE %(beginning)s
ORDER BY nom ORDER BY nom
""", """,
{"beginning": term + "%"}, {"beginning": term + "%"},
@ -279,8 +280,7 @@ def search_etud_by_name(term, REQUEST=None):
} }
for x in r for x in r
] ]
# log(data) return data
return scu.sendJSON(REQUEST, data)
# ---------- Recherche sur plusieurs département # ---------- Recherche sur plusieurs département

View File

@ -40,8 +40,8 @@ from zipfile import ZipFile
import psycopg2 import psycopg2
import flask import flask
from flask import g, url_for from flask import jsonify, url_for
from flask import current_app from flask import current_app, g, request
from flask_login import current_user from flask_login import current_user
from config import Config from config import Config
@ -320,9 +320,15 @@ sco_publish(
methods=["GET", "POST"], 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 # XMLgetEtudInfos était le nom dans l'ancienne API ScoDoc 6

View File

@ -1,7 +1,7 @@
# -*- mode: python -*- # -*- mode: python -*-
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
SCOVERSION = "9.0.6" SCOVERSION = "9.0.7"
SCONAME = "ScoDoc" SCONAME = "ScoDoc"