forked from ScoDoc/ScoDoc
add_fields ok
This commit is contained in:
parent
e4c9e5f9e8
commit
37303df74c
@ -75,6 +75,10 @@ SEQ = "Continue"
|
||||
TOUS = "Tous"
|
||||
|
||||
|
||||
def get_name(selfgroup, partition):
|
||||
return 'GR_{partition]_{groupe]'
|
||||
|
||||
|
||||
def _get_group_info(evaluation_id):
|
||||
# groupes
|
||||
groups = sco_groups.do_evaluation_listegroupes(evaluation_id, include_default=True)
|
||||
@ -86,7 +90,7 @@ def _get_group_info(evaluation_id):
|
||||
group_name = group["group_name"] or TOUS
|
||||
if partition not in groups_tree:
|
||||
groups_tree[partition] = {}
|
||||
name = "GR_%s_%s" % (partition, group_name)
|
||||
name = get_name(partition, group_name)
|
||||
groups_tree[partition][group_name] = {
|
||||
"id": group_id,
|
||||
"field": BooleanField(name),
|
||||
@ -132,32 +136,23 @@ class PlacementForm(FlaskForm):
|
||||
submit = SubmitField("OK")
|
||||
|
||||
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
|
||||
self._unbound_fields.append((name, field))
|
||||
|
||||
def __init__(self, groups_tree, formdata=None, data=None, **kwargs):
|
||||
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.add_dynamic(name, field)
|
||||
# create the form (including new dynamic fields) and proccess all fields
|
||||
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:
|
||||
@ -174,7 +169,7 @@ class PlacementForm(FlaskForm):
|
||||
self.has_groups = self.nb_partitions > 1
|
||||
|
||||
def get_checkbox(self, partition, groupe):
|
||||
return self.groups_tree[partition][groupe]["field"]
|
||||
return self._fields[get_name(partition, groupe)]
|
||||
|
||||
|
||||
class _DistributeurContinu:
|
||||
|
@ -27,8 +27,7 @@
|
||||
{{ render_field(form.nb_rangs) }}
|
||||
{{ render_field(form.etiquetage) }}
|
||||
{% if form.has_groups %}
|
||||
{{ render_field(form.groups) }}
|
||||
<!-- Tentative de recréer le choix des groupes sous forme de cases à cocher // demande à créer des champs wtf dynamiquement
|
||||
{# {{ render_field(form.groups) }}#}
|
||||
{% for partition in form.groups_tree %}
|
||||
<tr>
|
||||
{% if partition == 'Tous' %}
|
||||
@ -37,12 +36,11 @@
|
||||
<td>{{ partition }}</td>
|
||||
<td>
|
||||
{% for groupe in form.groups_tree[partition] %}
|
||||
{{ groupe }}{{ form[form.groups_tree[partition][groupe]] }}
|
||||
{{ groupe }}{{ form.get_checkbox(partition, groupe)() }}
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
-->
|
||||
{% endif %}
|
||||
{{ render_field(form.file_format) }}
|
||||
</tbody>
|
||||
@ -52,46 +50,6 @@
|
||||
<input id="gr_cancel" type=submit value="Annuler">
|
||||
</script>
|
||||
</form>
|
||||
<form method=post>
|
||||
{{ form.evaluation_id }}
|
||||
{{ form.csrf_token }}
|
||||
<table class="tf">
|
||||
<tbody>
|
||||
{{ render_field(form.surveillants) }}
|
||||
{{ render_field(form.batiment) }}
|
||||
{{ render_field(form.salle) }}
|
||||
{{ render_field(form.nb_rangs) }}
|
||||
{{ render_field(form.etiquetage) }}
|
||||
{% if form.has_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>#}
|
||||
{#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) }}
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<input id="gr_submit" type=submit value="Ok">
|
||||
<input id="gr_cancel" type=submit value="Annuler">
|
||||
</script>
|
||||
</form>
|
||||
<h3>Explications</h3>
|
||||
<ul>
|
||||
<li>préciser les surveillants et la localisation (bâtiment et salle) et indiquer la largeur de la salle (nombre
|
||||
|
Loading…
x
Reference in New Issue
Block a user