adding food logging, phase 1
This commit is contained in:
@@ -169,6 +169,24 @@ class HydrationGoalForm(forms.ModelForm):
|
||||
widgets = {'daily_water_goal_ml': forms.NumberInput(attrs={'min': 250, 'max': 10000, 'step': 1})}
|
||||
|
||||
|
||||
class FoodGoalForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = UserSettings
|
||||
fields = ('daily_calorie_goal', 'carbohydrate_goal_g', 'protein_goal_g', 'fat_goal_g')
|
||||
labels = {
|
||||
'daily_calorie_goal': 'Daily calorie goal (kcal)',
|
||||
'carbohydrate_goal_g': 'Daily carbohydrate target (g)',
|
||||
'protein_goal_g': 'Daily protein target (g)',
|
||||
'fat_goal_g': 'Daily fat target (g)',
|
||||
}
|
||||
widgets = {
|
||||
'daily_calorie_goal': forms.NumberInput(attrs={'min': 0, 'step': 1}),
|
||||
'carbohydrate_goal_g': forms.NumberInput(attrs={'min': 0, 'step': '0.1'}),
|
||||
'protein_goal_g': forms.NumberInput(attrs={'min': 0, 'step': '0.1'}),
|
||||
'fat_goal_g': forms.NumberInput(attrs={'min': 0, 'step': '0.1'}),
|
||||
}
|
||||
|
||||
|
||||
class WaterIntakeForm(forms.Form):
|
||||
amount_ml = forms.IntegerField(min_value=1, max_value=3000)
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Generated by Django 6.1.1 on 2026-10-03 18:39
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('planner', '0018_fastingsettings_last_phase_notification_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='usersettings',
|
||||
name='carbohydrate_goal_g',
|
||||
field=models.DecimalField(blank=True, decimal_places=1, max_digits=7, null=True, validators=[django.core.validators.MinValueValidator(0)]),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='usersettings',
|
||||
name='daily_calorie_goal',
|
||||
field=models.PositiveIntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='usersettings',
|
||||
name='fat_goal_g',
|
||||
field=models.DecimalField(blank=True, decimal_places=1, max_digits=7, null=True, validators=[django.core.validators.MinValueValidator(0)]),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='usersettings',
|
||||
name='protein_goal_g',
|
||||
field=models.DecimalField(blank=True, decimal_places=1, max_digits=7, null=True, validators=[django.core.validators.MinValueValidator(0)]),
|
||||
),
|
||||
]
|
||||
@@ -120,6 +120,10 @@ class UserSettings(models.Model):
|
||||
daily_water_goal_ml = models.PositiveIntegerField(
|
||||
default=2000, validators=[MinValueValidator(250), MaxValueValidator(10000)],
|
||||
)
|
||||
daily_calorie_goal = models.PositiveIntegerField(null=True, blank=True)
|
||||
carbohydrate_goal_g = models.DecimalField(max_digits=7, decimal_places=1, null=True, blank=True, validators=[MinValueValidator(0)])
|
||||
protein_goal_g = models.DecimalField(max_digits=7, decimal_places=1, null=True, blank=True, validators=[MinValueValidator(0)])
|
||||
fat_goal_g = models.DecimalField(max_digits=7, decimal_places=1, null=True, blank=True, validators=[MinValueValidator(0)])
|
||||
ntfy_url = models.URLField(blank=True)
|
||||
ntfy_enabled = models.BooleanField(default=False)
|
||||
ntfy_last_tested_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<section class="settings-card"><h2>Location & weather</h2><p>Location is optional and private. It is used only to retrieve your forecast.</p><form method="post" data-geolocation-form>{% csrf_token %}<input type="hidden" name="section" value="location">{% for field in profile_form %}<div class="form-field">{{ field.label_tag }}{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{{ field.errors }}</div>{% endfor %}<button class="button button--secondary" type="button" data-use-location>Use my current location</button><span data-location-status role="status"></span><button class="button" type="submit">Save location</button></form></section>
|
||||
<section class="settings-card"><h2>Sick Day Mode</h2><p>Temporarily defer routine work while you recover.</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="sick-day">{% for field in sick_form %}{% if field.name == 'enabled' %}<div class="settings-switch-row"><label class="settings-switch"><span class="settings-switch__copy"><strong>Enable Sick Day Mode</strong><small>Give routine tasks a rest while you recover.</small></span>{{ field }}<span class="settings-switch__track" aria-hidden="true"></span></label>{{ field.errors }}</div>{% else %}<div class="form-field">{{ field.label_tag }}{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{{ field.errors }}</div>{% endif %}{% endfor %}<button class="button" type="submit">Save Sick Day settings</button></form></section>
|
||||
<section class="settings-card"><h2>Hydration</h2><p>Set your daily water goal.</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="hydration">{% for field in hydration_goal_form %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save water goal</button></form></section>
|
||||
<section class="settings-card"><h2>Food</h2><p>Set optional daily nutrition goals. Exercise calories do not change these goals.</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="food">{% for field in food_goal_form %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save food goals</button></form></section>
|
||||
<section class="settings-card" aria-labelledby="ntfy-title">
|
||||
<h2 id="ntfy-title">Notifications / ntfy</h2>
|
||||
<p>Enter your private topic URL, test it, then enable notifications.</p>
|
||||
|
||||
@@ -19,7 +19,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import CreateView, DeleteView, DetailView, ListView, TemplateView, UpdateView
|
||||
|
||||
from .forms import (
|
||||
DailyPlannerForm, FastingSettingsForm, RegistrationForm, SickDaySettingsForm, SleepCheckInForm, TimeZoneSettingsForm,
|
||||
DailyPlannerForm, FastingSettingsForm, FoodGoalForm, RegistrationForm, SickDaySettingsForm, SleepCheckInForm, TimeZoneSettingsForm,
|
||||
BowelHealthCheckInForm, NeckHeadacheCheckInForm, TaskForm, UserSettingsForm, WorkoutForm, HydrationGoalForm, WaterIntakeForm, NtfySettingsForm,
|
||||
)
|
||||
from .models import BowelHealthCheckIn, FastingPeriod, FastingSettings, NeckHeadacheCheckIn, SickDaySettings, SleepCheckIn, Task, ToothBrushing, UserSettings, Workout, WaterIntakeEntry
|
||||
@@ -753,6 +753,7 @@ def user_settings(request):
|
||||
fasting = FastingSettings.objects.filter(user=request.user).first()
|
||||
profile_form = UserSettingsForm(instance=profile)
|
||||
hydration_goal_form = HydrationGoalForm(instance=profile)
|
||||
food_goal_form = FoodGoalForm(instance=profile)
|
||||
sick_form = SickDaySettingsForm(instance=sick_day)
|
||||
fasting_form = FastingSettingsForm(instance=fasting)
|
||||
time_zone_form = TimeZoneSettingsForm(instance=profile)
|
||||
@@ -772,6 +773,12 @@ def user_settings(request):
|
||||
hydration_goal_form.save()
|
||||
messages.success(request, 'Your daily water goal was saved.')
|
||||
return redirect('planner:user-settings')
|
||||
elif section == 'food':
|
||||
food_goal_form = FoodGoalForm(request.POST, instance=profile)
|
||||
if food_goal_form.is_valid():
|
||||
food_goal_form.save()
|
||||
messages.success(request, 'Your food goals were saved.')
|
||||
return redirect('planner:user-settings')
|
||||
elif section == 'ntfy':
|
||||
old_url = profile.ntfy_url
|
||||
ntfy_form = NtfySettingsForm(request.POST, instance=profile)
|
||||
@@ -842,6 +849,7 @@ def user_settings(request):
|
||||
return render(request, 'planner/user_settings.html', {
|
||||
'profile_form': profile_form,
|
||||
'hydration_goal_form': hydration_goal_form,
|
||||
'food_goal_form': food_goal_form,
|
||||
'sick_form': sick_form,
|
||||
'fasting_form': fasting_form,
|
||||
'time_zone_form': time_zone_form,
|
||||
|
||||
Reference in New Issue
Block a user