Add meal v2 flow and user timezone support

Introduces a new add_meal_v2 blueprint with barcode scanning, item search, and improved meal logging UI. Adds user timezone support: login form now captures timezone, User model and database schema updated, and timezone is set on login. Refactors templates and forms to support these changes, and removes the old login template.
This commit is contained in:
2025-08-14 06:08:17 +02:00
parent 7ff345d3a2
commit d78f48710e
14 changed files with 503 additions and 43 deletions

View File

@@ -1,8 +1,8 @@
from flask import Blueprint, request, render_template, redirect, url_for
from flask import Blueprint, render_template, redirect, url_for
from flask_login import current_user, login_user, logout_user
from forms import LoginForm, ChangePasswordForm
from models import User
from application.utils import default_return
from application.utils import default_return, is_valid_timezone
from application import db
bp = Blueprint(
@@ -19,12 +19,16 @@ def login():
form = LoginForm()
if form.validate_on_submit():
assert form.timezone.data
user = User.query.filter_by(username=form.username.data).first()
if user and user.check_password(password=form.password.data):
# User found and password correct
next_page = request.args.get("next") # Get next page if given
tz = form.timezone.data
if is_valid_timezone(tz):
user.set_timezone(tz)
db.session.commit()
login_user(user) # Log in the user
return default_return(next_page=next_page)
return default_return()
else:
pass
# invalid user

View File

@@ -3,7 +3,10 @@
{% block content %}
<div class="container d-flex justify-content-center align-items-center">
<div class="card shadow-sm p-4" style="width: 100%; max-width: 400px;">
<h3 class="mb-4 text-center">Login</h3>
<h3 class="mb-1 text-center">Login</h3>
<p class="text-center text-muted small mb-4">
Your timezone will be saved to show times correctly.
</p>
<form method="post">
{{ form.hidden_tag() }}
@@ -27,10 +30,21 @@
{% endif %}
</div>
{{ form.timezone(id="timezone") }}
<div class="d-grid">
{{ form.submit(class="btn btn-primary btn-lg") }}
</div>
</form>
</div>
</div>
{% endblock%}
{% endblock %}
{% block scripts %}
<script>
document.addEventListener('DOMContentLoaded', () => {
const tzField = document.getElementById('timezone');
tzField.value = Intl.DateTimeFormat().resolvedOptions().timeZone;
});
</script>
{% endblock %}