# -*- mode: python -*- # -*- coding: utf-8 -*- ############################################################################## # # Gestion scolarite IUT # # Copyright (c) 1999 - 2021 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 # ############################################################################## """Recherche d'étudiants """ from types import ListType import xml.dom.minidom import sco_utils as scu import notesdb as ndb from notes_log import log from gen_tables import GenTable import html_sco_header import scolars import sco_formsemestre import sco_groups from sco_permissions import ScoView def form_search_etud( context, REQUEST=None, dest_url=None, parameters=None, parameters_keys=None, title="Rechercher un étudiant par nom : ", add_headers=False, # complete page ): "form recherche par nom" H = [] if title: H.append("
La recherche porte sur tout ou partie du NOM ou du NIP de l'étudiant
""" ) return "\n".join(H) + html_sco_header.sco_footer(context, REQUEST) # Was chercheEtudsInfo() def search_etuds_infos(context, expnom=None, code_nip=None, REQUEST=None): """recherche les étudiants correspondants à expnom ou au code_nip et ramene liste de mappings utilisables en DTML. """ may_be_nip = scu.is_valid_code_nip(expnom) cnx = context.GetDBConnexion() if expnom and not may_be_nip: expnom = scu.strupper(expnom) # les noms dans la BD sont en uppercase etuds = scolars.etudident_list(cnx, args={"nom": expnom}, test="~") else: code_nip = code_nip or expnom if code_nip: etuds = scolars.etudident_list(cnx, args={"code_nip": code_nip}) else: etuds = [] context.fillEtudsInfo(etuds) return etuds def search_etud_by_name(context, term, REQUEST=None): """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 """ may_be_nip = scu.is_valid_code_nip(term) # term = scu.strupper(term) # conserve les accents term = term.upper() if ( not scu.ALPHANUM_EXP.match( term.decode(scu.SCO_ENCODING) ) # n'autorise pas les caractères spéciaux and not may_be_nip ): data = [] else: if may_be_nip: r = ndb.SimpleDictFetch( context, "SELECT nom, prenom, code_nip FROM identite WHERE code_nip LIKE %(beginning)s ORDER BY nom", {"beginning": term + "%"}, ) data = [ { "label": "%s %s %s" % (x["code_nip"], x["nom"], scolars.format_prenom(x["prenom"])), "value": x["code_nip"], } for x in r ] else: r = ndb.SimpleDictFetch( context, "SELECT etudid, nom, prenom FROM identite WHERE nom LIKE %(beginning)s ORDER BY nom", {"beginning": term + "%"}, ) data = [ { "label": "%s %s" % (x["nom"], scolars.format_prenom(x["prenom"])), "value": x["etudid"], } for x in r ] # log(data) return scu.sendJSON(REQUEST, data) # ---------- Recherche sur plusieurs département def form_search_etud_in_accessible_depts(context, REQUEST): """Form recherche etudiants pour page accueil ScoDoc""" authuser = REQUEST.AUTHENTICATED_USER # present form only to authenticated users if not authuser.has_role("Authenticated"): return "" return """