From 251949c220173e519674cb511927d7c104c30be2 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Wed, 3 Aug 2022 21:42:53 +0200 Subject: [PATCH] Edition partition parcours. Closes #435. --- app/api/partitions.py | 7 +++ app/models/formsemestre.py | 1 + app/models/groups.py | 4 +- app/scodoc/sco_groups.py | 59 +++++++++++++------------ app/templates/scolar/affect_groups.html | 6 ++- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/app/api/partitions.py b/app/api/partitions.py index f46598b26..9af1fb303 100644 --- a/app/api/partitions.py +++ b/app/api/partitions.py @@ -359,6 +359,8 @@ def partition_create(formsemestre_id: int): partition_name = data.get("partition_name") if partition_name is None: return error_response(404, "missing partition_name or invalid data format") + if partition_name == scu.PARTITION_PARCOURS: + return error_response(404, f"invalid partition_name {scu.PARTITION_PARCOURS}") if not Partition.check_name(formsemestre, partition_name): return error_response(404, "invalid partition_name") numero = data.get("numero", 0) @@ -482,7 +484,10 @@ def partition_edit(partition_id: int): data = request.get_json(force=True) # may raise 400 Bad Request modified = False partition_name = data.get("partition_name") + # if partition_name is not None and partition_name != partition.partition_name: + if partition.is_parcours(): + return error_response(404, f"can't rename {scu.PARTITION_PARCOURS}") if not Partition.check_name( partition.formsemestre, partition_name, existing=True ): @@ -502,6 +507,8 @@ def partition_edit(partition_id: int): if value is not None and value != getattr(partition, boolean_field): if not isinstance(value, bool): return error_response(404, f"invalid type for {boolean_field}") + if boolean_field == "groups_editable" and partition.is_parcours(): + return error_response(404, f"can't change {scu.PARTITION_PARCOURS}") setattr(partition, boolean_field, value) modified = True diff --git a/app/models/formsemestre.py b/app/models/formsemestre.py index a5514200e..316811c4f 100644 --- a/app/models/formsemestre.py +++ b/app/models/formsemestre.py @@ -576,6 +576,7 @@ class FormSemestre(db.Model): formsemestre_id=self.id, partition_name=scu.PARTITION_PARCOURS, numero=-1, + groups_editable=False, ) db.session.add(partition) db.session.flush() # pour avoir un id diff --git a/app/models/groups.py b/app/models/groups.py index 8b890a6ac..1a5dc257d 100644 --- a/app/models/groups.py +++ b/app/models/groups.py @@ -38,7 +38,7 @@ class Partition(db.Model): show_in_lists = db.Column( db.Boolean(), nullable=False, default=True, server_default="true" ) - # Editable ? (faux pour les groupes de parcours) + # Editable (créer/renommer groupes) ? (faux pour les groupes de parcours) groups_editable = db.Column( db.Boolean(), nullable=False, default=True, server_default="true" ) @@ -80,7 +80,7 @@ class Partition(db.Model): return True def is_parcours(self) -> bool: - "Vrai s'il s'agit de la partitoon de parcours" + "Vrai s'il s'agit de la partition de parcours" return self.partition_name == scu.PARTITION_PARCOURS def to_dict(self, with_groups=False) -> dict: diff --git a/app/scodoc/sco_groups.py b/app/scodoc/sco_groups.py index 2a9b4dac2..1f759e2aa 100644 --- a/app/scodoc/sco_groups.py +++ b/app/scodoc/sco_groups.py @@ -760,7 +760,7 @@ def setGroups( return response partition = get_partition(partition_id) - if not partition["groups_editable"]: + if not partition["groups_editable"] and (groupsToCreate or groupsToDelete): msg = "setGroups: partition non editable" log(msg) return xml_error(msg, code=403) @@ -998,51 +998,54 @@ def edit_partition_form(formsemestre_id=None): for p in partitions: if p["partition_name"] is not None: H.append( - '%s ' - % (p["partition_id"], suppricon) + f"""{suppricon} """ ) if i != 0: H.append( - '%s' - % (p["partition_id"], arrow_up) + f"""{arrow_up}""" ) H.append('') if i < len(partitions) - 2: H.append( - '%s' - % (p["partition_id"], arrow_down) + f"""{arrow_down}""" ) i += 1 - H.append("") - pname = p["partition_name"] or "" - H.append("%s" % pname) - H.append("") + H.append( + f""" + {p["partition_name"] or ""} + """ + ) lg = [ - "%s (%d)" - % ( - group["group_name"], - len(get_group_members(group["group_id"])), - ) + f"""{group["group_name"]} ({len(get_group_members(group["group_id"]))})""" for group in get_partition_groups(p) ] H.append(", ".join(lg)) H.append("""""") + H.append( + f"""répartir + """ + ) + H.append("""""") if p["groups_editable"]: H.append( - f"""répartir - """ + f"""renommer""" ) else: - H.append("""non éditable""") - H.append("""""") - H.append( - 'renommer' - % p["partition_id"] - ) + H.append("""non éditable""") # classement: H.append('') if p["bul_show_rank"]: diff --git a/app/templates/scolar/affect_groups.html b/app/templates/scolar/affect_groups.html index 323a42e52..1f1dd908b 100644 --- a/app/templates/scolar/affect_groups.html +++ b/app/templates/scolar/affect_groups.html @@ -16,8 +16,10 @@ href="{{ url_for('scolar.groups_auto_repartition', scodoc_dept=g.scodoc_dept, pa
- - + {% if partition.groups_editable %} + + + {% endif %}