diff --git a/loko/assets/views/structures.py b/loko/assets/views/structures.py index 4ec617e..c1dabd8 100644 --- a/loko/assets/views/structures.py +++ b/loko/assets/views/structures.py @@ -723,19 +723,21 @@ def structures_edit_exceptional_transport(request, structure_id): @require_GET def structures_exceptional_transport_geojson(request): - """Retourne l'ensemble des ouvrages avec données de transport exceptionnel au format GeoJSON.""" + """Retourne l'ensemble des ouvrages pertinents (ponts, viaducs, tunnels, passerelles...) au format GeoJSON.""" if not request.user.is_authenticated or not can_view_exceptional_transport(request.user): return JsonResponse({'type': 'FeatureCollection', 'features': []}) - te_list = ( - StructureExceptionalTransport.objects - .select_related('structure', 'structure__main_location') + structures = ( + Structure.objects + .exclude(structure_type='gallery') + .exclude(name_fr__icontains='galerie technique') + .exclude(name_nl__icontains='technische koker') + .select_related('exceptional_transport_info', 'main_location') .all() ) features = [] - for te in te_list: - structure = te.structure + for structure in structures: loc = structure.main_location if not loc: continue @@ -760,9 +762,10 @@ def structures_exceptional_transport_geojson(request): continue detail_url = reverse('assets:structures_locations_detail', args=[loc.id]) + te = getattr(structure, 'exceptional_transport_info', None) h_str = "" - if te.clearance_height_left_m or te.clearance_height_center_m or te.clearance_height_right_m: + if te and (te.clearance_height_left_m or te.clearance_height_center_m or te.clearance_height_right_m): h_left = f"{te.clearance_height_left_m}m" if te.clearance_height_left_m else "-" h_center = f"{te.clearance_height_center_m}m" if te.clearance_height_center_m else "-" h_right = f"{te.clearance_height_right_m}m" if te.clearance_height_right_m else "-" @@ -775,33 +778,35 @@ def structures_exceptional_transport_geojson(request): 'coordinates': [lon, lat] }, 'properties': { - 'id': te.id, + 'id': te.id if te else None, + 'has_te_info': bool(te), 'structure_id': structure.id, 'structure_code': structure.code or '', 'name': structure.get_name(), 'name_fr': structure.name_fr or '', 'name_nl': structure.name_nl or '', 'structure_type': structure.get_structure_type_display() if hasattr(structure, 'get_structure_type_display') else (structure.structure_type or ''), + 'structure_type_code': structure.structure_type or '', 'location_id': loc.id, 'location_code': loc.code or '', 'detail_url': detail_url, - 'fod_vnr': te.fod_vnr, - 'national_id': te.national_id or '', - 'bridge_class': te.bridge_class or '', - 'passage_status': te.passage_status, - 'passage_status_display': str(te.get_passage_status_display()), - 'max_authorized_weight_tonnes': float(te.max_authorized_weight_tonnes) if te.max_authorized_weight_tonnes is not None else None, - 'min_guaranteed_capacity_tonnes': float(te.min_guaranteed_capacity_tonnes) if te.min_guaranteed_capacity_tonnes is not None else None, - 'max_calculated_weight_tonnes': float(te.max_calculated_weight_tonnes) if te.max_calculated_weight_tonnes is not None else None, - 'usable_width_m': float(te.usable_width_m) if te.usable_width_m is not None else None, + 'fod_vnr': te.fod_vnr if te else None, + 'national_id': te.national_id if te and te.national_id else '', + 'bridge_class': te.bridge_class if te and te.bridge_class else '', + 'passage_status': te.passage_status if te else 'not_evaluated', + 'passage_status_display': str(te.get_passage_status_display()) if te else str(_("Non évalué")), + 'max_authorized_weight_tonnes': float(te.max_authorized_weight_tonnes) if te and te.max_authorized_weight_tonnes is not None else None, + 'min_guaranteed_capacity_tonnes': float(te.min_guaranteed_capacity_tonnes) if te and te.min_guaranteed_capacity_tonnes is not None else None, + 'max_calculated_weight_tonnes': float(te.max_calculated_weight_tonnes) if te and te.max_calculated_weight_tonnes is not None else None, + 'usable_width_m': float(te.usable_width_m) if te and te.usable_width_m is not None else None, 'clearance_heights_str': h_str, - 'max_speed_kmh': te.max_speed_kmh, - 'is_braking_forbidden': te.is_braking_forbidden, - 'is_isolated_crossing_only': te.is_isolated_crossing_only, - 'safety_distance_m': float(te.safety_distance_m) if te.safety_distance_m is not None else None, - 'prescriptions_fr': te.prescriptions_fr or '', - 'prescriptions_nl': te.prescriptions_nl or '', - 'last_study_ref': te.last_study_ref or '', + 'max_speed_kmh': te.max_speed_kmh if te else None, + 'is_braking_forbidden': te.is_braking_forbidden if te else False, + 'is_isolated_crossing_only': te.is_isolated_crossing_only if te else False, + 'safety_distance_m': float(te.safety_distance_m) if te and te.safety_distance_m is not None else None, + 'prescriptions_fr': te.prescriptions_fr if te and te.prescriptions_fr else '', + 'prescriptions_nl': te.prescriptions_nl if te and te.prescriptions_nl else '', + 'last_study_ref': te.last_study_ref if te and te.last_study_ref else '', } }) diff --git a/loko/home/templates/home/widgets/exceptional_transport.html b/loko/home/templates/home/widgets/exceptional_transport.html index 25ccd53..9661285 100644 --- a/loko/home/templates/home/widgets/exceptional_transport.html +++ b/loko/home/templates/home/widgets/exceptional_transport.html @@ -13,14 +13,14 @@ {% translate "Transport Exceptionnel & Convois Lourds" %} - {% translate "Cartographie du réseau d'ouvrages d'art et conditions d'admissibilité" %} + {% translate "Cartographie du réseau d'ouvrages d'art (ponts, viaducs, tunnels, passerelles) et conditions de passage" %}