diff --git a/sar_calls.py b/sar_calls.py index e7108f4..c6705fa 100644 --- a/sar_calls.py +++ b/sar_calls.py @@ -92,12 +92,21 @@ def edit_sar(id): @app.route('/sar_details/') def sar_details(id): sar = SARCall.query.get_or_404(id) # Fetch the SARCall record or return 404 - gpx_files = [id[0] for id in GPSTrack.query.with_entities(GPSTrack.id).filter_by(sar_call_id=id).all()] # Fetch all GPX files for this SARCall + gpx_files = [id[0] for id in GPSTrack.query.with_entities(GPSTrack.id).filter_by( + sar_call_id=id).all()] # Fetch all GPX files for this SARCall + comments_with_gpx = [] - # Assuming each comment has a relationship to GPXFile - print (gpx_files) + for comment in sar.comments: + gpx_tracks = GPSTrack.query.filter_by(comment_id=comment.id).all() + for track in gpx_tracks: + comments_with_gpx.append({ + "id": track.id, + "comment_id": comment.id, + "name": track.file_name, + "comment": track.gpx_name + }) - return render_template('sar_details.html', sar=sar, gpx_ids=gpx_files) + return render_template('sar_details.html', sar=sar, gpx_ids=gpx_files, comments_with_gpx=comments_with_gpx) @app.route('/delete_sar/') @@ -169,9 +178,8 @@ def upload_gpx(): return jsonify({'message': 'GPX file uploaded successfully'}) - @app.route('/get_gpx/') @login_required def get_gpx(gpx_id): gpx_file = GPSTrack.query.get_or_404(gpx_id) - return Response(gpx_file.gpx_data, mimetype='application/gpx+xml') \ No newline at end of file + return Response(gpx_file.gpx_data, mimetype='application/gpx+xml') diff --git a/templates/sar_details.html b/templates/sar_details.html index 64ab545..22732d4 100644 --- a/templates/sar_details.html +++ b/templates/sar_details.html @@ -60,6 +60,15 @@

{{ comment.text }}

+ {% for gpx_track in comments_with_gpx %} + {% if gpx_track.comment_id == comment.id %} +
  • + {{ gpx_track.name }}: {{gpx_track.comment}} +
  • + {% endif %} + + {% endfor %} + {% if current_user.id == comment.user_id or current_user.id == 1 or current_user.id == sar.user_id %}