forked from ScoDoc/ScoDoc
test ajout cb
This commit is contained in:
parent
b552588c1c
commit
b05aea95b6
@ -46,7 +46,8 @@ from wtforms import (
|
||||
RadioField,
|
||||
HiddenField,
|
||||
SelectMultipleField,
|
||||
BooleanField, FormField,
|
||||
BooleanField,
|
||||
FormField,
|
||||
)
|
||||
from wtforms.form import BaseForm
|
||||
|
||||
@ -87,7 +88,7 @@ def _get_group_info(evaluation_id):
|
||||
group_name = group["group_name"] or TOUS
|
||||
if partition not in groups_tree:
|
||||
groups_tree[partition] = {}
|
||||
name = "G_%s_%s" % (partition, group_name)
|
||||
name = "GR_%s_%s" % (partition, group_name)
|
||||
groups_tree[partition][group_name] = {
|
||||
"id": group_id,
|
||||
"field": BooleanField(name),
|
||||
@ -96,21 +97,9 @@ def _get_group_info(evaluation_id):
|
||||
return groups_tree
|
||||
|
||||
|
||||
def form_from(groups_tree):
|
||||
def create_form(prefix='', **kwargs):
|
||||
fields = [(groups_tree[partition][groupe]['name'], groups_tree[partition][groupe]['field'])
|
||||
for partition in groups_tree
|
||||
for groupe in groups_tree[partition]
|
||||
]
|
||||
form_enclosed = BaseForm(fields, prefix=prefix, meta=FlaskForm.Meta)
|
||||
form_enclosed.process(**kwargs)
|
||||
return form_enclosed
|
||||
|
||||
return create_form
|
||||
|
||||
|
||||
class PlacementForm(FlaskForm):
|
||||
"""Formulaire pour placement des étudiants en Salle"""
|
||||
|
||||
evaluation_id = HiddenField("evaluation_id")
|
||||
file_format = RadioField(
|
||||
"Format de fichier",
|
||||
@ -132,34 +121,64 @@ class PlacementForm(FlaskForm):
|
||||
wtforms.validators.DataRequired("indiquez le style de numérotation"),
|
||||
],
|
||||
)
|
||||
groups = SelectMultipleField(
|
||||
"Groupe(s)",
|
||||
validators=[
|
||||
wtforms.validators.DataRequired("indiquez au moins un groupe"),
|
||||
],
|
||||
)
|
||||
cb_groups = FormField("cb_groups")
|
||||
# groups = SelectMultipleField(
|
||||
# "Groupe(s)",
|
||||
# validators=[
|
||||
# wtforms.validators.DataRequired("indiquez au moins un groupe"),
|
||||
# ],
|
||||
# )
|
||||
submit = SubmitField("OK")
|
||||
dynamic_fields = {}
|
||||
|
||||
def __init__(self, groups_tree, formdata=None, data=None):
|
||||
super().__init__(formdata=formdata, data=data)
|
||||
self.groups_tree = groups_tree
|
||||
self.nb_partitions = len(self.groups_tree)
|
||||
self.has_groups = self.nb_partitions > 1
|
||||
self.set_evaluation_infos(data["evaluation_id"])
|
||||
def clear_dynamics(self):
|
||||
if self.dynamic_fields:
|
||||
for field_name in self.dynamic_fields:
|
||||
del self._fields[field_name]
|
||||
|
||||
def set_evaluation_infos(self, evaluation_id):
|
||||
def add_dynamic(self, name, field):
|
||||
breakpoint()
|
||||
bind_field = self._fields[name] = self.meta.bind_field(
|
||||
form=self, unbound_field=field, options={"name": name, "prefix": self._prefix}
|
||||
)
|
||||
self.__setattr__(name, bind_field)
|
||||
breakpoint()
|
||||
self.dynamic_fields[name] = field
|
||||
|
||||
def get_dynamic(self, name):
|
||||
return self.dynamic_fields[name]
|
||||
|
||||
def __init__(self, groups_tree, formdata=None, data=None, **kwargs):
|
||||
super().__init__(formdata=formdata, data=data, **kwargs)
|
||||
# first remove previous dynamic fields that might have been created for this form
|
||||
self.clear_dynamics()
|
||||
self.add_dynamic("test_cb", BooleanField("test_cb"))
|
||||
# compute the values for new dynamic fields
|
||||
evaluation_id = data["evaluation_id"]
|
||||
# self.groups_tree = groups_tree
|
||||
# self.nb_groups = sum([len(x) for x in groups_tree.values()])
|
||||
# self.has_groups = self.nb_groups > 1
|
||||
# add dynamic fields to Class
|
||||
# for partition in groups_tree:
|
||||
# for groupe in groups_tree[partition]:
|
||||
# name = self.groups_tree[partition][groupe].name
|
||||
# field = self.groups_tree[partition][groupe].field
|
||||
# self.dynamic_fields.add(name)
|
||||
# self._fields[name] = field
|
||||
# create the form (including new dynamic fields) and proccess all fields
|
||||
"""Initialise les données du formulaire avec les données de l'évaluation."""
|
||||
eval_data = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id})
|
||||
if not eval_data:
|
||||
raise ScoValueError("invalid evaluation_id")
|
||||
if self.has_groups:
|
||||
choices = []
|
||||
for partition in self.groups_tree:
|
||||
for groupe in self.groups_tree[partition]:
|
||||
groupe_id = str(self.groups_tree[partition][groupe])
|
||||
choices.append((groupe_id, "%s (%s)" % (str(groupe), partition)))
|
||||
self.groups.choices = choices
|
||||
# if self.has_groups:
|
||||
# choices = []
|
||||
# for partition in self.groups_tree:
|
||||
# for groupe in self.groups_tree[partition]:
|
||||
# groupe_id = str(self.groups_tree[partition][groupe])
|
||||
# choices.append((groupe_id, "%s (%s)" % (str(groupe), partition)))
|
||||
# self.groups.choices = choices
|
||||
self.groups_tree = groups_tree
|
||||
self.nb_partitions = len(self.groups_tree)
|
||||
self.has_groups = self.nb_partitions > 1
|
||||
|
||||
def get_checkbox(self, partition, groupe):
|
||||
return self.groups_tree[partition][groupe]["field"]
|
||||
@ -199,8 +218,6 @@ class _Distributeur2D:
|
||||
def placement_eval_selectetuds(evaluation_id):
|
||||
"""Creation de l'écran de placement"""
|
||||
groups_tree = _get_group_info(evaluation_id)
|
||||
breakpoint()
|
||||
PlacementForm.cb_groups = form_from(groups_tree)
|
||||
form = PlacementForm(
|
||||
groups_tree,
|
||||
request.form,
|
||||
@ -210,12 +227,12 @@ def placement_eval_selectetuds(evaluation_id):
|
||||
runner = PlacementRunner(form)
|
||||
if not runner.check_placement():
|
||||
return (
|
||||
"""<h2>Génération du placement impossible pour %s</h2>
|
||||
"""<h2>Génération du placement impossible pour %s</h2>
|
||||
<p>(vérifiez que le semestre n'est pas verrouillé et que vous
|
||||
avez l'autorisation d'effectuer cette opération)</p>
|
||||
<p><a href="moduleimpl_status?moduleimpl_id=%s">Continuer</a></p>
|
||||
"""
|
||||
% runner.__dict__
|
||||
% runner.__dict__
|
||||
)
|
||||
return runner.exec_placement() # calcul et generation du fichier
|
||||
# return flask.redirect(url_for("scodoc.index"))
|
||||
@ -349,8 +366,8 @@ class PlacementRunner:
|
||||
def _production_pdf(self):
|
||||
pdf_title = "<br/>".join(self.desceval)
|
||||
pdf_title += (
|
||||
"\nDate : %(jour)s - Horaire : %(heure_debut)s à %(heure_fin)s"
|
||||
% self.eval_data
|
||||
"\nDate : %(jour)s - Horaire : %(heure_debut)s à %(heure_fin)s"
|
||||
% self.eval_data
|
||||
)
|
||||
filename = "placement_%(evalname)s_%(gr_title_filename)s" % self.__dict__
|
||||
titles = {
|
||||
@ -384,8 +401,8 @@ class PlacementRunner:
|
||||
rows=rows,
|
||||
filename=filename,
|
||||
origin="Généré par %s le " % sco_version.SCONAME
|
||||
+ scu.timedate_human_repr()
|
||||
+ "",
|
||||
+ scu.timedate_human_repr()
|
||||
+ "",
|
||||
pdf_title=pdf_title,
|
||||
# pdf_shorttitle = '',
|
||||
preferences=sco_preferences.SemPreferences(
|
||||
@ -618,7 +635,7 @@ class PlacementRunner:
|
||||
maxlines = sem_preferences.get("feuille_placement_positions")
|
||||
nb_rangs = int(self.nb_rangs)
|
||||
column_width_ratio = (
|
||||
1 / 250
|
||||
1 / 250
|
||||
) # changement d unités entre pyExcelerator et openpyxl
|
||||
|
||||
workbook = ScoExcelBook()
|
||||
@ -633,7 +650,7 @@ class PlacementRunner:
|
||||
ws0.set_column_dimension_width("A", 750 * column_width_ratio)
|
||||
for col in range(nb_rangs):
|
||||
ws0.set_column_dimension_width(
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[col + 1: col + 2], width
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[col + 1 : col + 2], width
|
||||
)
|
||||
|
||||
sheet_name_1 = "Positions"
|
||||
|
@ -27,24 +27,25 @@
|
||||
{{ render_field(form.nb_rangs) }}
|
||||
{{ render_field(form.etiquetage) }}
|
||||
{% if form.has_groups %}
|
||||
{{ render_field(form.groups) }}
|
||||
{# {{ render_field(form.groups) }}#}
|
||||
{{ form.get_dynamic("test_cb") }}
|
||||
{# Tentative de recréer le choix des groupes sous forme de cases à cocher // demande à créer des champs wtf dynamiquement #}
|
||||
<tr><th>Groupes</th>
|
||||
<td><table><tbody>
|
||||
{% for partition in form.groups_tree %}
|
||||
<tr>
|
||||
{# {% if partition == 'Tous' %}#}
|
||||
{# <td colspan="{{ form.nb_max_groups }}">Tous</td>#}
|
||||
{# {% else %}#}
|
||||
<th>{{ partition }}</th>
|
||||
{% for groupe in form.groups_tree[partition] %}
|
||||
<td>{{ groupe }}{{ form.get_checkbox(partition, groupe)()|safe() }}</td>
|
||||
{% endfor %}
|
||||
{# {% endif %}#}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody></table></td>
|
||||
</tr>
|
||||
{# <tr><th>Groupes</th>#}
|
||||
{# <td><table><tbody>#}
|
||||
{# {% for partition in form.groups_tree %}#}
|
||||
{# <tr>#}
|
||||
{#1 {% if partition == 'Tous' %}#}
|
||||
{#1 <td colspan="{{ form.nb_max_groups }}">Tous</td>#}
|
||||
{#1 {% else %}#}
|
||||
{# <th>{{ partition }}</th>#}
|
||||
{# {% for groupe in form.groups_tree[partition] %}#}
|
||||
{# <td>{{ groupe }}{{ form.get_checkbox(partition, groupe)()|safe() }}</td>#}
|
||||
{# {% endfor %}#}
|
||||
{#1 {% endif %}#}
|
||||
{# </tr>#}
|
||||
{# {% endfor %}#}
|
||||
{# </tbody></table></td>#}
|
||||
{# </tr>#}
|
||||
{# Fin tentative #}
|
||||
{% endif %}
|
||||
{{ render_field(form.file_format) }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user