add public view

This commit is contained in:
2025-12-02 14:42:41 +01:00
parent 6acb633c2e
commit f23293fcf5

34
app.py
View File

@@ -13,8 +13,6 @@ from functools import wraps
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
DATABASE = os.path.join(os.path.dirname(__file__), "avent.db") DATABASE = os.path.join(os.path.dirname(__file__), "avent.db")
# Configuration upload images
UPLOAD_FOLDER = os.path.join(os.path.dirname(__file__), "static", "uploads") UPLOAD_FOLDER = os.path.join(os.path.dirname(__file__), "static", "uploads")
os.makedirs(UPLOAD_FOLDER, exist_ok=True) os.makedirs(UPLOAD_FOLDER, exist_ok=True)
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif"} ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif"}
@@ -22,7 +20,7 @@ ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif"}
app = Flask(__name__) app = Flask(__name__)
app.secret_key = "change-me-super-secret-key-2025" app.secret_key = "change-me-super-secret-key-2025"
app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
app.config["MAX_CONTENT_LENGTH"] = 5 * 1024 * 1024 # 5 Mo max app.config["MAX_CONTENT_LENGTH"] = 5 * 1024 * 1024 # Max 5 MB
def allowed_file(filename): def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@@ -59,11 +57,10 @@ def init_db():
24 24
) )
).lastrowid ).lastrowid
people_list = ["Valentin", "Nicolas", "Victor", "Julie", "Louis", "Alexandre", "David", "Raphaël"] people_list = ["User1"]
for name in people_list: for name in people_list:
db.execute("INSERT INTO people (project_id, name, draws, max_draws) VALUES (?, ?, 0, 0)", (project_id, name)) db.execute("INSERT INTO people (project_id, name, draws, max_draws) VALUES (?, ?, 0, 0)", (project_id, name))
recalc_max_draws_for_project(project_id) recalc_max_draws_for_project(project_id)
db.commit() db.commit()
def get_user_by_username(username): def get_user_by_username(username):
@@ -175,6 +172,30 @@ def catchup_draws(project_id):
db.commit() db.commit()
return new_draws return new_draws
@app.route("/public")
def public_dashboard():
projects = get_project()
return render_template("public_projects.html", projects=projects)
@app.route("/public/project/<int:project_id>")
def public_project_view(project_id):
project = get_project(project_id)
if not project:
flash("Projet non trouvé.")
return redirect(url_for('public_dashboard'))
today = date.today()
today_day = today.day if today.month == 12 else 1
if today_day > project["total_days"]:
today_day = project["total_days"]
today_draw = get_draw_for_project_day(project_id, today_day)
all_draws = get_all_draws_for_project(project_id)
stats = get_people_stats(project_id)
return render_template("public_project_view.html", project=project, today_day=today_day,
today_draw=today_draw, all_draws=all_draws, stats=stats)
@app.route("/") @app.route("/")
@login_required @login_required
def dashboard(): def dashboard():
@@ -249,7 +270,6 @@ def admin_projects():
description = request.form.get("description", "").strip() description = request.form.get("description", "").strip()
total_days = int(request.form.get("total_days", 24)) total_days = int(request.form.get("total_days", 24))
# Gestion upload image
image_url = None image_url = None
if 'image_file' in request.files: if 'image_file' in request.files:
file = request.files['image_file'] file = request.files['image_file']
@@ -269,7 +289,6 @@ def admin_projects():
flash("Projet ajouté avec succès.") flash("Projet ajouté avec succès.")
else: # update else: # update
project_id = int(request.form.get("project_id")) project_id = int(request.form.get("project_id"))
# Si pas d'image uploadée, conserver l'ancienne
if image_url is None: if image_url is None:
cur = db.execute("SELECT image_url FROM project WHERE id = ?", (project_id,)) cur = db.execute("SELECT image_url FROM project WHERE id = ?", (project_id,))
row = cur.fetchone() row = cur.fetchone()
@@ -366,6 +385,7 @@ def logout():
flash("Déconnecté.") flash("Déconnecté.")
return redirect(url_for("login")) return redirect(url_for("login"))
if __name__ == "__main__": if __name__ == "__main__":
if not os.path.exists(DATABASE): if not os.path.exists(DATABASE):
with app.app_context(): with app.app_context():