🎨 Complete Tailwind CSS conversion - Redesigned post detail page with modern gradient backgrounds - Updated profile page with consistent design language - Converted from Bootstrap to Tailwind CSS throughout ✨ New Features & Improvements - Enhanced community post management system - Added admin panel with analytics dashboard - Improved post creation and editing workflows - Interactive GPS map integration with Leaflet.js - Photo gallery with modal view and hover effects - Adventure statistics and metadata display - Like system and community engagement features 🔧 Technical Improvements - Fixed template syntax errors and CSRF token issues - Updated database models and relationships - Enhanced media file management - Improved responsive design patterns - Added proper error handling and validation 📱 Mobile-First Design - Responsive grid layouts - Touch-friendly interactions - Optimized for all screen sizes - Modern card-based UI components 🏍️ Adventure Platform Features - GPS track visualization and statistics - Photo uploads with thumbnail generation - GPX file downloads for registered users - Community comments and discussions - Post approval workflow for admins - Difficulty rating system with star indicators
107 lines
3.6 KiB
Python
107 lines
3.6 KiB
Python
import os
|
|
from app import create_app, db
|
|
from app.models import User, Post, PostImage, GPXFile, Comment, Like, PageView
|
|
|
|
app = create_app()
|
|
|
|
@app.shell_context_processor
|
|
def make_shell_context():
|
|
return {
|
|
'db': db,
|
|
'User': User,
|
|
'Post': Post,
|
|
'PostImage': PostImage,
|
|
'GPXFile': GPXFile,
|
|
'Comment': Comment,
|
|
'Like': Like,
|
|
'PageView': PageView
|
|
}
|
|
|
|
@app.cli.command()
|
|
def init_db():
|
|
"""Initialize the database."""
|
|
db.create_all()
|
|
print('Database initialized.')
|
|
|
|
@app.cli.command()
|
|
def migrate_db():
|
|
"""Apply database migrations."""
|
|
from sqlalchemy import text
|
|
try:
|
|
# Check if the media_folder column exists
|
|
result = db.session.execute(text('PRAGMA table_info(posts)'))
|
|
columns = [row[1] for row in result.fetchall()]
|
|
|
|
if 'media_folder' not in columns:
|
|
# Add the media_folder column
|
|
db.session.execute(text('ALTER TABLE posts ADD COLUMN media_folder VARCHAR(100)'))
|
|
db.session.commit()
|
|
print('Successfully added media_folder column to posts table')
|
|
else:
|
|
print('media_folder column already exists')
|
|
|
|
# Check if is_cover column exists in post_images table
|
|
result = db.session.execute(text('PRAGMA table_info(post_images)'))
|
|
columns = [row[1] for row in result.fetchall()]
|
|
|
|
if 'is_cover' not in columns:
|
|
# Add the is_cover column
|
|
db.session.execute(text('ALTER TABLE post_images ADD COLUMN is_cover BOOLEAN DEFAULT 0'))
|
|
db.session.commit()
|
|
print('Successfully added is_cover column to post_images table')
|
|
else:
|
|
print('is_cover column already exists')
|
|
|
|
# Check if page_views table exists
|
|
result = db.session.execute(text("SELECT name FROM sqlite_master WHERE type='table' AND name='page_views'"))
|
|
if not result.fetchone():
|
|
# Create page_views table
|
|
db.session.execute(text('''
|
|
CREATE TABLE page_views (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
path VARCHAR(255) NOT NULL,
|
|
user_agent VARCHAR(500),
|
|
ip_address VARCHAR(45),
|
|
referer VARCHAR(500),
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
user_id INTEGER,
|
|
post_id INTEGER,
|
|
FOREIGN KEY (user_id) REFERENCES users(id),
|
|
FOREIGN KEY (post_id) REFERENCES posts(id)
|
|
)
|
|
'''))
|
|
db.session.commit()
|
|
print('Successfully created page_views table')
|
|
else:
|
|
print('page_views table already exists')
|
|
|
|
print('Database schema is up to date')
|
|
except Exception as e:
|
|
print(f'Migration error: {e}')
|
|
db.session.rollback()
|
|
|
|
@app.cli.command()
|
|
def create_admin():
|
|
"""Create an admin user."""
|
|
admin_email = os.environ.get('ADMIN_EMAIL', 'admin@moto-adv.com')
|
|
admin_password = os.environ.get('ADMIN_PASSWORD', 'admin123')
|
|
|
|
admin = User.query.filter_by(email=admin_email).first()
|
|
if admin:
|
|
print(f'Admin user {admin_email} already exists.')
|
|
return
|
|
|
|
admin = User(
|
|
nickname='admin',
|
|
email=admin_email,
|
|
is_admin=True
|
|
)
|
|
admin.set_password(admin_password)
|
|
|
|
db.session.add(admin)
|
|
db.session.commit()
|
|
print(f'Admin user created: {admin_email}')
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=5000, debug=True)
|