From 7622cd1a7ee4d410c70000d96bf0ca99739a991b Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 18 Feb 2021 08:07:21 +0100 Subject: [PATCH] optimized etud search box --- html_sidebar.py | 2 +- sco_find_etud.py | 115 ++++++++++++++++------------------------------- 2 files changed, 39 insertions(+), 78 deletions(-) diff --git a/html_sidebar.py b/html_sidebar.py index 1216eae..0079b56 100644 --- a/html_sidebar.py +++ b/html_sidebar.py @@ -88,7 +88,7 @@ def sidebar(context, REQUEST=None): H.append( """
Chercher étudiant:
-
+
diff --git a/sco_find_etud.py b/sco_find_etud.py index 27ccf83..7038a16 100644 --- a/sco_find_etud.py +++ b/sco_find_etud.py @@ -96,73 +96,52 @@ def form_search_etud( return "\n".join(H) -# was chercheEtud() -def search_etud_in_dept( - context, - expnom=None, - dest_url="ficheEtud", - parameters={}, - parameters_keys="", - add_headers=True, # complete page - title=None, - REQUEST=None, -): - """Page recherche d'un etudiant - expnom est un regexp sur le nom ou un code_nip ou un etudid - dest_url est la page sur laquelle on sera redirigé après choix - parameters spécifie des arguments additionnels à passer à l'URL (en plus de etudid) +def search_etud_in_dept(context, expnom="", REQUEST=None): + """Page recherche d'un etudiant. + + Affiche la fiche de l'étudiant, ou, si la recherche donne plusieurs résultats, la liste des étudianst + correspondants. + Appelée par boite de recherche barre latérale gauche. + + Args: + expnom: string, regexp sur le nom ou un code_nip ou un etudid """ - if type(expnom) == ListType: - expnom = expnom[0] - q = [] - if parameters: - for param in parameters.keys(): - q.append("%s=%s" % (param, parameters[param])) - elif parameters_keys: - for key in parameters_keys.split(","): - v = REQUEST.form.get(key, False) - if v: - q.append("%s=%s" % (key, v)) - query_string = "&".join(q) - - no_side_bar = True - H = [] - if title: - H.append("

%s

" % title) - - if scu.is_valid_code_nip(expnom): - etuds = search_etuds_infos(context, code_nip=expnom, REQUEST=REQUEST) - elif expnom: - etuds = search_etuds_infos(context, expnom=expnom, REQUEST=REQUEST) - if expnom and not etuds: + dest_url = "ficheEtud" + if len(expnom) > 1: etuds = context.getEtudInfo(filled=1, etudid=expnom, REQUEST=REQUEST) if len(etuds) != 1: - etuds = [] + if scu.is_valid_code_nip(expnom): + etuds = search_etuds_infos(context, code_nip=expnom, REQUEST=REQUEST) + else: + etuds = search_etuds_infos(context, expnom=expnom, REQUEST=REQUEST) + else: + etuds = [] # si expnom est trop court, n'affiche rien + if len(etuds) == 1: # va directement a la destination - return REQUEST.RESPONSE.redirect( - dest_url + "?etudid=%s&" % etuds[0]["etudid"] + query_string - ) + return context.ficheEtud(etudid=etuds[0]["etudid"], REQUEST=REQUEST) + H = [ + context.sco_header( + page_title="Recherche d'un étudiant", + no_side_bar=True, + init_qtip=True, + javascripts=["js/etud_info.js"], + REQUEST=REQUEST, + ), + """

%d résultats pour "%s": choisissez un étudiant:

""" + % (len(etuds), expnom), + form_search_etud( + context, + dest_url=dest_url, + REQUEST=REQUEST, + title="Autre recherche", + ), + ] if len(etuds) > 0: # Choix dans la liste des résultats: - H.append( - """

%d résultats pour "%s": choisissez un étudiant:

""" - % (len(etuds), expnom) - ) - H.append( - form_search_etud( - context, - dest_url=dest_url, - parameters=parameters, - parameters_keys=parameters_keys, - REQUEST=REQUEST, - title="Autre recherche", - ) - ) - for e in etuds: - target = dest_url + "?etudid=%s&" % e["etudid"] + query_string + target = dest_url + "?etudid=%s&" % e["etudid"] e["_nomprenom_target"] = target e["inscription_target"] = target e["_nomprenom_td_attrs"] = 'id="%s" class="etudinfo"' % (e["etudid"]) @@ -187,34 +166,16 @@ def search_etud_in_dept( form_search_etud( context, dest_url=dest_url, - parameters=parameters, - parameters_keys=parameters_keys, REQUEST=REQUEST, title="Autre recherche", ) ) - else: H.append('

Aucun résultat pour "%s".

' % expnom) - add_headers = True - no_side_bar = False H.append( """

La recherche porte sur tout ou partie du NOM ou du NIP de l'étudiant

""" ) - if add_headers: - return ( - context.sco_header( - REQUEST, - page_title="Choix d'un étudiant", - init_qtip=True, - javascripts=["js/etud_info.js"], - no_side_bar=no_side_bar, - ) - + "\n".join(H) - + context.sco_footer(REQUEST) - ) - else: - return "\n".join(H) + return "\n".join(H) + context.sco_footer(REQUEST) # Was chercheEtudsInfo()