Fix Interactive Route Map: Create MapRoute records from GPX files
- Create MapRoute database records for all GPX files for map visualization - Populate route statistics (distance, elevation, coordinates) from GPX parsing - Update GPX file statistics to mirror MapRoute data for post detail pages - Enable /community/api/routes endpoint to return proper route data for map iframe - Fix post detail page GPX statistics display This resolves the issue where the community map showed '2 routes discovered' but routes weren't actually rendering on the Leaflet.js map visualization. Changes: - Dockerfile: Updated init script paths and added migrate-db call - app/__init__.py: Added admin user auto-creation with error handling - app/routes/community.py: Added debug logging and API route for map data - docker-compose.yml: Simplified to use .env for environment variables - run.py: Added comprehensive database schema migration command
This commit is contained in:
@@ -100,22 +100,28 @@ def create_app(config_name=None):
|
||||
os.makedirs(os.path.join(upload_dir, 'gpx'), exist_ok=True)
|
||||
|
||||
# --- Initial Admin Creation from .env ---
|
||||
# Temporarily disabled for migration setup
|
||||
# from app.models import User
|
||||
# with app.app_context():
|
||||
# admin_email = os.environ.get('ADMIN_EMAIL')
|
||||
# admin_nickname = os.environ.get('ADMIN_NICKNAME')
|
||||
# admin_password = os.environ.get('ADMIN_PASSWORD')
|
||||
# if admin_email and admin_nickname and admin_password:
|
||||
# if not User.query.filter_by(email=admin_email).first():
|
||||
# user = User(nickname=admin_nickname, email=admin_email, is_admin=True, is_active=True)
|
||||
# user.set_password(admin_password)
|
||||
# db.session.add(user)
|
||||
# db.session.commit()
|
||||
# print(f"[INFO] Admin user {admin_nickname} <{admin_email}> created from .env.")
|
||||
# else:
|
||||
# print(f"[INFO] Admin with email {admin_email} already exists.")
|
||||
# else:
|
||||
# print("[INFO] ADMIN_EMAIL, ADMIN_NICKNAME, or ADMIN_PASSWORD not set in .env. Skipping admin creation.")
|
||||
from app.models import User
|
||||
with app.app_context():
|
||||
admin_email = os.environ.get('ADMIN_EMAIL')
|
||||
admin_nickname = os.environ.get('ADMIN_NICKNAME')
|
||||
admin_password = os.environ.get('ADMIN_PASSWORD')
|
||||
if admin_email and admin_nickname and admin_password:
|
||||
try:
|
||||
# Check if users table exists first
|
||||
db.session.execute('SELECT 1 FROM users LIMIT 1')
|
||||
# If we got here, table exists, now check for admin user
|
||||
if not User.query.filter_by(email=admin_email).first():
|
||||
user = User(nickname=admin_nickname, email=admin_email, is_admin=True, is_active=True)
|
||||
user.set_password(admin_password)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
print(f"[INFO] Admin user {admin_nickname} <{admin_email}> created from .env.")
|
||||
else:
|
||||
print(f"[INFO] Admin with email {admin_email} already exists.")
|
||||
except Exception as e:
|
||||
# Table doesn't exist yet, skip admin creation
|
||||
print(f"[INFO] Database not initialized yet. Skipping admin creation. Run migrations with: flask db upgrade")
|
||||
else:
|
||||
print("[INFO] ADMIN_EMAIL, ADMIN_NICKNAME, or ADMIN_PASSWORD not set in .env. Skipping admin creation.")
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user