mirror of
				https://github.com/StefBuwalda/cal_counter.git
				synced 2025-10-30 03:10:00 +00:00 
			
		
		
		
	Add barcode-based meal logging workflow
Introduces a new add_meal blueprint with routes and templates for scanning barcodes, adding new food items, and logging meals. Updates FoodItemForm and FoodLogForm validation, changes FoodLog.amount to float, and integrates the new workflow into the daily log UI. Refactors user routes and templates to support the new meal logging process.
This commit is contained in:
		| @@ -47,21 +47,10 @@ def delete_food_item(id: int): | ||||
|     return redirect(url_for("user.dashboard")) | ||||
|  | ||||
|  | ||||
| fields = [ | ||||
|     "barcode", | ||||
|     "name", | ||||
|     "energy", | ||||
|     "protein", | ||||
|     "carbs", | ||||
|     "sugar", | ||||
|     "fat", | ||||
|     "saturated_fat", | ||||
| ] | ||||
|  | ||||
|  | ||||
| @user_bp.route("/add_food_item/<string:barcode>", methods=["GET", "POST"]) | ||||
| def add_food_item(barcode): | ||||
|     form = FoodItemForm(barcode=barcode) | ||||
|     print(form) | ||||
|  | ||||
|     if form.validate_on_submit(): | ||||
|         print("[DEBUG] Valid form") | ||||
| @@ -92,6 +81,7 @@ def add_food_item(barcode): | ||||
|     else: | ||||
|         print("[DEBUG] Invalid form") | ||||
|     if form.barcode.data: | ||||
|         print("1") | ||||
|         return render_template("add_food_item.html", form=form) | ||||
|     else: | ||||
|         return redirect("/") | ||||
| @@ -217,7 +207,7 @@ def add_meal(): | ||||
|  | ||||
|  | ||||
| @user_bp.route("/", methods=["GET"]) | ||||
| def test(): | ||||
| def daily_log(): | ||||
|     today = datetime.now(timezone.utc).date() | ||||
|     logs_today = current_user.food_logs.filter_by(date_=today).all() | ||||
|     logs = [[], [], [], []] | ||||
| @@ -225,7 +215,7 @@ def test(): | ||||
|         logs[log.part_of_day].append(log) | ||||
|     print(logs) | ||||
|     return render_template( | ||||
|         "test.html", date=(today.strftime("%d/%m/%y")), logs=logs | ||||
|         "daily_log.html", date=(today.strftime("%d/%m/%y")), logs=logs | ||||
|     ) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -25,11 +25,11 @@ Food Nutritional Info | ||||
|         <div class="p-3 mb-2 border rounded"> | ||||
|             <div class="d-flex justify-content-between align-items-center"> | ||||
|                 <h4 class="mb-0">Breakfast</h4> | ||||
|                 <a href="{{url_for('user.select_meal', meal_type=0)}}" class="btn btn-sm btn-primary">Add</a> | ||||
|                 <a href="{{url_for('add_meal.step1', meal_type=0)}}" class="btn btn-sm btn-primary">Add</a> | ||||
|             </div> | ||||
|             <div> | ||||
|                 {% for log in logs[0] %} | ||||
|                 <p class="p-0 mb-0">{{log.food_item.name}}</p> | ||||
|                 <p class="p-0 mb-0">{{log.food_item.name}} - {{log.amount}}</p> | ||||
|                 {% endfor %} | ||||
|             </div> | ||||
|         </div> | ||||
| @@ -37,33 +37,33 @@ Food Nutritional Info | ||||
|         <div class="p-3 mb-2 border rounded"> | ||||
|             <div class="d-flex justify-content-between align-items-center"> | ||||
|                 <h4 class="mb-0">Lunch</h4> | ||||
|                 <a href="{{url_for('user.select_meal', meal_type=1)}}" class="btn btn-sm btn-primary">Add</a> | ||||
|                 <a href="{{url_for('add_meal.step1', meal_type=1)}}" class="btn btn-sm btn-primary">Add</a> | ||||
|             </div> | ||||
|             <div> | ||||
|                 {% for log in logs[1] %} | ||||
|                 <p class="p-0 mb-0">{{log.food_item.name}}</p> | ||||
|                 <p class="p-0 mb-0">{{log.food_item.name}} - {{log.amount}}</p> | ||||
|                 {% endfor %} | ||||
|             </div> | ||||
|         </div> | ||||
|         <div class="p-3 mb-2 border rounded"> | ||||
|             <div class="d-flex justify-content-between align-items-center"> | ||||
|                 <h4 class="mb-0">Dinner</h4> | ||||
|                 <a href="{{url_for('user.select_meal', meal_type=2)}}" class="btn btn-sm btn-primary">Add</a> | ||||
|                 <a href="{{url_for('add_meal.step1', meal_type=2)}}" class="btn btn-sm btn-primary">Add</a> | ||||
|             </div> | ||||
|             <div> | ||||
|                 {% for log in logs[2] %} | ||||
|                 <p class="p-0 mb-0">{{log.food_item.name}}</p> | ||||
|                 <p class="p-0 mb-0">{{log.food_item.name}} - {{log.amount}}</p> | ||||
|                 {% endfor %} | ||||
|             </div> | ||||
|         </div> | ||||
|         <div class="p-3 mb-2 border rounded"> | ||||
|             <div class="d-flex justify-content-between align-items-center"> | ||||
|                 <h4 class="mb-0">Snacks</h4> | ||||
|                 <a href="{{url_for('user.select_meal', meal_type=3)}}" class="btn btn-sm btn-primary">Add</a> | ||||
|                 <a href="{{url_for('add_meal.step1', meal_type=3)}}" class="btn btn-sm btn-primary">Add</a> | ||||
|             </div> | ||||
|             <div> | ||||
|                 {% for log in logs[3] %} | ||||
|                 <p class="p-0 mb-0">{{log.food_item.name}}</p> | ||||
|                 <p class="p-0 mb-0">{{log.food_item.name}} - {{log.amount}}</p> | ||||
|                 {% endfor %} | ||||
|             </div> | ||||
|         </div> | ||||
| @@ -55,7 +55,7 @@ | ||||
|                         if (!response.ok) { | ||||
|                             throw new Error('Network response was not OK'); | ||||
|                         } | ||||
|                         return response.json(); // or response.text(), response.blob(), etc. | ||||
|                         return response.json(); | ||||
|                     }) | ||||
|                     .then(data => { | ||||
|                         const baseURL2 = "{{url_for('user.select_item', item_id='0')}}" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user