forked from ScoDoc/DocScoDoc
API: group/partition: log + 1 bug
This commit is contained in:
parent
48990f5012
commit
312d0c1917
@ -10,7 +10,7 @@
|
|||||||
from flask import abort, jsonify, request
|
from flask import abort, jsonify, request
|
||||||
|
|
||||||
import app
|
import app
|
||||||
from app import db
|
from app import db, log
|
||||||
from app.api import bp
|
from app.api import bp
|
||||||
from app.api.auth import token_auth, token_permission_required
|
from app.api.auth import token_auth, token_permission_required
|
||||||
from app.models import FormSemestre, FormSemestreInscription, Identite
|
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)
|
group = GroupDescr(group_name=group_name, partition_id=partition_id)
|
||||||
db.session.add(group)
|
db.session.add(group)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
log(f"created group {group}")
|
||||||
app.set_sco_dept(partition.formsemestre.departement.acronym)
|
app.set_sco_dept(partition.formsemestre.departement.acronym)
|
||||||
sco_cache.invalidate_formsemestre(partition.formsemestre_id)
|
sco_cache.invalidate_formsemestre(partition.formsemestre_id)
|
||||||
return jsonify(group.to_dict(with_partition=True))
|
return jsonify(group.to_dict(with_partition=True))
|
||||||
@ -174,6 +175,7 @@ def group_delete(group_id: int):
|
|||||||
if not group.partition.groups_editable:
|
if not group.partition.groups_editable:
|
||||||
abort(404, "partition non editable")
|
abort(404, "partition non editable")
|
||||||
formsemestre_id = group.partition.formsemestre_id
|
formsemestre_id = group.partition.formsemestre_id
|
||||||
|
log(f"deleting {group}")
|
||||||
db.session.delete(group)
|
db.session.delete(group)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
app.set_sco_dept(group.partition.formsemestre.departement.acronym)
|
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()
|
group.group_name = group_name.strip()
|
||||||
db.session.add(group)
|
db.session.add(group)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
log(f"modified {group}")
|
||||||
app.set_sco_dept(group.partition.formsemestre.departement.acronym)
|
app.set_sco_dept(group.partition.formsemestre.departement.acronym)
|
||||||
sco_cache.invalidate_formsemestre(group.partition.formsemestre_id)
|
sco_cache.invalidate_formsemestre(group.partition.formsemestre_id)
|
||||||
return jsonify(group.to_dict(with_partition=True))
|
return jsonify(group.to_dict(with_partition=True))
|
||||||
@ -236,13 +239,14 @@ def partition_create(formsemestre_id: int):
|
|||||||
value = data.get(
|
value = data.get(
|
||||||
boolean_field, False if boolean_field != "groups_editable" else True
|
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}")
|
abort(404, f"invalid type for {boolean_field}")
|
||||||
args[boolean_field] = value
|
args[boolean_field] = value
|
||||||
|
|
||||||
partition = Partition(**args)
|
partition = Partition(**args)
|
||||||
db.session.add(partition)
|
db.session.add(partition)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
log(f"created partition {partition}")
|
||||||
app.set_sco_dept(formsemestre.departement.acronym)
|
app.set_sco_dept(formsemestre.departement.acronym)
|
||||||
sco_cache.invalidate_formsemestre(formsemestre_id)
|
sco_cache.invalidate_formsemestre(formsemestre_id)
|
||||||
return jsonify(partition.to_dict(with_groups=True))
|
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"):
|
for boolean_field in ("bul_show_rank", "show_in_lists", "groups_editable"):
|
||||||
value = data.get(boolean_field)
|
value = data.get(boolean_field)
|
||||||
if value is not None and value != getattr(partition, 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}")
|
abort(404, f"invalid type for {boolean_field}")
|
||||||
setattr(partition, boolean_field, value)
|
setattr(partition, boolean_field, value)
|
||||||
modified = True
|
modified = True
|
||||||
@ -294,6 +298,7 @@ def partition_edit(partition_id: int):
|
|||||||
if modified:
|
if modified:
|
||||||
db.session.add(partition)
|
db.session.add(partition)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
log(f"modified partition {partition}")
|
||||||
app.set_sco_dept(partition.formsemestre.departement.acronym)
|
app.set_sco_dept(partition.formsemestre.departement.acronym)
|
||||||
sco_cache.invalidate_formsemestre(partition.formsemestre_id)
|
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")
|
abort(404, "ne peut pas supprimer la partition par défaut")
|
||||||
is_parcours = partition.is_parcours()
|
is_parcours = partition.is_parcours()
|
||||||
formsemestre: FormSemestre = partition.formsemestre
|
formsemestre: FormSemestre = partition.formsemestre
|
||||||
|
log(f"deleting partition {partition}")
|
||||||
db.session.delete(partition)
|
db.session.delete(partition)
|
||||||
|
db.session.commit()
|
||||||
app.set_sco_dept(partition.formsemestre.departement.acronym)
|
app.set_sco_dept(partition.formsemestre.departement.acronym)
|
||||||
sco_cache.invalidate_formsemestre(formsemestre.id)
|
sco_cache.invalidate_formsemestre(formsemestre.id)
|
||||||
if is_parcours:
|
if is_parcours:
|
||||||
|
@ -87,7 +87,7 @@ class Partition(db.Model):
|
|||||||
"""as a dict, with or without groups"""
|
"""as a dict, with or without groups"""
|
||||||
d = dict(self.__dict__)
|
d = dict(self.__dict__)
|
||||||
d.pop("_sa_instance_state", None)
|
d.pop("_sa_instance_state", None)
|
||||||
d.pop("formsemestre")
|
d.pop("formsemestre", None)
|
||||||
|
|
||||||
if with_groups:
|
if with_groups:
|
||||||
d["groups"] = [group.to_dict(with_partition=False) for group in self.groups]
|
d["groups"] = [group.to_dict(with_partition=False) for group in self.groups]
|
||||||
|
@ -155,7 +155,23 @@ POST(f"/group/{group_id}/set_etudiant/{etudid}")
|
|||||||
|
|
||||||
|
|
||||||
POST_JSON(f"/partition/{pid}/group/create", data={"group_name": "Omega10"})
|
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:
|
# # --- 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 !")
|
||||||
|
Loading…
Reference in New Issue
Block a user