diff --git a/app.py b/app.py
index e19823f..5b1f5fb 100644
--- a/app.py
+++ b/app.py
@@ -81,4 +81,5 @@ def scan():
# Run
if __name__ == "__main__":
- app.run(host="0.0.0.0", debug=True, ssl_context=("cert.pem", "key.pem"))
+ # app.run(host="0.0.0.0", debug=True, ssl_context=("cert.pem", "key.pem"))
+ app.run(host="0.0.0.0", debug=True)
diff --git a/application/user/routes.py b/application/user/routes.py
index 78e989d..089db2d 100644
--- a/application/user/routes.py
+++ b/application/user/routes.py
@@ -3,6 +3,7 @@ from flask_login import current_user
from application import db
from forms import FoodItemForm, FoodLogForm
from models import FoodItem, FoodLog
+from datetime import datetime, timezone
user_bp = Blueprint(
"user",
@@ -163,8 +164,27 @@ def log_food(item_id):
item_id,
current_user.id,
form.amount.data,
+ part_of_day=0,
)
)
db.session.commit()
return redirect(url_for("user.dashboard"))
return render_template("log_food.html", item_id=item_id, form=form)
+
+
+@user_bp.route("/overview", methods=["GET"])
+def overview():
+ return render_template("overview.html")
+
+
+@user_bp.route("/", methods=["GET"])
+def test():
+ today = datetime.now(timezone.utc).date()
+ logs_today = current_user.food_logs.filter_by(date_=today).all()
+ logs = {0: [], 1: [], 2: [], 3: []}
+ for log in logs_today:
+ logs[log.part_of_day].append(log)
+ print(logs)
+ return render_template(
+ "test.html", date=(today.strftime("%d/%m/%y")), logs=logs
+ )
diff --git a/application/user/templates/overview.html b/application/user/templates/overview.html
new file mode 100644
index 0000000..3424a55
--- /dev/null
+++ b/application/user/templates/overview.html
@@ -0,0 +1,69 @@
+{% extends "base.html" %}
+
+{% block title %}
+Food Nutritional Info
+{% endblock %}
+
+{% block content %}
+
+
+
+
Daily Nutrition Overview
+
+
+
+
+
+
+
+
Calories
+
1,850 / 2,000 kcal
+
+
+
+
+
+
+
+
+
+
Protein
+
120g / 150g
+
+
+
+
+
+
+
+
+
+
Carbs
+
200g / 250g
+
+
+
+
+
+
+
+
+
+
+{% endblock%}
\ No newline at end of file
diff --git a/application/user/templates/test.html b/application/user/templates/test.html
new file mode 100644
index 0000000..227ee9f
--- /dev/null
+++ b/application/user/templates/test.html
@@ -0,0 +1,69 @@
+{% extends "base.html" %}
+
+{% block title %}
+Food Nutritional Info
+{% endblock %}
+
+{% block content %}
+
+
+
+
+
+
+
Daily Overview ({{date}})
+
Summary info here...
+
+
+
+
+
+
+
Detailed Information
+
More content here...
+
+
+
Breakfast
+ {% for log in logs[0] %}
+
{{log.food_item.name}}
+ {% endfor %}
+
+
+
Lunch
+ {% for log in logs[1] %}
+
{{log.food_item.name}}
+ {% endfor %}
+
+
+
Dinner
+ {% for log in logs[2] %}
+
{{log.food_item.name}}
+ {% endfor %}
+
+
+
Snacks
+ {% for log in logs[3] %}
+
{{log.food_item.name}}
+ {% endfor %}
+
+
+
+
+
+
+
+
+
Overview {{date}}
+
+
+
ENERGY
+
PROTEIN
+
CARBS
+
FATS
+
+
+
+
+{% endblock%}
\ No newline at end of file
diff --git a/models.py b/models.py
index e58a4e5..660c967 100644
--- a/models.py
+++ b/models.py
@@ -3,7 +3,7 @@ from werkzeug.security import generate_password_hash, check_password_hash
from application import db
from typing import Optional
from forms import FoodItemForm
-from datetime import datetime, timezone
+from datetime import datetime, timezone, date
class User(UserMixin, db.Model):
@@ -107,17 +107,31 @@ class FoodItem(db.Model):
class FoodLog(db.Model):
__tablename__ = "food_log"
id = db.Column(db.Integer, primary_key=True)
- datetime = db.Column(
+ datetime_created = db.Column(
db.DateTime, default=datetime.now(timezone.utc), nullable=False
)
+ date_ = db.Column(
+ db.Date, default=datetime.now(timezone.utc).date, nullable=False
+ )
food_item_id = db.Column(
db.Integer, db.ForeignKey("food_item.id"), nullable=False
)
+ part_of_day = db.Column(db.Integer, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
amount = db.Column(db.Integer, nullable=False)
- def __init__(self, food_item_id: int, user_id: int, amount: int):
+ def __init__(
+ self,
+ food_item_id: int,
+ user_id: int,
+ amount: int,
+ part_of_day: int,
+ date_: Optional[date] = None,
+ ):
super().__init__()
self.food_item_id = food_item_id
self.user_id = user_id
self.amount = amount
+ if date_ is not None:
+ self.date_ = date_
+ self.part_of_day = part_of_day
diff --git a/seed.py b/seed.py
index acf39d3..8592523 100644
--- a/seed.py
+++ b/seed.py
@@ -22,6 +22,10 @@ with app.app_context():
)
FoodLog.query.delete()
- db.session.add(FoodLog(1, 1, 200))
+ db.session.add(FoodLog(1, 1, 200, 0))
+ db.session.add(FoodLog(1, 1, 200, 1))
+ db.session.add(FoodLog(1, 1, 200, 2))
+ db.session.add(FoodLog(1, 1, 200, 3))
+ db.session.add(FoodLog(1, 1, 100, 1))
db.session.commit()