Expose relation fields in the champ pickers and fix their column resolution
data_definition_options() used to exclude relation-type fields from its field list entirely, so a filter/binding could never reference "the linked object" of a row — and even when a relation field's clean name was typed manually (as the earlier "level.parcour" example needed), it silently matched nothing: every column lookup for a filter/repeater field used the field's own name, but a relation is actually stored in a "<field>_id" column (see create_definition.py), so the lookup always missed.
Relation fields now appear in the champ dropdowns (Répéteur's filtre_champ/filtre2_champ, Donnée liée's data_filtre_champ/data_filtre2_champ) labeled with the object they point to (e.g. "parcour (→ parcours)"), and a new _field_column() helper in filter_repeater_rows.py resolves the right "<field>_id" column whenever the field turns out to be a relation — used consistently by the filter comparison itself, the "{{Objet.champ}}" dynamic-value resolver, the repeater's row content ({{champ}}), and the Donnée liée row context. Jauge's own champ/champ_nom pickers (which need an actual displayable value, not an id) still exclude relations, both server- and client-side.
Verified end to end: the dropdown shows the relation field with its target-object label, and filtering "level" rows by the clean relation field name "parcour" (not "parcour_id") against a dynamic {{game.current_parcours}} reference now actually matches, alongside the existing "number" filter. Full suite green (89).
This commit is contained in:
@@ -6,6 +6,15 @@ from .data_definition_options import data_definition_options
|
||||
from ..element_types.list_element_types import list_element_types
|
||||
|
||||
|
||||
def _field_label(f):
|
||||
"""Libellé affiché dans une liste déroulante de champs — précise l'objet
|
||||
visé pour un champ "relation" (ex. "parcour (→ parcours)"), pour qu'on
|
||||
sache ce qu'on choisit sans avoir à aller vérifier dans l'objet."""
|
||||
if f["type"] == "relation" and f.get("relation_definition_name"):
|
||||
return f"{f['name']} (→ {f['relation_definition_name']})"
|
||||
return f["name"]
|
||||
|
||||
|
||||
def controls_with_values(slug, el):
|
||||
"""Pour le panneau de propriétés : la liste des réglages du widget de
|
||||
cet élément, chacun avec sa valeur actuelle déjà résolue. Le réglage
|
||||
@@ -38,11 +47,16 @@ def controls_with_values(slug, el):
|
||||
control["options"] = [("", "(aucun — utiliser le modèle de texte ci-dessous)")] + [(str(t["id"]), t["name"]) for t in types]
|
||||
if control["key"] == "row_id":
|
||||
control["options"] = [("", "(sélectionner un objet d'abord)")] + [(str(r["id"]), r["label"]) for r in jauge_options["rows"]]
|
||||
if control["key"] in ("champ", "filtre_champ", "filtre2_champ"):
|
||||
control["options"] = [("", "(sélectionner un objet d'abord)")] + [(f["name"], f["name"]) for f in jauge_options["fields"]]
|
||||
if control["key"] == "champ_nom":
|
||||
control["options"] = [("", "— aucun —")] + [(f["name"], f["name"]) for f in jauge_options["fields"]]
|
||||
if control["key"] in ("champ", "champ_nom"):
|
||||
# La Jauge affiche une VALEUR (champ) ou un NOM (champ_nom) tel
|
||||
# quel — un champ "relation" n'y a pas de sens (c'est un id, pas
|
||||
# une valeur à afficher), donc exclu ici uniquement.
|
||||
non_relation_fields = [f for f in jauge_options["fields"] if f["type"] != "relation"]
|
||||
empty_label = "— aucun —" if control["key"] == "champ_nom" else "(sélectionner un objet d'abord)"
|
||||
control["options"] = [("", empty_label)] + [(f["name"], _field_label(f)) for f in non_relation_fields]
|
||||
if control["key"] in ("filtre_champ", "filtre2_champ"):
|
||||
control["options"] = [("", "(sélectionner un objet d'abord)")] + [(f["name"], _field_label(f)) for f in jauge_options["fields"]]
|
||||
if control["key"] in ("data_filtre_champ", "data_filtre2_champ"):
|
||||
control["options"] = [("", "(sélectionner un objet d'abord)")] + [(f["name"], f["name"]) for f in data_binding_options["fields"]]
|
||||
control["options"] = [("", "(sélectionner un objet d'abord)")] + [(f["name"], _field_label(f)) for f in data_binding_options["fields"]]
|
||||
result.append({**control, "value": _control_value(el, control)})
|
||||
return result
|
||||
|
||||
@@ -23,5 +23,18 @@ def data_definition_options(slug, definition_id):
|
||||
{"id": r["id"], "label": f"{r.get(display_col)} (#{r['id']})" if display_col else f"Ligne #{r['id']}"}
|
||||
for r in rows
|
||||
]
|
||||
field_options = [{"name": f["name"], "type": f["type"]} for f in full["fields"] if f["type"] != "relation"]
|
||||
# Les champs "relation" sont INCLUS (contrairement à avant) : un filtre
|
||||
# de Répéteur/Donnée liée doit pouvoir comparer, par exemple, "le
|
||||
# parcours lié" d'un niveau — ils restent identifiables via leur "type"
|
||||
# pour les endroits qui n'en veulent pas (ex: le champ numérique suivi
|
||||
# par une Jauge, voir controls_with_values.py). relation_definition_name
|
||||
# (le nom de l'objet visé) sert uniquement à afficher un libellé clair
|
||||
# dans la liste déroulante, ex. "parcour (→ parcours)".
|
||||
definitions_by_id = {d["id"]: d["name"] for d in db.list_definitions(slug)}
|
||||
field_options = []
|
||||
for f in full["fields"]:
|
||||
entry = {"name": f["name"], "type": f["type"]}
|
||||
if f["type"] == "relation":
|
||||
entry["relation_definition_name"] = definitions_by_id.get(f.get("relation_definition_id"))
|
||||
field_options.append(entry)
|
||||
return {"rows": row_options, "fields": field_options}
|
||||
|
||||
Reference in New Issue
Block a user