forked from ScoDoc/ScoDoc
template + accessors
This commit is contained in:
parent
2a72fb881b
commit
ae1feba96c
@ -85,11 +85,13 @@ def _get_group_info(evaluation_id):
|
|||||||
group_name = group["group_name"] or TOUS
|
group_name = group["group_name"] or TOUS
|
||||||
if partition not in groups_tree:
|
if partition not in groups_tree:
|
||||||
groups_tree[partition] = {}
|
groups_tree[partition] = {}
|
||||||
groups_tree[partition][group_name] = group_id
|
name = "G_%s_%s" % (partition, group_name)
|
||||||
if partition != TOUS:
|
groups_tree[partition][group_name] = {
|
||||||
has_groups = True
|
"id": group_id,
|
||||||
nb_groups = len(groups_tree)
|
"field": BooleanField(name),
|
||||||
return groups_tree, has_groups, nb_groups
|
"name": name,
|
||||||
|
}
|
||||||
|
return groups_tree
|
||||||
|
|
||||||
|
|
||||||
class PlacementForm(FlaskForm):
|
class PlacementForm(FlaskForm):
|
||||||
@ -124,12 +126,14 @@ class PlacementForm(FlaskForm):
|
|||||||
)
|
)
|
||||||
submit = SubmitField("OK")
|
submit = SubmitField("OK")
|
||||||
|
|
||||||
def __init__(self, formdata=None, data=None):
|
def __init__(self, groups_tree, formdata=None, data=None):
|
||||||
|
for partition in groups_tree:
|
||||||
|
for groupe in groups_tree[partition]:
|
||||||
|
self.meta.bind_field(self, groups_tree[partition][groupe]['field'])
|
||||||
super().__init__(formdata=formdata, data=data)
|
super().__init__(formdata=formdata, data=data)
|
||||||
self.groups_tree = {}
|
self.groups_tree = groups_tree
|
||||||
self.has_groups = None
|
self.nb_partitions = len(self.groups_tree)
|
||||||
self.group_tree_length = None
|
self.has_groups = self.nb_partitions > 1
|
||||||
self.nb_groups = None
|
|
||||||
self.set_evaluation_infos(data["evaluation_id"])
|
self.set_evaluation_infos(data["evaluation_id"])
|
||||||
|
|
||||||
def set_evaluation_infos(self, evaluation_id):
|
def set_evaluation_infos(self, evaluation_id):
|
||||||
@ -137,9 +141,6 @@ class PlacementForm(FlaskForm):
|
|||||||
eval_data = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id})
|
eval_data = sco_evaluations.do_evaluation_list({"evaluation_id": evaluation_id})
|
||||||
if not eval_data:
|
if not eval_data:
|
||||||
raise ScoValueError("invalid evaluation_id")
|
raise ScoValueError("invalid evaluation_id")
|
||||||
self.groups_tree, self.has_groups, self.nb_groups = _get_group_info(
|
|
||||||
evaluation_id
|
|
||||||
)
|
|
||||||
if self.has_groups:
|
if self.has_groups:
|
||||||
choices = []
|
choices = []
|
||||||
for partition in self.groups_tree:
|
for partition in self.groups_tree:
|
||||||
@ -148,6 +149,9 @@ class PlacementForm(FlaskForm):
|
|||||||
choices.append((groupe_id, "%s (%s)" % (str(groupe), partition)))
|
choices.append((groupe_id, "%s (%s)" % (str(groupe), partition)))
|
||||||
self.groups.choices = choices
|
self.groups.choices = choices
|
||||||
|
|
||||||
|
def get_checkbox(self, partition, groupe):
|
||||||
|
return self.groups_tree[partition][groupe]["field"]
|
||||||
|
|
||||||
|
|
||||||
class _DistributeurContinu:
|
class _DistributeurContinu:
|
||||||
"""Distribue les places selon un ordre numérique."""
|
"""Distribue les places selon un ordre numérique."""
|
||||||
@ -182,7 +186,18 @@ class _Distributeur2D:
|
|||||||
|
|
||||||
def placement_eval_selectetuds(evaluation_id):
|
def placement_eval_selectetuds(evaluation_id):
|
||||||
"""Creation de l'écran de placement"""
|
"""Creation de l'écran de placement"""
|
||||||
form = PlacementForm(
|
class F(PlacementForm):
|
||||||
|
pass
|
||||||
|
|
||||||
|
setattr(F, 'test', BooleanField('test'))
|
||||||
|
groups_tree = _get_group_info(evaluation_id)
|
||||||
|
for partition in groups_tree:
|
||||||
|
for groupe in groups_tree[partition]:
|
||||||
|
name = groups_tree[partition][groupe]["name"]
|
||||||
|
field = groups_tree[partition][groupe]["field"]
|
||||||
|
# F.__setattr__(name, field)
|
||||||
|
form = F(
|
||||||
|
groups_tree,
|
||||||
request.form,
|
request.form,
|
||||||
data={"evaluation_id": int(evaluation_id), "groups": TOUS},
|
data={"evaluation_id": int(evaluation_id), "groups": TOUS},
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% macro render_field(field) %}
|
{% macro render_field(field) %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="wtf-field">{{ field.label }}</td>
|
<th class="wtf-field">{{ field.label }}</th>
|
||||||
<td class="wtf-field">{{ field()|safe }}
|
<td class="wtf-field">{{ field()|safe }}
|
||||||
{% if field.errors %}
|
{% if field.errors %}
|
||||||
<ul class=errors>
|
<ul class=errors>
|
||||||
@ -28,21 +28,24 @@
|
|||||||
{{ render_field(form.etiquetage) }}
|
{{ render_field(form.etiquetage) }}
|
||||||
{% if form.has_groups %}
|
{% if form.has_groups %}
|
||||||
{{ render_field(form.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
|
{# 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 %}
|
{% for partition in form.groups_tree %}
|
||||||
<tr>
|
<tr>
|
||||||
{% if partition == 'Tous' %}
|
{# {% if partition == 'Tous' %}#}
|
||||||
<td rowspan="{{ form.nb_groups }}">Groupes</td>
|
{# <td colspan="{{ form.nb_max_groups }}">Tous</td>#}
|
||||||
{% endif %}
|
{# {% else %}#}
|
||||||
<td>{{ partition }}</td>
|
<th>{{ partition }}</th>
|
||||||
<td>
|
|
||||||
{% for groupe in form.groups_tree[partition] %}
|
{% for groupe in form.groups_tree[partition] %}
|
||||||
{{ groupe }}{{ form[form.groups_tree[partition][groupe]] }}
|
<td>{{ groupe }}{{ form.get_checkbox(partition, groupe)()|safe() }}</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
{# {% endif %}#}
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
-->
|
</tbody></table></td>
|
||||||
|
</tr>
|
||||||
|
{# Fin tentative #}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ render_field(form.file_format) }}
|
{{ render_field(form.file_format) }}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user