mirror of
				https://github.com/StefBuwalda/cal_counter.git
				synced 2025-10-29 19:00:00 +00:00 
			
		
		
		
	Add user dashboard and per-user food item ownership
Introduces a user dashboard route and template, moving dashboard logic to a user blueprint. FoodItem now has an owner_id field and a unique constraint on (barcode, owner_id), with relationships set up in the User model. Updates food item creation to associate with the current user, and adds a utility script for dropping a temporary table.
This commit is contained in:
		
							
								
								
									
										20
									
								
								application/user/routes.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								application/user/routes.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| from flask import Blueprint, redirect, url_for, render_template | ||||
| from flask_login import current_user | ||||
|  | ||||
| user_bp = Blueprint( | ||||
|     "user", | ||||
|     __name__, | ||||
|     template_folder="templates", | ||||
| ) | ||||
|  | ||||
|  | ||||
| @user_bp.before_request | ||||
| def login_required(): | ||||
|     if not current_user.is_authenticated: | ||||
|         return redirect(url_for("login")) | ||||
|  | ||||
|  | ||||
| @user_bp.route("/dashboard", methods=["GET"]) | ||||
| def dashboard(): | ||||
|     items = current_user.food_items.all() | ||||
|     return render_template("dashboard.html", items=items) | ||||
		Reference in New Issue
	
	Block a user