34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from flask import render_template, request, abort
|
|
|
|
import db
|
|
|
|
from core.flask_app import app
|
|
|
|
|
|
@app.route("/game/<slug>/objects/<int:definition_id>")
|
|
def object_view(slug, definition_id):
|
|
game = db.game_meta(slug)
|
|
definition = db.get_definition(slug, definition_id)
|
|
if not definition:
|
|
abort(404)
|
|
rows = db.list_rows(slug, definition)
|
|
|
|
# Pour l'affichage : traduit chaque id de relation en un libellé lisible
|
|
# (ex. "Salle serveur (#1)") au lieu d'un identifiant numérique brut.
|
|
relation_labels = {}
|
|
for f in definition["fields"]:
|
|
if f["type"] == "relation":
|
|
options = db.relation_options(slug, f["relation_definition_id"])
|
|
relation_labels[f["id"]] = {opt["id"]: opt["label"] for opt in options}
|
|
|
|
referenced_by = db.definitions_referencing(slug, definition_id)
|
|
|
|
blocked_row_id = request.args.get("blocked_row", type=int)
|
|
blocked_row_refs = db.rows_referencing(slug, definition_id, blocked_row_id) if blocked_row_id else None
|
|
|
|
return render_template(
|
|
"data_list.html", game=game, definition=definition, rows=rows,
|
|
relation_labels=relation_labels, referenced_by=referenced_by,
|
|
blocked_row_id=blocked_row_id, blocked_row_refs=blocked_row_refs,
|
|
)
|