From a5ed9b815faeae04ee4454c19a3ac4799b202d07 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sun, 19 Sep 2021 08:21:08 +0200 Subject: [PATCH] fix plantage si un seul groupe ; correction indentation for radio button in wtf_forms (css) --- app/scodoc/sco_placement.py | 34 +++++++++++++++++++++++----------- app/static/css/scodoc.css | 2 ++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/scodoc/sco_placement.py b/app/scodoc/sco_placement.py index ab9777b44..b304558e2 100644 --- a/app/scodoc/sco_placement.py +++ b/app/scodoc/sco_placement.py @@ -89,6 +89,9 @@ def _get_group_info(evaluation_id): if partition != TOUS: has_groups = True nb_groups = len(groups_tree) + else: + has_groups = False + nb_groups = 1 return groups_tree, has_groups, nb_groups @@ -121,9 +124,7 @@ class PlacementForm(FlaskForm): ) groups = SelectMultipleField( "Groupe(s)", - validators=[ - wtforms.validators.DataRequired("indiquez au moins un groupe"), - ], + validators=[], ) submit = SubmitField("OK") @@ -131,8 +132,8 @@ class PlacementForm(FlaskForm): super().__init__(formdata=formdata, data=data) self.groups_tree = {} self.has_groups = None - self.group_tree_length = None self.nb_groups = None + self.tous_id = None self.set_evaluation_infos(data["evaluation_id"]) def set_evaluation_infos(self, evaluation_id): @@ -143,13 +144,20 @@ class PlacementForm(FlaskForm): self.groups_tree, self.has_groups, self.nb_groups = _get_group_info( evaluation_id ) - if self.has_groups: - choices = [] - for partition in self.groups_tree: - for groupe in self.groups_tree[partition]: + choices = [] + for partition in self.groups_tree: + for groupe in self.groups_tree[partition]: + if ( + groupe == TOUS + ): # Affichage et valeur spécifique pour le groupe TOUS + self.tous_id = str(self.groups_tree[partition][groupe]) + choices.append((TOUS, TOUS)) + else: groupe_id = str(self.groups_tree[partition][groupe]) choices.append((groupe_id, "%s (%s)" % (str(groupe), partition))) - self.groups.choices = choices + self.groups.choices = choices + # self.groups.default = [TOUS] # Ne fonctionnne pas... (ni dans la déclaration de PlaceForm.groups) + # la réponse [] est de toute façon transposée en [ self.tous_id ] lors du traitement (cas du groupe unique) class _DistributeurContinu: @@ -201,7 +209,6 @@ def placement_eval_selectetuds(evaluation_id): % runner.__dict__ ) return runner.exec_placement() # calcul et generation du fichier - # return flask.redirect(url_for("scodoc.index")) htmls = [ html_sco_header.sco_header(init_jquery_ui=True), sco_evaluations.evaluation_describe(evaluation_id=evaluation_id), @@ -224,7 +231,12 @@ class PlacementRunner: self.salle = form["salle"].data self.nb_rangs = form["nb_rangs"].data self.file_format = form["file_format"].data - self.groups_ids = form["groups"].data + if len(form["groups"].data) == 0: + self.groups_ids = [form.tous_id] + else: # On remplace le mot-clé TOUS le l'identiant de ce groupe + self.groups_ids = [ + gid if gid != TOUS else form.tous_id for gid in form["groups"].data + ] self.eval_data = sco_evaluations.do_evaluation_list( {"evaluation_id": self.evaluation_id} )[0] diff --git a/app/static/css/scodoc.css b/app/static/css/scodoc.css index a537bb96f..82ada0fe7 100644 --- a/app/static/css/scodoc.css +++ b/app/static/css/scodoc.css @@ -1094,6 +1094,8 @@ h2.formsemestre, .gtrcontent h2 { } .wtf-field li { display: inline; +}.wtf-field ul { + padding-left: 0; } .wtf-field .errors { color: red ; font-weight: bold;