forked from ScoDoc/ScoDoc
recherche étudiant inter-département
This commit is contained in:
parent
9646452457
commit
748caf8ada
@ -33,10 +33,11 @@ def unquote(s):
|
||||
return s.replace("&", "&")
|
||||
|
||||
|
||||
def open_dept_connection():
|
||||
"""Open a connection to the current dept db"""
|
||||
# log("open_dept_connection to " + scu.get_db_cnx_string())
|
||||
return psycopg2.connect(scu.get_db_cnx_string())
|
||||
def open_dept_connection(scodoc_dept=None):
|
||||
"""Open a connection to the current dept db (g.scodoc_dept)
|
||||
or to the argument scodoc_dept
|
||||
"""
|
||||
return psycopg2.connect(scu.get_db_cnx_string(scodoc_dept))
|
||||
|
||||
|
||||
def close_dept_connection():
|
||||
@ -46,7 +47,16 @@ def close_dept_connection():
|
||||
g.db_conn.close()
|
||||
|
||||
|
||||
# Essai bien plus simple pour Flask:
|
||||
def set_sco_dept(scodoc_dept):
|
||||
"""Set "context" to given dept
|
||||
open db connection
|
||||
"""
|
||||
g.scodoc_dept = scodoc_dept
|
||||
if hasattr(g, "db_conn"):
|
||||
close_dept_connection()
|
||||
g.db_conn = open_dept_connection()
|
||||
|
||||
|
||||
def GetDBConnexion(autocommit=True): # on n'utilise plus autocommit
|
||||
return g.db_conn
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
"""Recherche d'étudiants
|
||||
"""
|
||||
from flask import url_for, g
|
||||
from flask_login import current_user
|
||||
|
||||
from scodoc_manager import sco_mgr
|
||||
import app.scodoc.sco_utils as scu
|
||||
@ -98,8 +99,8 @@ def form_search_etud(
|
||||
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.
|
||||
Affiche la fiche de l'étudiant, ou, si la recherche donne plusieurs résultats,
|
||||
la liste des étudiants correspondants.
|
||||
Appelée par boite de recherche barre latérale gauche.
|
||||
|
||||
Args:
|
||||
@ -109,9 +110,9 @@ def search_etud_in_dept(context, expnom="", REQUEST=None):
|
||||
etuds = sco_etud.get_etud_info(filled=1, etudid=expnom, REQUEST=REQUEST)
|
||||
if len(etuds) != 1:
|
||||
if scu.is_valid_code_nip(expnom):
|
||||
etuds = search_etuds_infos(context, code_nip=expnom, REQUEST=REQUEST)
|
||||
etuds = search_etuds_infos(code_nip=expnom)
|
||||
else:
|
||||
etuds = search_etuds_infos(context, expnom=expnom, REQUEST=REQUEST)
|
||||
etuds = search_etuds_infos(expnom=expnom)
|
||||
else:
|
||||
etuds = [] # si expnom est trop court, n'affiche rien
|
||||
|
||||
@ -188,7 +189,7 @@ def search_etud_in_dept(context, expnom="", REQUEST=None):
|
||||
|
||||
|
||||
# Was chercheEtudsInfo()
|
||||
def search_etuds_infos(context, expnom=None, code_nip=None, REQUEST=None):
|
||||
def search_etuds_infos(expnom=None, code_nip=None):
|
||||
"""recherche les étudiants correspondants à expnom ou au code_nip
|
||||
et ramene liste de mappings utilisables en DTML.
|
||||
"""
|
||||
@ -270,36 +271,31 @@ def form_search_etud_in_accessible_depts(context, REQUEST):
|
||||
"""
|
||||
|
||||
|
||||
def search_etud_in_accessible_depts(context, expnom=None, code_nip=None, REQUEST=None):
|
||||
def search_etud_in_accessible_depts(expnom=None, code_nip=None):
|
||||
"""
|
||||
context est le ZScoDoc
|
||||
result is a list of (sorted) etuds, one list per dept.
|
||||
"""
|
||||
result = []
|
||||
accessible_depts = []
|
||||
depts = sco_mgr.get_dept_ids()
|
||||
for dept in depts:
|
||||
# log('%s searching %s' % (str(REQUEST.AUTHENTICATED_USER),dept))
|
||||
if REQUEST.AUTHENTICATED_USER.has_permission(Permission.ScoView, dept=dept):
|
||||
if current_user.has_permission(Permission.ScoView, dept=dept):
|
||||
if expnom or code_nip:
|
||||
accessible_depts.append(dept.Scolarite.DeptId())
|
||||
etuds = search_etuds_infos(
|
||||
dept.Scolarite, expnom=expnom, code_nip=code_nip, REQUEST=REQUEST
|
||||
)
|
||||
accessible_depts.append(dept)
|
||||
ndb.set_sco_dept(dept)
|
||||
etuds = search_etuds_infos(expnom=expnom, code_nip=code_nip)
|
||||
else:
|
||||
etuds = []
|
||||
result.append(etuds)
|
||||
return result, accessible_depts
|
||||
|
||||
|
||||
def table_etud_in_accessible_depts(context, expnom=None, REQUEST=None):
|
||||
def table_etud_in_accessible_depts(expnom=None):
|
||||
"""
|
||||
Page avec table étudiants trouvés, dans tous les departements.
|
||||
Attention: nous sommes ici au niveau de ScoDoc, pas dans un département
|
||||
"""
|
||||
result, accessible_depts = search_etud_in_accessible_depts(
|
||||
context, expnom=expnom, REQUEST=REQUEST
|
||||
)
|
||||
result, accessible_depts = search_etud_in_accessible_depts(expnom=expnom)
|
||||
H = [
|
||||
"""<div class="table_etud_in_accessible_depts">""",
|
||||
"""<h3>Recherche multi-département de "<tt>%s</tt>"</h3>""" % expnom,
|
||||
@ -330,15 +326,18 @@ def table_etud_in_accessible_depts(context, expnom=None, REQUEST=None):
|
||||
else:
|
||||
ss = ""
|
||||
H.append(
|
||||
"""<p>(recherche menée dans le%s département%s: %s)</p><p>
|
||||
<a href=".." class="stdlink">Retour à l'accueil</a></p>"""
|
||||
% (ss, ss, ", ".join(accessible_depts))
|
||||
f"""<p>(recherche menée dans le{ss} département{ss}:
|
||||
{", ".join(accessible_depts)})
|
||||
</p>
|
||||
<p>
|
||||
<a href="{url_for("scodoc.index")}" class="stdlink">Retour à l'accueil</a>
|
||||
</p>
|
||||
</div>
|
||||
"""
|
||||
)
|
||||
H.append("</div>")
|
||||
|
||||
return (
|
||||
html_sco_header.scodoc_top_html_header(
|
||||
context, REQUEST, page_title="Choix d'un étudiant"
|
||||
None, None, page_title="Choix d'un étudiant"
|
||||
)
|
||||
+ "\n".join(H)
|
||||
+ html_sco_header.standard_html_footer()
|
||||
|
@ -322,8 +322,8 @@ def get_dept_id():
|
||||
raise sco_exceptions.ScoInvalidDept("département invalide: %s" % g.scodoc_dept)
|
||||
|
||||
|
||||
def get_db_cnx_string():
|
||||
return "dbname=SCO" + g.scodoc_dept
|
||||
def get_db_cnx_string(scodoc_dept=None):
|
||||
return "dbname=SCO" + (scodoc_dept or g.scodoc_dept)
|
||||
|
||||
|
||||
def ScoURL():
|
||||
|
@ -20,12 +20,14 @@
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if current_user.is_authenticated %}
|
||||
<form action="table_etud_in_accessible_depts" method="POST">
|
||||
<b>Chercher étudiant:</b>
|
||||
<input type="text" name="expnom" width="12" spellcheck="false" value="">
|
||||
<input type="submit" value="Chercher">
|
||||
<br />(entrer une partie du nom ou le code NIP, cherche dans tous les départements autorisés)
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
<div style="margin-top: 1cm; font-size: 120%;">
|
||||
<p><a href="/ScoDoc/static/mobile">Version mobile (expérimentale, à vos risques et périls)</a></p>
|
||||
|
@ -32,11 +32,14 @@ Emmanuel Viennet, 2021
|
||||
"""
|
||||
import flask
|
||||
from flask import render_template
|
||||
from flask import request
|
||||
from flask_login.utils import login_required
|
||||
|
||||
from scodoc_manager import sco_mgr
|
||||
|
||||
from app.views import scodoc_bp as bp
|
||||
from app.scodoc import VERSION
|
||||
from app.scodoc import sco_find_etud
|
||||
from app.scodoc.sco_permissions import Permission
|
||||
|
||||
|
||||
@ -51,3 +54,10 @@ def index():
|
||||
dept_ids=dept_ids,
|
||||
Permission=Permission,
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/ScoDoc/table_etud_in_accessible_depts", methods=["POST"])
|
||||
@login_required
|
||||
def table_etud_in_accessible_depts():
|
||||
"""recherche étudiants sur plusieurs départements"""
|
||||
return sco_find_etud.table_etud_in_accessible_depts(expnom=request.form["expnom"])
|
||||
|
Loading…
Reference in New Issue
Block a user