From be49b66dae4a7868b2dccdefd99fb7bee3e01925 Mon Sep 17 00:00:00 2001 From: Joren de Graaf Date: Sat, 3 Oct 2026 21:44:38 +0200 Subject: [PATCH] adding food logging, polish + demo updates --- main/README.md | 9 +- main/food/static/food/food.css | 17 ++- main/planner/forms.py | 2 +- main/planner/management/commands/seed_demo.py | 114 +++++++++++++++++- .../partials/bowel_health_checkin.html | 6 +- main/planner/tests.py | 47 +++++++- main/planner/views.py | 2 +- 7 files changed, 184 insertions(+), 13 deletions(-) diff --git a/main/README.md b/main/README.md index fd910da..685bdbb 100644 --- a/main/README.md +++ b/main/README.md @@ -26,9 +26,12 @@ Create or reset the public demonstration account and its dummy data with: ``` The command resets only the `demo` account (default password: `demo`). It creates -sample parent/subtasks, workouts, pain and sleep check-ins, and a 16-hour fasting -schedule. It is idempotent: running it again removes demo-only edits and restores -the same baseline. Use `--username` and `--password` to override the credentials. +sample parent/subtasks, workouts, pain, sleep, bowel, tooth-brushing and water +check-ins, a 16-hour fasting schedule, and a food diary with nutrition goals, +six local foods, favourites, custom portions, and entries across several days. +Food seeding makes no external API requests. It is idempotent: running it again +removes demo-only edits and restores the same baseline. Use `--username` and +`--password` to override the credentials. A daily systemd timer template is provided in `main/deploy/systemd/`. Adjust the `User`, `WorkingDirectory`, and `ExecStart` paths in the service file if needed, diff --git a/main/food/static/food/food.css b/main/food/static/food/food.css index 20b95a8..2518256 100644 --- a/main/food/static/food/food.css +++ b/main/food/static/food/food.css @@ -1,7 +1,22 @@ -.food-page{max-width:1180px;margin:0 auto;padding:1.5rem 0 4rem}.food-heading,.food-meal-heading{display:flex;justify-content:space-between;align-items:center;gap:1rem}.food-heading nav{display:flex;gap:.5rem;align-items:center}.food-heading nav a,.food-add-meal{display:inline-flex;align-items:center;justify-content:center;min-width:44px;min-height:44px;border:1px solid currentColor;border-radius:50%;text-decoration:none}.food-layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(290px,340px);gap:2rem;align-items:start}.food-sidebar{position:sticky;top:1rem}.food-card{background:var(--surface,#222);border:1px solid var(--border,#555);border-radius:1.2rem;padding:1.2rem;margin-bottom:1rem}.food-card h2,.food-card h3{margin:.1rem 0 .5rem}.food-remaining{font-size:1.45rem;font-weight:700}.food-progress{height:.65rem;background:#7776;border-radius:2rem;overflow:hidden}.food-progress span{display:block;height:100%;background:#62bd70;border-radius:inherit}.food-macros{display:grid;gap:.7rem}.food-macro{display:flex;align-items:center;gap:1rem}.food-macro p{margin:.15rem 0}.food-ring{--accent:#d45b8b;flex:none;width:74px;height:74px;border-radius:50%;display:grid;place-items:center;background:conic-gradient(var(--accent) var(--progress,0%),#7776 0)}.food-ring span{display:grid;place-items:center;width:60px;height:60px;background:var(--surface,#222);border-radius:50%;font-weight:700}.food-macro--blue{--accent:#53a9e7}.food-macro--orange{--accent:#e87952}.food-meal{margin-bottom:1.5rem}.food-meal-heading h2{margin:0}.food-meal-heading p{margin:.1rem 0;color:#62bd70}.food-add-meal{color:#62bd70;font-size:1.8rem}.food-entry-list,.food-product-list{list-style:none;margin:.8rem 0;padding:0}.food-entry,.food-product-list li{background:var(--surface,#222);border:1px solid var(--border,#555);padding:1rem;border-radius:1rem;margin:.4rem 0}.food-entry{display:flex;align-items:center;justify-content:space-between;gap:1rem}.food-entry-main{display:flex;align-items:center;gap:.8rem;min-width:0}.food-entry-main img{width:64px;height:64px;object-fit:contain;background:white;border-radius:.6rem}.food-entry-main strong,.food-entry-main span,.food-entry-main small{display:block}.food-entry-main small,.food-entry-main span,.food-empty{opacity:.75}.food-form-page{max-width:620px;margin:1.5rem auto 4rem}.food-form-page .food-card{margin-top:1rem}.food-search{display:flex;flex-wrap:wrap;gap:.6rem;align-items:center}.food-search input{min-width:180px;flex:1}.food-product-list a{display:block;min-height:44px;align-content:center}.food-form-page details dl{display:grid;grid-template-columns:1fr 1fr;gap:.4rem}.food-form-page details dd{margin:0;text-align:right}@media(max-width:760px){.food-layout{display:flex;flex-direction:column-reverse;gap:1rem}.food-sidebar{position:static;width:100%}.food-macros{grid-template-columns:repeat(3,minmax(0,1fr));gap:.4rem}.food-macro{display:block;padding:.65rem;text-align:center}.food-ring{margin:auto;width:58px;height:58px}.food-ring span{width:46px;height:46px;font-size:.8rem}.food-macro h3{font-size:.9rem;overflow-wrap:anywhere}.food-macro p{font-size:.8rem}.food-heading h1{font-size:1.5rem}.food-page{padding-top:.5rem}}@media(max-width:400px){.food-macros{grid-template-columns:1fr}.food-macro{display:flex;text-align:left}.food-ring{margin:0}}@media(prefers-reduced-motion:reduce){.food-page *{scroll-behavior:auto!important;animation:none!important;transition:none!important}} +/* Food surfaces follow the shared Tasknest light and dark appearance setting. */ +body[data-theme="light"]{--food-surface:#fff;--food-border:#dfe4dc;--food-ink:#25292e;--food-muted:#626a70;--food-progress-track:#e2e7e1;--food-ring-track:#e2e7e1;--food-green:#277a46} +body[data-theme="dark"]{--food-surface:#202923;--food-border:#3b473f;--food-ink:#edf5ef;--food-muted:#b8c3bb;--food-progress-track:#48554b;--food-ring-track:#48554b;--food-green:#75cf88} +.food-page{max-width:1180px;margin:0 auto;padding:1.5rem 0 4rem}.food-heading,.food-meal-heading{display:flex;justify-content:space-between;align-items:center;gap:1rem}.food-heading nav{display:flex;gap:.5rem;align-items:center}.food-heading nav a,.food-add-meal{display:inline-flex;align-items:center;justify-content:center;min-width:44px;min-height:44px;border:1px solid currentColor;border-radius:50%;text-decoration:none}.food-layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(290px,340px);gap:2rem;align-items:start}.food-sidebar{position:sticky;top:1rem}.food-card{background:var(--food-surface);border:1px solid var(--food-border);border-radius:1.2rem;padding:1.2rem;margin-bottom:1rem}.food-card h2,.food-card h3{margin:.1rem 0 .5rem}.food-remaining{font-size:1.45rem;font-weight:700}.food-progress{height:.65rem;background:var(--food-progress-track);border-radius:2rem;overflow:hidden}.food-progress span{display:block;height:100%;background:#62bd70;border-radius:inherit}.food-macros{display:grid;gap:.7rem}.food-macro{display:flex;align-items:center;gap:1rem}.food-macro p{margin:.15rem 0}.food-ring{--accent:#d45b8b;flex:none;width:74px;height:74px;border-radius:50%;display:grid;place-items:center;background:conic-gradient(var(--accent) var(--progress,0%),var(--food-ring-track) 0)}.food-ring span{display:grid;place-items:center;width:60px;height:60px;background:var(--food-surface);border-radius:50%;font-weight:700}.food-macro--blue{--accent:#53a9e7}.food-macro--orange{--accent:#e87952}.food-meal{margin-bottom:1.5rem}.food-meal-heading h2{margin:0}.food-meal-heading p{margin:.1rem 0;color:#62bd70}.food-add-meal{color:#62bd70;font-size:1.8rem}.food-entry-list,.food-product-list{list-style:none;margin:.8rem 0;padding:0}.food-entry,.food-product-list li{background:var(--food-surface);border:1px solid var(--food-border);padding:1rem;border-radius:1rem;margin:.4rem 0}.food-entry{display:flex;align-items:center;justify-content:space-between;gap:1rem}.food-entry-main{display:flex;align-items:center;gap:.8rem;min-width:0}.food-entry-main img{width:64px;height:64px;object-fit:contain;background:white;border-radius:.6rem}.food-entry-main strong,.food-entry-main span,.food-entry-main small{display:block}.food-entry-main small,.food-entry-main span,.food-empty{opacity:.75}.food-form-page{max-width:620px;margin:1.5rem auto 4rem}.food-form-page .food-card{margin-top:1rem}.food-search{display:flex;flex-wrap:wrap;gap:.6rem;align-items:center}.food-search input{min-width:180px;flex:1}.food-product-list a{display:block;min-height:44px;align-content:center}.food-form-page details dl{display:grid;grid-template-columns:1fr 1fr;gap:.4rem}.food-form-page details dd{margin:0;text-align:right}@media(max-width:760px){.food-layout{display:flex;flex-direction:column-reverse;gap:1rem}.food-sidebar{position:static;width:100%}.food-macros{grid-template-columns:repeat(3,minmax(0,1fr));gap:.4rem}.food-macro{display:block;padding:.65rem;text-align:center}.food-ring{margin:auto;width:58px;height:58px}.food-ring span{width:46px;height:46px;font-size:.8rem}.food-macro h3{font-size:.9rem;overflow-wrap:anywhere}.food-macro p{font-size:.8rem}.food-heading h1{font-size:1.5rem}.food-page{padding-top:.5rem}}@media(max-width:400px){.food-macros{grid-template-columns:1fr}.food-macro{display:flex;text-align:left}.food-ring{margin:0}}@media(prefers-reduced-motion:reduce){.food-page *{scroll-behavior:auto!important;animation:none!important;transition:none!important}} .food-product-image{display:block;max-width:180px;max-height:180px;object-fit:contain;background:#fff;border-radius:1rem;margin:0 auto 1rem} .food-tabs,.food-actions{display:flex;gap:.5rem;flex-wrap:wrap;margin:1rem 0}.food-tabs a{padding:.55rem .9rem;border-radius:2rem;border:1px solid currentColor;text-decoration:none}.food-tabs a[aria-current=page]{background:#62bd70;color:#111;border-color:#62bd70}.food-product-list a,.food-result-button{display:flex;align-items:center;gap:.8rem;width:100%;text-align:left}.food-product-list img{width:58px;height:58px;object-fit:contain;background:#fff;border-radius:.6rem}.food-product-list strong,.food-product-list small{display:block}.food-result-button{border:0;background:none;color:inherit;font:inherit;cursor:pointer;min-height:44px}.food-barcode-form{display:flex;align-items:center;gap:.5rem;flex-wrap:wrap;margin:1rem 0}.food-barcode-form input{min-width:130px;flex:1}.food-attribution{font-size:.85rem;opacity:.8} .food-scanner{max-width:620px;margin:1.5rem auto 6rem}.food-scanner-header{display:flex;align-items:center;gap:1rem}.food-scanner-header a{display:grid;place-items:center;min-width:44px;min-height:44px;font-size:2rem;text-decoration:none}.food-camera-frame{position:relative;aspect-ratio:4/3;background:#111;border-radius:1rem;overflow:hidden}.food-camera-frame video{width:100%;height:100%;object-fit:cover}.food-scan-guide{position:absolute;inset:25% 10%;border:3px solid #62bd70;border-radius:.8rem;pointer-events:none}.food-mobile-switch{display:none}@media(max-width:760px){.food-mobile-switch{position:fixed;bottom:env(safe-area-inset-bottom,0px);left:50%;transform:translateX(-50%);display:flex;gap:.3rem;background:#222;color:#fff;padding:.35rem;border-radius:2rem;z-index:20;box-shadow:0 2px 15px #0008}.food-mobile-switch a,.food-mobile-switch span{display:grid;place-items:center;min-width:110px;min-height:44px;padding:.2rem 1rem;border-radius:2rem;color:inherit;text-decoration:none}.food-mobile-switch [aria-current=page]{background:#555}} .food-detail-title{display:flex;align-items:center;justify-content:space-between;gap:1rem}.food-favourite-form{flex:none}.food-favourite{min-width:44px;min-height:44px;border:0;background:none;color:#62bd70;font-size:2rem;cursor:pointer}.food-product-list li{display:flex;align-items:center;justify-content:space-between;gap:.5rem}.food-product-list li>a{flex:1;min-width:0}.food-product-list li>.food-favourite-form{margin:0} /* V1 polish: keep the date and search titles from crowding the useful content. */ .food-heading{align-items:end;margin-bottom:1.1rem}.food-heading h1{font-size:clamp(2rem,3.2vw,3.2rem);line-height:1.08;margin:.25rem 0 0}.food-heading nav a:nth-child(2){border-radius:999px;padding:0 1rem}.food-form-page h1{font-size:clamp(2.3rem,4vw,3.8rem);line-height:1.05;margin:.45rem 0 1rem;overflow-wrap:anywhere}.food-product-list li>a{text-decoration:none}.food-product-list li>a:hover strong,.food-product-list li>a:focus-visible strong{text-decoration:underline}.food-list-empty{border-style:dashed!important;opacity:.72}.food-entry>a{min-width:44px;min-height:44px;display:grid;place-items:center}.food-entry-main strong{overflow-wrap:anywhere}.food-export{margin-top:1.25rem}.food-export p{margin:.3rem 0 1rem;opacity:.75}.food-export-actions{display:flex;gap:.6rem;flex-wrap:wrap}.food-export-actions a{display:inline-flex;align-items:center;min-height:44px;padding:.55rem .8rem;border:1px solid currentColor;border-radius:999px;text-decoration:none}.food-export-actions a:hover,.food-export-actions a:focus-visible{background:#62bd7028}.food-entry-form{display:grid;gap:1rem}.food-entry-form [data-food-custom-fields],.food-entry-form [data-food-save-fields]{display:grid;gap:1rem}.food-entry-form .settings-switch-row{margin:.25rem 0}.food-edit-nutrition p{line-height:1.55}.food-edit-nutrition details{margin-top:.7rem}.food-entry-form .settings-switch input[type=checkbox]{min-height:0;padding:0;border:0;border-radius:0}.food-entry-form .settings-switch__copy strong{font-weight:700}.food-form-page .food-card .form-field label{line-height:1.35}@media(max-width:760px){.food-heading{align-items:start}.food-heading nav{flex:none}.food-heading nav a:nth-child(2){padding:0 .6rem}.food-heading h1{font-size:clamp(1.55rem,6vw,2.2rem)}.food-export{margin-top:.5rem}} + +.food-card,.food-entry,.food-product-list li{color:var(--food-ink);background:var(--food-surface);border-color:var(--food-border)} +.food-ring span{color:var(--food-ink);background:var(--food-surface)} +.food-meal-heading p,.food-add-meal,.food-favourite{color:var(--food-green)} +.food-progress span{background:var(--food-green)} +.food-entry-main span,.food-entry-main small,.food-card>p:not(.food-remaining),.food-attribution{color:var(--food-muted);opacity:1} +.food-entry-main strong,.food-card h2,.food-card h3,.food-remaining{color:var(--food-ink)} +.food-tabs a[aria-current=page]{background:var(--food-green);border-color:var(--food-green);color:#fff} +.food-export-actions a{color:var(--food-ink);border-color:var(--food-border)} +.food-export-actions a:hover,.food-export-actions a:focus-visible{background:var(--food-progress-track)} +.food-macro p,.food-product-list small{color:var(--food-muted)} +body[data-theme="dark"] .food-tabs a[aria-current=page]{color:#102317} diff --git a/main/planner/forms.py b/main/planner/forms.py index e0af00d..8c1134b 100644 --- a/main/planner/forms.py +++ b/main/planner/forms.py @@ -254,7 +254,7 @@ class BowelHealthCheckInForm(forms.ModelForm): **{f'{period}_severity': forms.NumberInput(attrs={'min': 0, 'max': 10, 'inputmode': 'numeric'}) for period in ('morning', 'afternoon', 'evening')}, **{f'{period}_note': forms.Textarea(attrs={'maxlength': 500, 'rows': 2}) for period in ('morning', 'afternoon', 'evening')}, } - labels = {'check_in_date': 'Date', **{f'{period}_severity': 'Bowel symptoms (0–10)' for period in ('morning', 'afternoon', 'evening')}, **{f'{period}_note': 'Note (optional)' for period in ('morning', 'afternoon', 'evening')}} + labels = {'check_in_date': 'Date', **{f'{period}_severity': 'Gut symptoms (0–10)' for period in ('morning', 'afternoon', 'evening')}, **{f'{period}_note': 'Note (optional)' for period in ('morning', 'afternoon', 'evening')}} def __init__(self, *args, user=None, **kwargs): super().__init__(*args, **kwargs) diff --git a/main/planner/management/commands/seed_demo.py b/main/planner/management/commands/seed_demo.py index 08995b7..9b0af4a 100644 --- a/main/planner/management/commands/seed_demo.py +++ b/main/planner/management/commands/seed_demo.py @@ -1,12 +1,16 @@ """Reset a safe, self-contained demo account with representative Tasknest data.""" -from datetime import time, timedelta +from datetime import datetime, time, timedelta +from decimal import Decimal from django.contrib.auth import get_user_model from django.core.management.base import BaseCommand from django.db import transaction from django.utils import timezone +from food.models import FoodFavourite, FoodLogEntry, FoodPortion, FoodProduct, MealType, Unit + from planner.models import ( + BowelHealthCheckIn, FastingPause, FastingPeriod, FastingSettings, @@ -14,12 +18,76 @@ from planner.models import ( SickDaySettings, SleepCheckIn, Task, + ToothBrushing, UserSettings, + WaterIntakeEntry, Workout, WorkoutCompletion, ) from planner.services.fasting import synchronize_fasting_periods -from planner.timezones import DEFAULT_TIME_ZONE, localdate_for_user +from planner.timezones import DEFAULT_TIME_ZONE, localdate_for_user, timezone_for_user + + +def _seed_food(user, today): + """Create local demo foods without network calls or third-party assets.""" + product_data = ( + ('Greek yoghurt', 'Demo dairy', Unit.GRAM, '73', '4', '8', '2', '0'), + ('Banana', '', Unit.GRAM, '89', '22.8', '1.1', '0.3', '2.6'), + ('Wholegrain sandwich', 'Demo bakery', Unit.GRAM, '250', '42', '10', '4', '6'), + ('Tomato soup', 'Home made', Unit.MILLILITRE, '35', '5', '1.2', '1', None), + ('Pasta with vegetables', 'Home made', Unit.GRAM, '145', '23', '5', '3', '2.5'), + ('Almonds', '', Unit.GRAM, '579', '10', '21', '50', '12.5'), + ) + products = {} + for name, brand, unit, kcal, carbs, protein, fat, fibre in product_data: + products[name] = FoodProduct.objects.create( + owner=user, product_name=name, brand=brand, base_unit=unit, + energy_kcal_100=Decimal(kcal), carbohydrates_100=Decimal(carbs), + protein_100=Decimal(protein), fat_100=Decimal(fat), + fibre_100=Decimal(fibre) if fibre is not None else None, + source=FoodProduct.Source.MANUAL, + ) + + yoghurt = products['Greek yoghurt'] + soup = products['Tomato soup'] + for product in (yoghurt, soup): + FoodFavourite.objects.create(user=user, product=product) + FoodPortion.objects.create(user=user, product=yoghurt, label='My bowl', + amount=Decimal('250'), unit=Unit.GRAM, is_default=True) + FoodPortion.objects.create(user=user, product=soup, label='One mug', + amount=Decimal('250'), unit=Unit.MILLILITRE) + + def log(days_ago, meal, name, amount, label=''): + product = products[name] + amount = Decimal(str(amount)) + factor = amount / Decimal('100') + def consumed(value): + return (value * factor).quantize(Decimal('0.001')) if value is not None else None + FoodLogEntry.objects.create( + user=user, date=today - timedelta(days=days_ago), meal=meal, product=product, + product_name_snapshot=product.product_name, brand_snapshot=product.brand, + portion_label_snapshot=label, amount=amount, unit=product.base_unit, + calories_kcal=consumed(product.energy_kcal_100), + carbohydrates_g=consumed(product.carbohydrates_100), + protein_g=consumed(product.protein_100), fat_g=consumed(product.fat_100), + fibre_g=consumed(product.fibre_100), source=product.source, + ) + + for days_ago, meal, name, amount, label in ( + (0, MealType.BREAKFAST, 'Greek yoghurt', 250, 'My bowl'), + (0, MealType.BREAKFAST, 'Banana', 120, ''), + (0, MealType.LUNCH, 'Wholegrain sandwich', 100, ''), + (0, MealType.LUNCH, 'Tomato soup', 250, 'One mug'), + (0, MealType.DINNER, 'Pasta with vegetables', 180, ''), + (0, MealType.SNACKS, 'Almonds', 30, ''), + (1, MealType.BREAKFAST, 'Greek yoghurt', 200, ''), + (1, MealType.DINNER, 'Pasta with vegetables', 200, ''), + (2, MealType.LUNCH, 'Wholegrain sandwich', 100, ''), + (5, MealType.SNACKS, 'Banana', 100, ''), + ): + log(days_ago, meal, name, amount, label) + + return len(products), 10 class Command(BaseCommand): @@ -46,6 +114,14 @@ class Command(BaseCommand): profile.longitude = '4.904100' profile.onboarding_enabled = False profile.onboarding_step = 0 + profile.daily_water_goal_ml = 2000 + profile.daily_calorie_goal = 2000 + profile.carbohydrate_goal_g = Decimal('250.0') + profile.protein_goal_g = Decimal('100.0') + profile.fat_goal_g = Decimal('70.0') + profile.ntfy_url = '' + profile.ntfy_enabled = False + profile.ntfy_last_tested_at = None profile.save() SickDaySettings.objects.update_or_create(user=user, defaults={'enabled': False, 'recovery_date': None}) @@ -56,10 +132,37 @@ class Command(BaseCommand): SleepCheckIn.objects.filter(user=user).delete() FastingPause.objects.filter(user=user).delete() FastingPeriod.objects.filter(user=user).delete() + WaterIntakeEntry.objects.filter(user=user).delete() + ToothBrushing.objects.filter(user=user).delete() + BowelHealthCheckIn.objects.filter(user=user).delete() + FoodLogEntry.objects.filter(user=user).delete() + FoodFavourite.objects.filter(user=user).delete() + FoodPortion.objects.filter(user=user).delete() + FoodProduct.objects.filter(owner=user).delete() now = timezone.now() today = localdate_for_user(user, now) + ToothBrushing.objects.create(user=user, date=today - timedelta(days=1), morning=True, evening=True) + ToothBrushing.objects.create(user=user, date=today, morning=True, evening=False) + for days_ago, severity, note in ( + (2, 3, 'A slightly unsettled day.'), + (1, 1, 'Feeling better after lunch.'), + (0, 0, 'Feeling well today.'), + ): + BowelHealthCheckIn.objects.create( + user=user, check_in_date=today - timedelta(days=days_ago), + morning_severity=severity, morning_note=note, + afternoon_severity=max(0, severity - 1), + evening_severity=max(0, severity - 1), + ) + yesterday = today - timedelta(days=1) + local_zone = timezone_for_user(user) + for hour, amount in ((9, 350), (12, 500), (16, 400)): + WaterIntakeEntry.objects.create(user=user, amount_ml=amount, + recorded_at=timezone.make_aware(datetime.combine(yesterday, time(hour, 0)), local_zone)) + WaterIntakeEntry.objects.create(user=user, amount_ml=350, recorded_at=now) + laundry = Task.objects.create( owner=user, title='Run the washing machine', @@ -168,11 +271,16 @@ class Command(BaseCommand): 'fasting_start_time': time(20, 0), 'fasting_duration_minutes': 16 * 60, 'tracking_started_at': now - timedelta(days=3), + 'last_phase_notification_at': None, }, ) synchronize_fasting_periods(fasting, now) + food_products, food_entries = _seed_food(user, today) + verb = 'Created' if created else 'Reset' self.stdout.write(self.style.SUCCESS( - f'{verb} demo user {username!r}: 5 tasks, 2 workouts, 4 pain check-ins, and 4 sleep check-ins.' + f'{verb} demo user {username!r}: 5 tasks, 2 workouts, 4 pain check-ins, ' + f'4 sleep check-ins, 3 bowel check-ins, 4 water entries, ' + f'{food_products} foods, and {food_entries} food logs.' )) diff --git a/main/planner/templates/planner/partials/bowel_health_checkin.html b/main/planner/templates/planner/partials/bowel_health_checkin.html index 164e9ce..9d75bab 100644 --- a/main/planner/templates/planner/partials/bowel_health_checkin.html +++ b/main/planner/templates/planner/partials/bowel_health_checkin.html @@ -1,5 +1,5 @@
-

Daily wellbeing

Bowel health

Record how your bowels felt during each part of the day. Choose a date below to edit an entry.

+

Daily wellbeing

Gut health

Record how your gut felt during each part of the day. Choose a date below to edit an entry.

{% csrf_token %}{% if bowel_form.non_field_errors %}
{{ bowel_form.non_field_errors }}
{% endif %}
{{ bowel_form.check_in_date.label_tag }}{{ bowel_form.check_in_date }}{{ bowel_form.check_in_date.errors }}
@@ -7,11 +7,11 @@

Morning

{{ bowel_form.morning_severity.label_tag }}{{ bowel_form.morning_severity }}{{ bowel_form.morning_severity.errors }}
{{ bowel_form.morning_note.label_tag }}{{ bowel_form.morning_note }}{{ bowel_form.morning_note.errors }}

Afternoon

{{ bowel_form.afternoon_severity.label_tag }}{{ bowel_form.afternoon_severity }}{{ bowel_form.afternoon_severity.errors }}
{{ bowel_form.afternoon_note.label_tag }}{{ bowel_form.afternoon_note }}{{ bowel_form.afternoon_note.errors }}

Evening

{{ bowel_form.evening_severity.label_tag }}{{ bowel_form.evening_severity }}{{ bowel_form.evening_severity.errors }}
{{ bowel_form.evening_note.label_tag }}{{ bowel_form.evening_note }}{{ bowel_form.evening_note.errors }}
-
+
←

{{ bowel_selected_date|date:'F Y' }}

→ -
+

M = morning · A = afternoon · E = evening · 0 = no symptoms · 10 = worst symptoms

diff --git a/main/planner/tests.py b/main/planner/tests.py index 73fad91..c49ad95 100644 --- a/main/planner/tests.py +++ b/main/planner/tests.py @@ -9,7 +9,8 @@ from django.utils import timezone from django.urls import reverse from .models import FastingPause, FastingPeriod, FastingSettings, SickDaySettings, Task -from .models import UserSettings, WaterIntakeEntry +from .models import BowelHealthCheckIn, ToothBrushing, UserSettings, WaterIntakeEntry +from .timezones import localdate_for_user from .services.hydration import hydration_context from .forms import DAILY_FASTING_DURATION_CHOICES, FastingSettingsForm from .services.deferrals import ( @@ -1025,10 +1026,17 @@ class OnboardingTests(TestCase): class DemoSeedCommandTests(TestCase): def test_command_creates_and_repeatedly_restores_only_the_demo_account(self): + from food.models import FoodFavourite, FoodLogEntry, FoodPortion, FoodProduct, MealType, Unit + other = get_user_model().objects.create_user(username="private-user", password="password") private_task = Task.objects.create( owner=other, title="Private task", scheduled_for=timezone.localdate() ) + private_food = FoodProduct.objects.create(owner=other, product_name='Private snack') + private_food_entry = FoodLogEntry.objects.create( + user=other, date=timezone.localdate(), meal=MealType.SNACKS, + product=private_food, product_name_snapshot='Private snack', amount=100, unit=Unit.GRAM, + ) call_command("seed_demo") @@ -1039,17 +1047,54 @@ class DemoSeedCommandTests(TestCase): self.assertEqual(NeckHeadacheCheckIn.objects.filter(user=demo).count(), 4) self.assertEqual(SleepCheckIn.objects.filter(user=demo).count(), 4) self.assertTrue(FastingSettings.objects.get(user=demo).enabled) + self.assertEqual(FoodProduct.objects.filter(owner=demo).count(), 6) + self.assertEqual(FoodLogEntry.objects.filter(user=demo).count(), 10) + self.assertEqual(FoodFavourite.objects.filter(user=demo).count(), 2) + self.assertEqual(FoodPortion.objects.filter(user=demo).count(), 2) + self.assertEqual(WaterIntakeEntry.objects.filter(user=demo).count(), 4) + self.assertEqual(ToothBrushing.objects.filter(user=demo).count(), 2) + self.assertEqual(BowelHealthCheckIn.objects.filter(user=demo).count(), 3) profile = UserSettings.objects.get(user=demo) self.assertEqual(profile.time_zone, "Europe/Amsterdam") self.assertFalse(profile.onboarding_enabled) + self.assertEqual(profile.daily_calorie_goal, 2000) + self.assertEqual(profile.carbohydrate_goal_g, 250) + self.assertEqual(profile.protein_goal_g, 100) + self.assertEqual(profile.fat_goal_g, 70) + self.assertFalse(profile.ntfy_enabled) + today = localdate_for_user(demo) + self.assertEqual(FoodLogEntry.objects.filter(user=demo, date=today).count(), 6) + self.assertEqual(set(FoodLogEntry.objects.filter(user=demo, date=today).values_list('meal', flat=True)), + set(MealType.values)) + bowl = FoodPortion.objects.get(user=demo, label='My bowl') + self.assertTrue(bowl.is_default) + self.assertEqual(FoodLogEntry.objects.get(user=demo, date=today, portion_label_snapshot='My bowl').calories_kcal, 182.5) self.assertTrue(Task.objects.filter(owner=demo, title="Fold the clothes", parent_task__isnull=False).exists()) Task.objects.create(owner=demo, title="Temporary demo edit", scheduled_for=timezone.localdate()) + FoodProduct.objects.create(owner=demo, product_name='Temporary demo food') + banana = FoodProduct.objects.get(owner=demo, product_name='Banana') + FoodFavourite.objects.create(user=demo, product=banana) + FoodPortion.objects.create(user=demo, product=banana, label='Temporary portion', amount=100, unit=Unit.GRAM) + FoodLogEntry.objects.filter(user=demo, portion_label_snapshot='My bowl').update(product_name_snapshot='Edited demo food') + profile.ntfy_url = 'https://ntfy.example.com/old-demo-topic' + profile.ntfy_enabled = True + profile.save() call_command("seed_demo") self.assertEqual(Task.objects.filter(owner=demo).count(), 5) self.assertFalse(Task.objects.filter(owner=demo, title="Temporary demo edit").exists()) + self.assertEqual(FoodProduct.objects.filter(owner=demo).count(), 6) + self.assertEqual(FoodLogEntry.objects.filter(user=demo).count(), 10) + self.assertFalse(FoodLogEntry.objects.filter(user=demo, product_name_snapshot='Edited demo food').exists()) + self.assertEqual(FoodFavourite.objects.filter(user=demo).count(), 2) + self.assertEqual(FoodPortion.objects.filter(user=demo).count(), 2) + profile.refresh_from_db() + self.assertFalse(profile.ntfy_enabled) + self.assertEqual(profile.ntfy_url, '') self.assertTrue(Task.objects.filter(pk=private_task.pk, owner=other).exists()) + self.assertTrue(FoodProduct.objects.filter(pk=private_food.pk, owner=other).exists()) + self.assertTrue(FoodLogEntry.objects.filter(pk=private_food_entry.pk, user=other).exists()) class UserTimeZoneTests(TestCase): diff --git a/main/planner/views.py b/main/planner/views.py index f946b4a..5bcd97f 100644 --- a/main/planner/views.py +++ b/main/planner/views.py @@ -60,7 +60,7 @@ ONBOARDING_STEPS = ( { 'target': 'wellbeing', 'title': 'Keep a lightweight wellbeing record', - 'copy': 'Open Health for pain, sleep, and bowel check-ins, with calendars that make past days easy to revisit.', + 'copy': 'Open Health for pain, sleep, and gut health check-ins, with calendars that make past days easy to revisit.', }, { 'target': 'fasting',