1
0
forked from ScoDoc/ScoDoc

WIP: API group/partition

This commit is contained in:
Emmanuel Viennet 2022-07-20 16:12:20 +02:00
parent b53958c777
commit 4cb2db61bc
2 changed files with 29 additions and 8 deletions

View File

@ -94,7 +94,7 @@ def etud_in_group(group_id: int):
@token_permission_required(Permission.APIView) @token_permission_required(Permission.APIView)
def etud_in_group_query(group_id: int): def etud_in_group_query(group_id: int):
"""Etudiants du groupe, filtrés par état""" """Etudiants du groupe, filtrés par état"""
etat = request.get("etat", "") etat = request.args.get("etat")
if etat not in {scu.INSCRIT, scu.DEMISSION, scu.DEF}: if etat not in {scu.INSCRIT, scu.DEMISSION, scu.DEF}:
abort(404, "etat invalid") abort(404, "etat invalid")
group = GroupDescr.query.get_or_404(group_id) group = GroupDescr.query.get_or_404(group_id)
@ -123,11 +123,11 @@ def set_etud_group(etudid: int, group_id: int):
.filter_by(etudid=etudid) .filter_by(etudid=etudid)
) )
ok = False ok = False
for group in groups: for g in groups:
if group.id == group_id: if g.id == group_id:
ok = True ok = True
else: else:
group.etuds.remove(etud) g.etuds.remove(etud)
if not ok: if not ok:
group.etuds.append(etud) group.etuds.append(etud)
db.session.commit() db.session.commit()

View File

@ -53,16 +53,18 @@ def GET(path: str, headers={}, errmsg=None):
"""Get and returns as JSON""" """Get and returns as JSON"""
r = requests.get(API_URL + "/" + path, headers=headers or HEADERS, verify=CHK_CERT) r = requests.get(API_URL + "/" + path, headers=headers or HEADERS, verify=CHK_CERT)
if r.status_code != 200: if r.status_code != 200:
raise ScoError(errmsg or "erreur !") raise ScoError(errmsg or f"erreur status={r.status_code} !")
return r.json() # decode la reponse JSON return r.json() # decode la reponse JSON
def POST(s, path: str, data: dict, errmsg=None): def POST(path: str, data: dict = {}, headers={}, errmsg=None):
"""Post""" """Post"""
r = s.post(API_URL + "/" + path, data=data, verify=CHK_CERT) r = requests.post(
API_URL + "/" + path, data=data, headers=headers or HEADERS, verify=CHK_CERT
)
if r.status_code != 200: if r.status_code != 200:
raise ScoError(errmsg or "erreur !") raise ScoError(errmsg or "erreur !")
return r.text return r.json() # decode la reponse JSON
# --- Obtention du jeton (token) # --- Obtention du jeton (token)
@ -113,6 +115,25 @@ print("\n".join([s["titre_num"] for s in sems]))
# Evaluation # Evaluation
evals = GET("/evaluations/1") evals = GET("/evaluations/1")
# Partitions d'un BUT
formsemestre_id = 1063 # A adapter
partitions = GET(f"/formsemestre/{formsemestre_id}/partitions")
print(partitions)
pid = partitions[1]["id"]
partition = GET(f"/partition/{pid}")
print(partition)
group_id = partition["groups"][0]["id"]
etuds = GET(f"/group/{group_id}/etudiants")
print(f"{len(etuds)} étudiants")
pp(etuds[1])
etuds_dem = GET(f"/group/{group_id}/etudiants/query?etat=D")
print(f"{len(etuds_dem)} étudiants")
etudid = 16650
group_id = 5315
POST(f"/group/{group_id}/set_etudiant/{etudid}")
# # --- Recupere la liste de tous les semestres: # # --- Recupere la liste de tous les semestres:
# sems = GET(s, "Notes/formsemestre_list?format=json", "Aucun semestre !") # sems = GET(s, "Notes/formsemestre_list?format=json", "Aucun semestre !")