From f5b6f34d75fc7e868c2b424b6301304a461ce063 Mon Sep 17 00:00:00 2001 From: Joaquim Nallar Date: Tue, 5 Dec 2023 17:14:40 +0100 Subject: [PATCH] update signage view --- .../signage/signage_detail_attributes.html | 2 +- .../templates/signage/sql/post_10_views.sql | 40 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/geotrek/signage/templates/signage/signage_detail_attributes.html b/geotrek/signage/templates/signage/signage_detail_attributes.html index 52d75265b3..1bcaf9e58c 100644 --- a/geotrek/signage/templates/signage/signage_detail_attributes.html +++ b/geotrek/signage/templates/signage/signage_detail_attributes.html @@ -110,7 +110,7 @@

{% trans "Blades" %}

{{ blade.type|default_if_none:"" }} {{ blade.color|default_if_none:"" }} {{ blade.direction }} - {% for condition in object.conditions.all %} + {% for condition in blade.conditions.all %} {% if not forloop.last %} {{ condition.label }}, {% else %} diff --git a/geotrek/signage/templates/signage/sql/post_10_views.sql b/geotrek/signage/templates/signage/sql/post_10_views.sql index 36b6cd5118..f7e6451f5e 100644 --- a/geotrek/signage/templates/signage/sql/post_10_views.sql +++ b/geotrek/signage/templates/signage/sql/post_10_views.sql @@ -18,8 +18,7 @@ CREATE VIEW {{ schema_geotrek }}.v_signages AS WITH v_signage_tmp AS t.code, t.printed_elevation, t.manager_id, - {% comment %} t.condition_id, {% endcomment %} - p.labels AS "Condition", + p.labels AS "Conditions", t.sealing_id, t.access_id, t.structure_id, @@ -29,14 +28,17 @@ CREATE VIEW {{ schema_geotrek }}.v_signages AS WITH v_signage_tmp AS FROM signage_signage t left join core_topology e on t.topo_object_id = e.id left join signage_signagetype b on t.type_id = b.id - -- FROM signage_signage t, - -- signage_signagetype b, - -- core_topology e - LEFT JOIN - (SELECT a.signagecondition_id, b.label AS labels, a.signage_id - FROM signage_signagecondition b - JOIN signage_signage_conditions a ON a.signagecondition_id = b.id) p - ON t.topo_object_id = p.signage_id + LEFT JOIN ( WITH signage_condition AS ( + SELECT a_1.signagecondition_id, + b_2.label AS labels, + a_1.signage_id + FROM signage_signagecondition b_2 + JOIN signage_signage_conditions a_1 ON a_1.signagecondition_id = b_2.id + ) + SELECT array_to_string(array_agg(signage_condition.labels), ', '::text, '_'::text)::character varying AS labels, + signage_condition.signage_id + FROM signage_condition + GROUP BY signage_condition.signage_id) p ON t.topo_object_id = p.signage_id WHERE e.deleted = FALSE ) SELECT a.id, e.name AS "Structure", @@ -47,7 +49,7 @@ SELECT a.id, {% endfor %} a.code AS "Code", b.label AS "Type", - -- c.label AS "State", + c.labels AS "States", {% for lang in MODELTRANSLATION_LANGUAGES %} a.description_{{ lang }} AS "Description {{ lang }}", {% endfor %} @@ -70,11 +72,17 @@ SELECT a.id, a.geom FROM v_signage_tmp a LEFT JOIN signage_signagetype b ON a.type_id = b.id -LEFT JOIN (SELECT a.signagecondition_id, b.label AS labels, a.signage_id - FROM signage_signagecondition b - JOIN signage_signage_conditions a ON a.signagecondition_id = b.id) c - ON a.id = c.signage_id --- LEFT JOIN infrastructure_infrastructurecondition c ON a.condition_id = c.id +LEFT JOIN ( WITH signage_condition AS ( + SELECT a_1.signagecondition_id, + b_1.label AS labels, + a_1.signage_id + FROM signage_signagecondition b_1 + JOIN signage_signage_conditions a_1 ON a_1.signagecondition_id = b_1.id + ) + SELECT array_to_string(array_agg(signage_condition.labels), ', '::text, '_'::text)::character varying AS labels, + signage_condition.signage_id + FROM signage_condition + GROUP BY signage_condition.signage_id) c ON a.id = c.signage_id LEFT JOIN signage_sealing d ON a.sealing_id = d.id LEFT JOIN authent_structure e ON a.structure_id = e.id LEFT JOIN infrastructure_infrastructureaccessmean i ON a.access_id = i.id