1
0
forked from ScoDoc/ScoDoc

API: group/partition: log + 1 bug

This commit is contained in:
Emmanuel Viennet 2022-07-20 22:33:41 +02:00
parent 48990f5012
commit 312d0c1917
3 changed files with 27 additions and 4 deletions

View File

@ -10,7 +10,7 @@
from flask import abort, jsonify, request
import app
from app import db
from app import db, log
from app.api import bp
from app.api.auth import token_auth, token_permission_required
from app.models import FormSemestre, FormSemestreInscription, Identite
@ -160,6 +160,7 @@ def group_create(partition_id: int):
group = GroupDescr(group_name=group_name, partition_id=partition_id)
db.session.add(group)
db.session.commit()
log(f"created group {group}")
app.set_sco_dept(partition.formsemestre.departement.acronym)
sco_cache.invalidate_formsemestre(partition.formsemestre_id)
return jsonify(group.to_dict(with_partition=True))
@ -174,6 +175,7 @@ def group_delete(group_id: int):
if not group.partition.groups_editable:
abort(404, "partition non editable")
formsemestre_id = group.partition.formsemestre_id
log(f"deleting {group}")
db.session.delete(group)
db.session.commit()
app.set_sco_dept(group.partition.formsemestre.departement.acronym)
@ -197,6 +199,7 @@ def group_edit(group_id: int):
group.group_name = group_name.strip()
db.session.add(group)
db.session.commit()
log(f"modified {group}")
app.set_sco_dept(group.partition.formsemestre.departement.acronym)
sco_cache.invalidate_formsemestre(group.partition.formsemestre_id)
return jsonify(group.to_dict(with_partition=True))
@ -236,13 +239,14 @@ def partition_create(formsemestre_id: int):
value = data.get(
boolean_field, False if boolean_field != "groups_editable" else True
)
if not isinstance(boolean_field, bool):
if not isinstance(value, bool):
abort(404, f"invalid type for {boolean_field}")
args[boolean_field] = value
partition = Partition(**args)
db.session.add(partition)
db.session.commit()
log(f"created partition {partition}")
app.set_sco_dept(formsemestre.departement.acronym)
sco_cache.invalidate_formsemestre(formsemestre_id)
return jsonify(partition.to_dict(with_groups=True))
@ -286,7 +290,7 @@ def partition_edit(partition_id: int):
for boolean_field in ("bul_show_rank", "show_in_lists", "groups_editable"):
value = data.get(boolean_field)
if value is not None and value != getattr(partition, boolean_field):
if not isinstance(boolean_field, bool):
if not isinstance(value, bool):
abort(404, f"invalid type for {boolean_field}")
setattr(partition, boolean_field, value)
modified = True
@ -294,6 +298,7 @@ def partition_edit(partition_id: int):
if modified:
db.session.add(partition)
db.session.commit()
log(f"modified partition {partition}")
app.set_sco_dept(partition.formsemestre.departement.acronym)
sco_cache.invalidate_formsemestre(partition.formsemestre_id)
@ -316,7 +321,9 @@ def partition_delete(partition_id: int):
abort(404, "ne peut pas supprimer la partition par défaut")
is_parcours = partition.is_parcours()
formsemestre: FormSemestre = partition.formsemestre
log(f"deleting partition {partition}")
db.session.delete(partition)
db.session.commit()
app.set_sco_dept(partition.formsemestre.departement.acronym)
sco_cache.invalidate_formsemestre(formsemestre.id)
if is_parcours:

View File

@ -87,7 +87,7 @@ class Partition(db.Model):
"""as a dict, with or without groups"""
d = dict(self.__dict__)
d.pop("_sa_instance_state", None)
d.pop("formsemestre")
d.pop("formsemestre", None)
if with_groups:
d["groups"] = [group.to_dict(with_partition=False) for group in self.groups]

View File

@ -155,7 +155,23 @@ POST(f"/group/{group_id}/set_etudiant/{etudid}")
POST_JSON(f"/partition/{pid}/group/create", data={"group_name": "Omega10"})
partitions = GET(f"/formsemestre/{formsemestre_id}/partitions")
pp(partitions)
POST_JSON(f"/group/5559/delete")
POST_JSON(f"/group/5327/edit", data={"group_name": "TDXXX"})
POST_JSON(
f"/formsemestre/{formsemestre_id}/partition/create",
data={"partition_name": "PXXXXYY"},
)
POST_JSON(
f"/partition/{2379}/edit",
data={"partition_name": "---PPPP", "show_in_lists": True},
)
POST_JSON(f"/partition/{2379}/delete")
# # --- Recupere la liste de tous les semestres:
# sems = GET(s, "Notes/formsemestre_list?format=json", "Aucun semestre !")