mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 11:19:59 +00:00
Implemented routes and forms for adding and viewing food items by barcode, including templates for displaying and entering nutritional information. Enhanced the scan workflow to redirect to food item details or entry form. Added admin ability to delete food items. Improved UI for login and scan pages. Updated FoodItem model and form fields for consistency and accuracy.
38 lines
893 B
Python
38 lines
893 B
Python
from flask import Blueprint, render_template, abort, redirect, url_for
|
|
from flask_login import current_user
|
|
from models import FoodItem
|
|
from application import db
|
|
|
|
admin_bp = Blueprint(
|
|
"admin",
|
|
__name__,
|
|
url_prefix="/admin",
|
|
template_folder="templates",
|
|
)
|
|
|
|
|
|
@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():
|
|
items = FoodItem.query.all()
|
|
return render_template("food_items.html", items=items)
|
|
|
|
|
|
@admin_bp.route("/barcode_test", methods=["GET"])
|
|
def barcode_test():
|
|
return render_template("barcode_test.html")
|
|
|
|
|
|
@admin_bp.route("/delete_food/<int:id>", methods=["POST"])
|
|
def delete_food(id):
|
|
item = FoodItem.query.get(id)
|
|
if item:
|
|
db.session.delete(item)
|
|
db.session.commit()
|
|
return redirect(url_for("admin.food_items"))
|