Edition partition parcours. Closes #435.

This commit is contained in:
Emmanuel Viennet 2022-08-03 21:42:53 +02:00
parent 54bf4a4f0f
commit 251949c220
5 changed files with 45 additions and 32 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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,36 +998,36 @@ def edit_partition_form(formsemestre_id=None):
for p in partitions:
if p["partition_name"] is not None:
H.append(
'<tr><td class="epnav"><a class="stdlink" href="partition_delete?partition_id=%s">%s</a>&nbsp;</td><td class="epnav">'
% (p["partition_id"], suppricon)
f"""<tr><td class="epnav"><a class="stdlink"
href="{url_for("scolar.partition_delete",
scodoc_dept=g.scodoc_dept, partition_id=p["partition_id"])
}">{suppricon}</a>&nbsp;</td><td class="epnav">"""
)
if i != 0:
H.append(
'<a href="partition_move?partition_id=%s&after=0">%s</a>'
% (p["partition_id"], arrow_up)
f"""<a href="{url_for("scolar.partition_move",
scodoc_dept=g.scodoc_dept, partition_id=p["partition_id"], after=0)
}">{arrow_up}</a>"""
)
H.append('</td><td class="epnav">')
if i < len(partitions) - 2:
H.append(
'<a href="partition_move?partition_id=%s&after=1">%s</a>'
% (p["partition_id"], arrow_down)
f"""<a href="{url_for("scolar.partition_move",
scodoc_dept=g.scodoc_dept, partition_id=p["partition_id"], after=1)
}">{arrow_down}</a>"""
)
i += 1
H.append("</td>")
pname = p["partition_name"] or ""
H.append("<td>%s</td>" % pname)
H.append("<td>")
lg = [
"%s (%d)"
% (
group["group_name"],
len(get_group_members(group["group_id"])),
H.append(
f"""</td>
<td>{p["partition_name"] or ""}</td>
<td>"""
)
lg = [
f"""{group["group_name"]} ({len(get_group_members(group["group_id"]))})"""
for group in get_partition_groups(p)
]
H.append(", ".join(lg))
H.append("""</td><td>""")
if p["groups_editable"]:
H.append(
f"""<a class="stdlink" href="{
url_for("scolar.affect_groups",
@ -1036,13 +1036,16 @@ def edit_partition_form(formsemestre_id=None):
}">répartir</a></td>
"""
)
else:
H.append("""non éditable""")
H.append("""</td>""")
if p["groups_editable"]:
H.append(
'<td><a class="stdlink" href="partition_rename?partition_id=%s">renommer</a></td>'
% p["partition_id"]
f"""<td><a class="stdlink" href="{
url_for("scolar.partition_rename",
scodoc_dept=g.scodoc_dept, partition_id=p["partition_id"])
}">renommer</a></td>"""
)
else:
H.append("""<td>non éditable</td>""")
# classement:
H.append('<td width="250px">')
if p["bul_show_rank"]:

View File

@ -16,8 +16,10 @@ href="{{ url_for('scolar.groups_auto_repartition', scodoc_dept=g.scodoc_dept, pa
<div id="savedinfo"></div>
<form name="formGroup" id="formGroup" onSubmit="return false;">
<input type="hidden" name="partition_id" value="{{ partition.id }}"/>
{% if partition.groups_editable %}
<input name="groupName" size="6"/>
<input type="button" onClick="createGroup();" value="Créer groupe"/>
{% endif %}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" onClick="submitGroups( target='gmsg' );" value="Enregistrer ces groupes" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;