mirror of
				https://github.com/StefBuwalda/cal_counter.git
				synced 2025-10-30 03:10:00 +00:00 
			
		
		
		
	Add admin check and update FoodItems model
Introduced an admin_required check for all admin routes using Flask-Login's current_user. Updated the FoodItems model to use per-100g nutritional fields and removed unit relationships. Seed script now creates both admin and regular user accounts.
This commit is contained in:
		| @@ -1,4 +1,6 @@ | ||||
| from flask import Blueprint, render_template | ||||
| from flask import Blueprint, render_template, abort | ||||
| from flask_login import current_user | ||||
| from models import FoodItems | ||||
|  | ||||
| admin_bp = Blueprint( | ||||
|     "admin", | ||||
| @@ -8,6 +10,13 @@ admin_bp = Blueprint( | ||||
| ) | ||||
|  | ||||
|  | ||||
| @admin_bp.before_request | ||||
| def admin_required(): | ||||
|     if not current_user.is_admin: | ||||
|         abort(403) | ||||
|  | ||||
|  | ||||
| @admin_bp.route("/food_items", methods=["GET"]) | ||||
| def food_items(): | ||||
|     return render_template("food_items.html") | ||||
|     items = FoodItems.query.all() | ||||
|     return render_template("food_items.html", items=items) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user