User Interface Improvements: - Added edit modal for skills with activate/deactivate checkbox - Added edit modal for social links with activate/deactivate checkbox - Skills and social links now default to "active" when created - Better UX with inline editing instead of separate pages Image Upload Feature: - Implemented file upload for project images - Support for png, jpg, jpeg, gif, webp (max 16 MB) - Automatic filename sanitization and timestamp prefixing - Preview of current image in edit mode - Option to upload file OR enter manual URL - Files saved to static/img/ directory Modified Files: - app.py: Added upload configuration (MAX_CONTENT_LENGTH, UPLOAD_FOLDER, ALLOWED_EXTENSIONS) - routes/admin.py: Added save_uploaded_file() helper and file handling in project routes - templates/admin/skills.html: Added edit modal with is_active checkbox - templates/admin/social_links.html: Added edit modal with is_active checkbox - templates/admin/project_form.html: Added file upload input with preview Benefits: - No more "inactive" items when creating new entries - Easy toggle of active/inactive state - Professional image upload with validation - Better user experience overall
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright Hersel Giannella
|
|
|
|
from flask import Flask, send_from_directory
|
|
from flask_login import LoginManager
|
|
from config import config
|
|
from models import db, bcrypt, User
|
|
from routes.home import route_home
|
|
from routes.api import route_api
|
|
from routes.auth import route_auth
|
|
from routes.admin import route_admin
|
|
|
|
app = Flask(
|
|
__name__,
|
|
template_folder="templates",
|
|
static_folder="static",
|
|
)
|
|
|
|
# Load configuration
|
|
app.config['SECRET_KEY'] = config.SECRET_KEY
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = config.SQLALCHEMY_DATABASE_URI
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = config.SQLALCHEMY_TRACK_MODIFICATIONS
|
|
app.config['SQLALCHEMY_ECHO'] = config.SQLALCHEMY_ECHO
|
|
|
|
# File upload configuration
|
|
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB max file size
|
|
app.config['UPLOAD_FOLDER'] = 'static/img'
|
|
app.config['ALLOWED_EXTENSIONS'] = {'png', 'jpg', 'jpeg', 'gif', 'webp'}
|
|
|
|
# Initialize extensions
|
|
db.init_app(app)
|
|
bcrypt.init_app(app)
|
|
|
|
# Initialize Flask-Login
|
|
login_manager = LoginManager()
|
|
login_manager.init_app(app)
|
|
login_manager.login_view = 'auth.login'
|
|
login_manager.login_message = 'Per accedere a questa pagina devi effettuare il login.'
|
|
login_manager.login_message_category = 'warning'
|
|
|
|
@login_manager.user_loader
|
|
def load_user(user_id):
|
|
"""Load user for Flask-Login"""
|
|
return User.query.get(int(user_id))
|
|
|
|
# favicon.ico, sitemap.xml and robots.txt
|
|
@app.route('/favicon.ico')
|
|
def favicon():
|
|
return send_from_directory(app.static_folder, 'favicon.ico')
|
|
|
|
@app.route('/sitemap.xml')
|
|
def sitemap():
|
|
return send_from_directory(app.static_folder, 'sitemap.xml')
|
|
|
|
@app.route('/robots.txt')
|
|
def robots():
|
|
return send_from_directory(app.static_folder, 'robots.txt')
|
|
|
|
# BluePrint Routes
|
|
app.register_blueprint(route_home)
|
|
app.register_blueprint(route_api)
|
|
app.register_blueprint(route_auth)
|
|
app.register_blueprint(route_admin)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=config.DEBUG, host=config.APP_HOST, port=config.APP_PORT)
|