forked from ScoDoc/ScoDoc
API: group_set_edt_id. +cosmetic
This commit is contained in:
parent
a49437fa47
commit
a1e689d105
@ -394,6 +394,32 @@ def group_edit(group_id: int):
|
|||||||
return group.to_dict(with_partition=True)
|
return group.to_dict(with_partition=True)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/group/<int:group_id>/set_edt_id/<string:edt_id>", methods=["POST"])
|
||||||
|
@api_web_bp.route("/group/<int:group_id>/set_edt_id/<string:edt_id>", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
@scodoc
|
||||||
|
@permission_required(Permission.ScoView)
|
||||||
|
@as_json
|
||||||
|
def group_set_edt_id(group_id: int, edt_id: str):
|
||||||
|
"""Set edt_id for this group.
|
||||||
|
Contrairement à /edit, peut-être changé pour toute partition
|
||||||
|
ou formsemestre non verrouillé.
|
||||||
|
"""
|
||||||
|
query = GroupDescr.query.filter_by(id=group_id)
|
||||||
|
if g.scodoc_dept:
|
||||||
|
query = (
|
||||||
|
query.join(Partition).join(FormSemestre).filter_by(dept_id=g.scodoc_dept_id)
|
||||||
|
)
|
||||||
|
group: GroupDescr = query.first_or_404()
|
||||||
|
if not group.partition.formsemestre.can_change_groups():
|
||||||
|
return json_error(401, "opération non autorisée")
|
||||||
|
log(f"group_set_edt_id( {group_id}, '{edt_id}' )")
|
||||||
|
group.edt_id = edt_id
|
||||||
|
db.session.add(group)
|
||||||
|
db.session.commit()
|
||||||
|
return group.to_dict(with_partition=True)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/formsemestre/<int:formsemestre_id>/partition/create", methods=["POST"])
|
@bp.route("/formsemestre/<int:formsemestre_id>/partition/create", methods=["POST"])
|
||||||
@api_web_bp.route(
|
@api_web_bp.route(
|
||||||
"/formsemestre/<int:formsemestre_id>/partition/create", methods=["POST"]
|
"/formsemestre/<int:formsemestre_id>/partition/create", methods=["POST"]
|
||||||
@ -494,6 +520,7 @@ def formsemestre_order_partitions(formsemestre_id: int):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
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)
|
||||||
|
log(f"formsemestre_order_partitions({partition_ids})")
|
||||||
return [
|
return [
|
||||||
partition.to_dict()
|
partition.to_dict()
|
||||||
for partition in formsemestre.partitions.order_by(Partition.numero)
|
for partition in formsemestre.partitions.order_by(Partition.numero)
|
||||||
|
@ -242,10 +242,12 @@ class GroupDescr(ScoDocModel):
|
|||||||
|
|
||||||
def to_dict(self, with_partition=True) -> dict:
|
def to_dict(self, with_partition=True) -> dict:
|
||||||
"""as a dict, with or without partition"""
|
"""as a dict, with or without partition"""
|
||||||
|
if with_partition:
|
||||||
|
partition_dict = self.partition.to_dict(with_groups=False)
|
||||||
d = dict(self.__dict__)
|
d = dict(self.__dict__)
|
||||||
d.pop("_sa_instance_state", None)
|
d.pop("_sa_instance_state", None)
|
||||||
if with_partition:
|
if with_partition:
|
||||||
d["partition"] = self.partition.to_dict(with_groups=False)
|
d["partition"] = partition_dict
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def get_edt_ids(self) -> list[str]:
|
def get_edt_ids(self) -> list[str]:
|
||||||
|
@ -633,3 +633,7 @@ h3 {
|
|||||||
#zoneGroupes .groupe[data-idgroupe=aucun]>div:nth-child(1) {
|
#zoneGroupes .groupe[data-idgroupe=aucun]>div:nth-child(1) {
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#zonePartitions button span.editing:not(:first-child) {
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
@ -815,7 +815,7 @@
|
|||||||
fetch(url, { method: "POST" })
|
fetch(url, { method: "POST" })
|
||||||
.then(r => { return r.json() })
|
.then(r => { return r.json() })
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (r.OK != true) {
|
if (r.id != idGroupe) {
|
||||||
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données (5).</h2>";
|
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données (5).</h2>";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -870,7 +870,7 @@
|
|||||||
.then(r => { return r.json() })
|
.then(r => { return r.json() })
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (r.OK != true) {
|
if (r.OK != true) {
|
||||||
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données (5).</h2>";
|
document.querySelector("main").innerHTML = "<h2>Une erreur s'est produite lors de la sauvegarde des données (6).</h2>";
|
||||||
}
|
}
|
||||||
listeGroupesAutoaffectation();
|
listeGroupesAutoaffectation();
|
||||||
})
|
})
|
||||||
|
@ -391,11 +391,11 @@ def ics_raw_sample(edt_id: str):
|
|||||||
try:
|
try:
|
||||||
ics = raw_ics.decode(scu.SCO_ENCODING)
|
ics = raw_ics.decode(scu.SCO_ENCODING)
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
log(f"ics_raw_sample: raw_ics.decode failed")
|
log("ics_raw_sample: raw_ics.decode failed")
|
||||||
return f"Erreur lors de la conversion vers {scu.SCO_ENCODING}"
|
return f"Erreur lors de la conversion vers {scu.SCO_ENCODING}"
|
||||||
evs = ics.split("BEGIN:VEVENT")
|
evs = ics.split("BEGIN:VEVENT")
|
||||||
if len(evs) < 1:
|
if len(evs) < 1:
|
||||||
log(f"ics_raw_sample: empty calendar")
|
log("ics_raw_sample: empty calendar")
|
||||||
return "pas d'évènements VEVENT détectés dans ce fichier"
|
return "pas d'évènements VEVENT détectés dans ce fichier"
|
||||||
return "BEGIN:VEVENT" + evs[len(evs) // 2]
|
return "BEGIN:VEVENT" + evs[len(evs) // 2]
|
||||||
|
|
||||||
|
@ -120,6 +120,14 @@ def test_formsemestre_partition(api_headers):
|
|||||||
assert group["group_name"] == group_d["group_name"]
|
assert group["group_name"] == group_d["group_name"]
|
||||||
assert group["edt_id"] == "GEDT2"
|
assert group["edt_id"] == "GEDT2"
|
||||||
|
|
||||||
|
# Change edt_id via route dédiée:
|
||||||
|
group_t = POST_JSON(
|
||||||
|
f"/group/{group_r['id']}/set_edt_id/GEDT3",
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
assert group_t["id"] == group_r["id"]
|
||||||
|
assert group_t["edt_id"] == "GEDT3"
|
||||||
|
|
||||||
# Place un étudiant dans le groupe
|
# Place un étudiant dans le groupe
|
||||||
etud = GET(f"/formsemestre/{formsemestre_id}/etudiants", headers=headers)[0]
|
etud = GET(f"/formsemestre/{formsemestre_id}/etudiants", headers=headers)[0]
|
||||||
repl = POST_JSON(f"/group/{group['id']}/set_etudiant/{etud['id']}", headers=headers)
|
repl = POST_JSON(f"/group/{group['id']}/set_etudiant/{etud['id']}", headers=headers)
|
||||||
|
Loading…
Reference in New Issue
Block a user