Fix: Clean up map_iframe_single.html, remove debug overlay, ensure clean map rendering.

This commit is contained in:
ske087
2025-07-26 15:19:52 +03:00
parent 187254beca
commit 5ddde4bd9b
23 changed files with 1755 additions and 1658 deletions

View File

@@ -126,26 +126,50 @@ def post_detail(post_id):
@login_required
@admin_required
def publish_post(post_id):
"""Publish a post"""
"""Publish a post and create map routes if GPX files exist"""
post = Post.query.get_or_404(post_id)
post.published = True
post.updated_at = datetime.utcnow()
db.session.commit()
flash(f'Post "{post.title}" has been published.', 'success')
try:
db.session.commit()
# Create map routes for GPX files when post is published
from app.utils.gpx_processor import process_post_approval
success = process_post_approval(post_id)
if success:
flash(f'Post "{post.title}" has been published and map routes created.', 'success')
else:
flash(f'Post "{post.title}" has been published. No GPX files found or error creating map routes.', 'warning')
except Exception as e:
db.session.rollback()
current_app.logger.error(f'Error publishing post {post_id}: {str(e)}')
flash(f'Error publishing post: {str(e)}', 'error')
return redirect(url_for('admin.posts'))
@admin.route('/posts/<int:post_id>/unpublish', methods=['POST'])
@login_required
@admin_required
def unpublish_post(post_id):
"""Unpublish a post"""
"""Unpublish a post and remove from map"""
post = Post.query.get_or_404(post_id)
post.published = False
post.updated_at = datetime.utcnow()
db.session.commit()
flash(f'Post "{post.title}" has been unpublished.', 'success')
try:
# Note: We keep the MapRoute data for potential re-publishing
# Only the API will filter by published status
db.session.commit()
flash(f'Post "{post.title}" has been unpublished.', 'success')
except Exception as e:
db.session.rollback()
current_app.logger.error(f'Error unpublishing post {post_id}: {str(e)}')
flash(f'Error unpublishing post: {str(e)}', 'error')
return redirect(url_for('admin.posts'))
@admin.route('/posts/<int:post_id>/delete', methods=['POST'])
@@ -168,19 +192,23 @@ def delete_post(post_id):
# Delete associated files and records
db.session.delete(post)
db.session.commit()
# Clean up orphaned media folders
from app.utils.clean_orphan_media import clean_orphan_post_media
clean_orphan_post_media()
# Check posts after deletion
all_posts_after = Post.query.all()
current_app.logger.info(f'Posts after deletion: {[p.id for p in all_posts_after]}')
current_app.logger.info(f'Successfully deleted post {post_id}: "{title}"')
flash(f'Post "{title}" has been deleted.', 'success')
except Exception as e:
db.session.rollback()
current_app.logger.error(f'Error deleting post {post_id}: {str(e)}')
flash(f'Error deleting post: {str(e)}', 'error')
return redirect(url_for('admin.posts'))
@admin.route('/users')

View File

@@ -28,6 +28,11 @@ def index():
return render_template('community/index.html', posts=posts, posts_with_routes=posts_with_routes)
@community.route('/test-map')
def test_map():
"""Test map page for debugging"""
return render_template('community/test_map.html')
@community.route('/post/<int:id>')
def post_detail(id):
"""Individual post detail page"""
@@ -666,47 +671,68 @@ def save_gpx_file(gpx_file, post_id):
@community.route('/api/routes')
def api_routes():
"""API endpoint to get all routes for map display"""
posts_with_routes = Post.query.filter_by(published=True).join(GPXFile).all()
routes_data = []
for post in posts_with_routes:
for gpx_file in post.gpx_files:
"""API endpoint to get all routes for map display - database optimized"""
try:
from app.utils.gpx_processor import get_all_map_routes
routes_data = get_all_map_routes()
# Add additional post information and format for frontend
formatted_routes = []
for route_data in routes_data:
try:
# Read and parse GPX file using new folder structure
if post.media_folder:
gpx_path = os.path.join(current_app.root_path, 'static', 'media', 'posts',
post.media_folder, 'gpx', gpx_file.filename)
else:
# Fallback to old path for existing files
gpx_path = os.path.join(current_app.instance_path, 'uploads', 'gpx', gpx_file.filename)
if os.path.exists(gpx_path):
with open(gpx_path, 'r') as f:
gpx_content = f.read()
gpx = gpxpy.parse(gpx_content)
# Extract coordinates
coordinates = []
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
coordinates.append([point.latitude, point.longitude])
if coordinates:
routes_data.append({
'id': post.id,
'title': post.title,
'author': post.author.nickname,
'coordinates': coordinates,
'url': url_for('community.post_detail', id=post.id)
})
formatted_routes.append({
'id': route_data['post_id'],
'title': route_data['post_title'],
'author': route_data['post_author'],
'coordinates': route_data['coordinates'],
'url': url_for('community.post_detail', id=route_data['post_id']),
'distance': route_data['stats']['distance'],
'elevation_gain': route_data['stats']['elevation_gain'],
'max_elevation': route_data['stats']['max_elevation'],
'total_points': len(route_data['coordinates']),
'start_point': route_data['start_point'],
'end_point': route_data['end_point'],
'bounds': route_data['bounds']
})
except Exception as e:
current_app.logger.error(f'Error processing GPX file {gpx_file.filename}: {str(e)}')
current_app.logger.error(f'Error formatting route data: {str(e)}')
continue
return jsonify(routes_data)
return jsonify(formatted_routes)
except Exception as e:
current_app.logger.error(f'Error getting map routes: {str(e)}')
return jsonify([]) # Return empty array on error
@community.route('/api/route/<int:post_id>')
def api_route_detail(post_id):
"""API endpoint to get detailed route data for a specific post"""
try:
from app.utils.gpx_processor import get_post_route_details
route_data = get_post_route_details(post_id)
if not route_data:
return jsonify({'error': 'Route not found'}), 404
# Format for frontend
formatted_route = {
'id': route_data['post_id'],
'coordinates': route_data['coordinates'],
'simplified_coordinates': route_data['simplified_coordinates'],
'start_point': route_data['start_point'],
'end_point': route_data['end_point'],
'bounds': route_data['bounds'],
'stats': route_data['stats']
}
return jsonify(formatted_route)
except Exception as e:
current_app.logger.error(f'Error getting route details for post {post_id}: {str(e)}')
return jsonify({'error': 'Internal server error'}), 500
@community.route('/media/posts/<post_folder>/images/<filename>')
def serve_image(post_folder, filename):

View File

@@ -24,6 +24,18 @@ def health_check():
"""Health check endpoint"""
return {'status': 'healthy', 'timestamp': datetime.utcnow().isoformat()}
@main.route('/map-test')
def map_test():
"""Serve the map test page"""
from flask import send_from_directory
return send_from_directory('static', 'map_test.html')
@main.route('/basic-map-test')
def basic_map_test():
"""Serve the basic map test page"""
from flask import send_from_directory
return send_from_directory('static', 'basic_map_test.html')
@main.app_errorhandler(404)
def not_found_error(error):
return render_template('errors/404.html'), 404