added demo account data seeding
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
"""Reset a safe, self-contained demo account with representative Tasknest data."""
|
||||
from datetime import time, timedelta
|
||||
|
||||
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 planner.models import (
|
||||
FastingPause,
|
||||
FastingPeriod,
|
||||
FastingSettings,
|
||||
NeckHeadacheCheckIn,
|
||||
SickDaySettings,
|
||||
SleepCheckIn,
|
||||
Task,
|
||||
UserSettings,
|
||||
Workout,
|
||||
WorkoutCompletion,
|
||||
)
|
||||
from planner.services.fasting import synchronize_fasting_periods
|
||||
from planner.timezones import DEFAULT_TIME_ZONE, localdate_for_user
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Reset a demo account with safe, representative sample data.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--username', default='demo', help='Demo username (default: demo).')
|
||||
parser.add_argument('--password', default='demo', help='Demo password (default: demo).')
|
||||
|
||||
@transaction.atomic
|
||||
def handle(self, *args, **options):
|
||||
username = options['username']
|
||||
password = options['password']
|
||||
user_model = get_user_model()
|
||||
user, created = user_model.objects.get_or_create(username=username)
|
||||
user.set_password(password)
|
||||
user.is_active = True
|
||||
user.save()
|
||||
|
||||
profile, _ = UserSettings.objects.get_or_create(user=user)
|
||||
profile.time_zone = DEFAULT_TIME_ZONE
|
||||
profile.latitude = '52.367600'
|
||||
profile.longitude = '4.904100'
|
||||
profile.onboarding_enabled = False
|
||||
profile.onboarding_step = 0
|
||||
profile.save()
|
||||
SickDaySettings.objects.update_or_create(user=user, defaults={'enabled': False, 'recovery_date': None})
|
||||
|
||||
# Reset only demo-owned records. Cascades remove task weather shifts and workout completions.
|
||||
Task.objects.filter(owner=user).delete()
|
||||
Workout.objects.filter(owner=user).delete()
|
||||
NeckHeadacheCheckIn.objects.filter(user=user).delete()
|
||||
SleepCheckIn.objects.filter(user=user).delete()
|
||||
FastingPause.objects.filter(user=user).delete()
|
||||
FastingPeriod.objects.filter(user=user).delete()
|
||||
|
||||
now = timezone.now()
|
||||
today = localdate_for_user(user, now)
|
||||
|
||||
laundry = Task.objects.create(
|
||||
owner=user,
|
||||
title='Run the washing machine',
|
||||
description='A simple parent task to demonstrate dependencies.',
|
||||
category='Home',
|
||||
priority=Task.Priority.HIGH,
|
||||
estimated_duration_minutes=10,
|
||||
scheduled_for=today,
|
||||
)
|
||||
Task.objects.create(
|
||||
owner=user,
|
||||
title='Fold the clothes',
|
||||
description='This appears after the washing-machine task is complete.',
|
||||
category='Home',
|
||||
priority=Task.Priority.MEDIUM,
|
||||
estimated_duration_minutes=15,
|
||||
scheduled_for=today,
|
||||
parent_task=laundry,
|
||||
)
|
||||
finished_parent = Task.objects.create(
|
||||
owner=user,
|
||||
title='Plan this week',
|
||||
category='Planning',
|
||||
priority=Task.Priority.MEDIUM,
|
||||
estimated_duration_minutes=20,
|
||||
scheduled_for=today,
|
||||
is_completed=True,
|
||||
)
|
||||
Task.objects.create(
|
||||
owner=user,
|
||||
title='Choose tomorrow’s priority',
|
||||
category='Planning',
|
||||
priority=Task.Priority.HIGH,
|
||||
estimated_duration_minutes=5,
|
||||
scheduled_for=today,
|
||||
parent_task=finished_parent,
|
||||
)
|
||||
Task.objects.create(
|
||||
owner=user,
|
||||
title='Take a neighbourhood walk',
|
||||
description='An outdoor task with a weather preference.',
|
||||
category='Health',
|
||||
priority=Task.Priority.LOW,
|
||||
estimated_duration_minutes=30,
|
||||
scheduled_for=today,
|
||||
is_outdoor=True,
|
||||
weather_profile=Task.WeatherProfile.DRY,
|
||||
)
|
||||
|
||||
daily_stretch = Workout.objects.create(
|
||||
owner=user,
|
||||
name='Morning stretch',
|
||||
scheduled_for=today - timedelta(days=7),
|
||||
is_daily_recurring=True,
|
||||
duration_minutes=10,
|
||||
calories_burned=35,
|
||||
)
|
||||
WorkoutCompletion.objects.create(workout=daily_stretch, completed_on=today)
|
||||
Workout.objects.create(
|
||||
owner=user,
|
||||
name='Easy cycle',
|
||||
scheduled_for=today,
|
||||
is_completed=False,
|
||||
duration_minutes=30,
|
||||
calories_burned=180,
|
||||
)
|
||||
|
||||
for days_ago, neck, headache, physiotherapy, note in (
|
||||
(3, 3, 1, False, 'A little stiff after desk work.'),
|
||||
(2, 1, 0, True, 'Physiotherapy session.'),
|
||||
(1, 2, 1, False, ''),
|
||||
(0, 1, 0, False, 'Feeling better today.'),
|
||||
):
|
||||
NeckHeadacheCheckIn.objects.create(
|
||||
user=user,
|
||||
check_in_date=today - timedelta(days=days_ago),
|
||||
neck_pain_severity=neck,
|
||||
headache_severity=headache,
|
||||
had_physiotherapy=physiotherapy,
|
||||
note=note,
|
||||
)
|
||||
for days_ago, rested, watch_score, note in (
|
||||
(3, 5, 68, 'Late evening.'),
|
||||
(2, 7, 82, 'Good recovery.'),
|
||||
(1, 6, None, ''),
|
||||
(0, 8, 88, 'Rested this morning.'),
|
||||
):
|
||||
SleepCheckIn.objects.create(
|
||||
user=user,
|
||||
wake_up_date=today - timedelta(days=days_ago),
|
||||
rested_score=rested,
|
||||
watch_sleep_score=watch_score,
|
||||
note=note,
|
||||
)
|
||||
|
||||
fasting, _ = FastingSettings.objects.update_or_create(
|
||||
user=user,
|
||||
defaults={
|
||||
'enabled': True,
|
||||
'fasting_start_time': time(20, 0),
|
||||
'fasting_duration_minutes': 16 * 60,
|
||||
'tracking_started_at': now - timedelta(days=3),
|
||||
},
|
||||
)
|
||||
synchronize_fasting_periods(fasting, now)
|
||||
|
||||
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.'
|
||||
))
|
||||
@@ -0,0 +1,37 @@
|
||||
# Generated by Django 6.1.1 on 2026-09-30 15:35
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def disable_tour_for_existing_users(apps, schema_editor):
|
||||
"""Existing accounts should not suddenly see a first-run tour."""
|
||||
User = apps.get_model(*settings.AUTH_USER_MODEL.split('.'))
|
||||
UserSettings = apps.get_model('planner', 'UserSettings')
|
||||
UserSettings.objects.all().update(onboarding_enabled=False, onboarding_step=0)
|
||||
configured_user_ids = set(UserSettings.objects.values_list('user_id', flat=True))
|
||||
UserSettings.objects.bulk_create([
|
||||
UserSettings(user_id=user_id, onboarding_enabled=False, onboarding_step=0)
|
||||
for user_id in User.objects.exclude(pk__in=configured_user_ids).values_list('pk', flat=True)
|
||||
])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('planner', '0011_usersettings_time_zone_sleepcheckin'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='usersettings',
|
||||
name='onboarding_enabled',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='usersettings',
|
||||
name='onboarding_step',
|
||||
field=models.PositiveSmallIntegerField(default=0),
|
||||
),
|
||||
migrations.RunPython(disable_tour_for_existing_users, migrations.RunPython.noop),
|
||||
]
|
||||
@@ -107,6 +107,8 @@ class UserSettings(models.Model):
|
||||
validators=[MinValueValidator(-180), MaxValueValidator(180)],
|
||||
)
|
||||
time_zone = models.CharField(max_length=64, default='Europe/Amsterdam')
|
||||
onboarding_enabled = models.BooleanField(default=True)
|
||||
onboarding_step = models.PositiveSmallIntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
<nav class="primary-nav" aria-label="Primary navigation">
|
||||
{% if user.is_authenticated %}
|
||||
<a href="{% url 'planner:task-list' %}">My tasks</a>
|
||||
<a href="{% url 'planner:daily-planner' %}">Daily planner</a>
|
||||
<a href="{% url 'planner:user-settings' %}">Settings</a>
|
||||
<a id="daily-planner-nav" class="{% if onboarding_tour.target == 'daily-planner' %}onboarding-highlight{% endif %}" href="{% url 'planner:daily-planner' %}">Daily planner</a>
|
||||
<a id="settings-nav" class="{% if onboarding_tour.target == 'settings' %}onboarding-highlight{% endif %}" href="{% url 'planner:user-settings' %}">Settings</a>
|
||||
<form method="post" action="{% url 'planner:logout' %}" class="nav-logout">{% csrf_token %}<button type="submit">Log out</button></form>
|
||||
{% else %}
|
||||
<a href="{% url 'planner:login' %}">Log in</a>
|
||||
|
||||
@@ -1,69 +1,18 @@
|
||||
<article class="fasting-widget" id="fasting-widget" aria-labelledby="fasting-heading">
|
||||
<article class="fasting-widget{% if onboarding_tour.target == 'fasting' %} onboarding-highlight{% endif %}" id="fasting-widget" aria-labelledby="fasting-heading">
|
||||
{% if not fasting_settings %}
|
||||
<p class="eyebrow">Optional routine</p>
|
||||
<h2 id="fasting-heading">Intermittent fasting</h2>
|
||||
<p class="fasting-widget__copy">Set a daily fasting window when it fits your routine.</p>
|
||||
<a class="button button--secondary button--compact" href="{% url 'planner:fasting-configure' %}" hx-get="{% url 'planner:fasting-configure' %}" hx-target="#fasting-widget" hx-swap="outerHTML">Set up fasting</a>
|
||||
<p class="eyebrow">Optional routine</p><h2 id="fasting-heading">Intermittent fasting</h2><p class="fasting-widget__copy">Set a daily fasting window when it fits your routine.</p><a class="button button--secondary button--compact" href="{% url 'planner:fasting-configure' %}" hx-get="{% url 'planner:fasting-configure' %}" hx-target="#fasting-widget" hx-swap="outerHTML">Set up fasting</a>
|
||||
{% elif fasting_settings.enabled %}
|
||||
<div class="fasting-widget__topline">
|
||||
<p class="eyebrow">Intermittent fasting</p>
|
||||
<span class="fasting-state fasting-state--{{ fasting_phase.name }}">{% if fasting_phase.is_fasting %}Fasting{% else %}Eating{% endif %}</span>
|
||||
</div>
|
||||
<div class="fasting-widget__topline"><p class="eyebrow">Intermittent fasting</p><span class="fasting-state fasting-state--{{ fasting_phase.name }}">{% if fasting_phase.is_fasting %}Fasting{% else %}Eating{% endif %}</span></div>
|
||||
<h2 id="fasting-heading">{% if fasting_phase.is_fasting %}Fasting now{% else %}Eating window open{% endif %}</h2>
|
||||
<div
|
||||
class="fasting-timer fasting-timer--{{ fasting_phase.name }}"
|
||||
data-fasting-timer
|
||||
data-cycle-start="{{ fasting_phase.cycle_start|date:'c' }}"
|
||||
data-cycle-end="{{ fasting_phase.cycle_end|date:'c' }}"
|
||||
data-phase="{{ fasting_phase.name }}"
|
||||
data-refresh-url="{% url 'planner:fasting-widget' %}"
|
||||
role="timer"
|
||||
aria-live="off"
|
||||
aria-label="{% if fasting_phase.is_fasting %}Fasting{% else %}Eating window{% endif %} progress"
|
||||
>
|
||||
<svg class="fasting-timer__ring" viewBox="0 0 120 120" aria-hidden="true">
|
||||
<circle class="fasting-timer__track" cx="60" cy="60" r="53" pathLength="100"></circle>
|
||||
<circle class="fasting-timer__progress" cx="60" cy="60" r="53" pathLength="100" data-fasting-progress></circle>
|
||||
</svg>
|
||||
<div class="fasting-timer__content">
|
||||
<strong data-fasting-elapsed>00:00:00</strong>
|
||||
<span>{% if fasting_phase.is_fasting %}Fasting elapsed{% else %}Eating elapsed{% endif %}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="fasting-widget__copy fasting-widget__cycle-copy">
|
||||
{% if fasting_phase.is_fasting %}
|
||||
Fasting until <time datetime="{{ fasting_phase.cycle_end|date:'c' }}">{{ fasting_phase.cycle_end|time:"H:i" }}</time>
|
||||
{% else %}
|
||||
Next fast at <time datetime="{{ fasting_phase.cycle_end|date:'c' }}">{{ fasting_phase.cycle_end|time:"H:i" }}</time>
|
||||
{% endif %}
|
||||
</p>
|
||||
<dl class="fasting-widget__schedule">
|
||||
<div><dt>Fasting</dt><dd>{{ fasting_settings.fasting_start_time|time:"H:i" }} daily</dd></div>
|
||||
<div><dt>Schedule</dt><dd>{{ fasting_settings.fasting_duration_minutes }} min</dd></div>
|
||||
<div class="fasting-timer fasting-timer--{{ fasting_phase.name }}" data-fasting-timer data-cycle-start="{{ fasting_phase.cycle_start|date:'c' }}" data-cycle-end="{{ fasting_phase.cycle_end|date:'c' }}" data-phase="{{ fasting_phase.name }}" data-refresh-url="{% url 'planner:fasting-widget' %}" role="timer" aria-live="off" aria-label="{% if fasting_phase.is_fasting %}Fasting{% else %}Eating window{% endif %} progress"><svg class="fasting-timer__ring" viewBox="0 0 120 120" aria-hidden="true"><circle class="fasting-timer__track" cx="60" cy="60" r="53" pathLength="100"></circle><circle class="fasting-timer__progress" cx="60" cy="60" r="53" pathLength="100" data-fasting-progress></circle></svg><div class="fasting-timer__content"><strong data-fasting-elapsed>00:00:00</strong><span>{% if fasting_phase.is_fasting %}Fasting elapsed{% else %}Eating elapsed{% endif %}</span></div></div>
|
||||
<dl class="fasting-widget__windows">
|
||||
<div><dt>{{ current_window_label }}</dt><dd><time datetime="{{ current_window_start|date:'c' }}">{{ current_window_start|date:"D j M, H:i" }}</time><span aria-hidden="true"> → </span><time datetime="{{ current_window_end|date:'c' }}">{{ current_window_end|date:"D j M, H:i" }}</time></dd></div>
|
||||
<div><dt>{{ next_window_label }}</dt><dd><time datetime="{{ next_window_start|date:'c' }}">{{ next_window_start|date:"D j M, H:i" }}</time><span aria-hidden="true"> → </span><time datetime="{{ next_window_end|date:'c' }}">{{ next_window_end|date:"D j M, H:i" }}</time></dd></div>
|
||||
</dl>
|
||||
<div class="fasting-widget__actions">
|
||||
<form method="post" action="{% url 'planner:fasting-toggle' %}" hx-post="{% url 'planner:fasting-toggle' %}" hx-target="#fasting-widget" hx-swap="outerHTML">
|
||||
{% csrf_token %}
|
||||
<button class="button button--secondary button--compact" type="submit">Pause tracking</button>
|
||||
</form>
|
||||
<a class="text-link" href="{% url 'planner:fasting-configure' %}" hx-get="{% url 'planner:fasting-configure' %}" hx-target="#fasting-widget" hx-swap="outerHTML">Adjust</a>
|
||||
</div>
|
||||
{% if fasting_history %}
|
||||
<section class="fasting-history" aria-labelledby="fasting-history-heading">
|
||||
<h3 id="fasting-history-heading">Recent completed fasts</h3>
|
||||
<ul>{% for period in fasting_history %}<li><time datetime="{{ period.scheduled_start|date:'c' }}">{{ period.scheduled_start|date:"j M" }}</time><span>{{ period.scheduled_start|time:"H:i" }}–{{ period.scheduled_end|time:"H:i" }}</span></li>{% endfor %}</ul>
|
||||
</section>
|
||||
{% endif %}
|
||||
<dl class="fasting-widget__schedule"><div><dt>Daily fast</dt><dd>{{ fasting_duration_display }}</dd></div><div><dt>Eating window</dt><dd>{{ eating_duration_display }}</dd></div></dl>
|
||||
<div class="fasting-widget__actions"><form method="post" action="{% url 'planner:fasting-toggle' %}" hx-post="{% url 'planner:fasting-toggle' %}" hx-target="#fasting-widget" hx-swap="outerHTML">{% csrf_token %}<button class="button button--secondary button--compact" type="submit">Pause tracking</button></form><a class="text-link" href="{% url 'planner:fasting-configure' %}" hx-get="{% url 'planner:fasting-configure' %}" hx-target="#fasting-widget" hx-swap="outerHTML">Adjust</a></div>
|
||||
{% if fasting_history %}<section class="fasting-history" aria-labelledby="fasting-history-heading"><h3 id="fasting-history-heading">Recent completed fasts</h3><ul>{% for period in fasting_history %}<li><time datetime="{{ period.scheduled_start|date:'c' }}">{{ period.scheduled_start|date:"j M" }}</time><span>{{ period.scheduled_start|time:"H:i" }}–{{ period.scheduled_end|time:"H:i" }}</span></li>{% endfor %}</ul></section>{% endif %}
|
||||
{% else %}
|
||||
<p class="eyebrow">Intermittent fasting</p>
|
||||
<h2 id="fasting-heading">Tracking paused</h2>
|
||||
<p class="fasting-widget__copy">Your history is saved. Resume when you are ready to follow your normal schedule again.</p>
|
||||
<div class="fasting-widget__actions">
|
||||
<form method="post" action="{% url 'planner:fasting-toggle' %}" hx-post="{% url 'planner:fasting-toggle' %}" hx-target="#fasting-widget" hx-swap="outerHTML">
|
||||
{% csrf_token %}
|
||||
<button class="button button--compact" type="submit">Resume tracking</button>
|
||||
</form>
|
||||
<a class="text-link" href="{% url 'planner:fasting-configure' %}" hx-get="{% url 'planner:fasting-configure' %}" hx-target="#fasting-widget" hx-swap="outerHTML">Adjust schedule</a>
|
||||
</div>
|
||||
<p class="eyebrow">Intermittent fasting</p><h2 id="fasting-heading">Tracking paused</h2><p class="fasting-widget__copy">Your history is saved. Resume when you are ready to follow your normal schedule again.</p><div class="fasting-widget__actions"><form method="post" action="{% url 'planner:fasting-toggle' %}" hx-post="{% url 'planner:fasting-toggle' %}" hx-target="#fasting-widget" hx-swap="outerHTML">{% csrf_token %}<button class="button button--compact" type="submit">Resume tracking</button></form><a class="text-link" href="{% url 'planner:fasting-configure' %}" hx-get="{% url 'planner:fasting-configure' %}" hx-target="#fasting-widget" hx-swap="outerHTML">Adjust schedule</a></div>
|
||||
{% endif %}
|
||||
</article>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<section class="checkin-panel" id="neck-headache-checkin" aria-labelledby="checkin-heading">
|
||||
<section class="checkin-panel{% if onboarding_tour.target == 'wellbeing' %} onboarding-highlight{% endif %}" id="neck-headache-checkin" aria-labelledby="checkin-heading">
|
||||
<header class="checkin-panel__header">
|
||||
<div>
|
||||
<p class="eyebrow">Daily wellbeing</p>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<section class="onboarding-tour" aria-labelledby="onboarding-title" aria-live="polite">
|
||||
<p class="eyebrow">Getting started · {{ onboarding_tour.number }} of {{ onboarding_tour.total }}</p>
|
||||
<h2 id="onboarding-title">{{ onboarding_tour.title }}</h2>
|
||||
<p>{{ onboarding_tour.copy }}</p>
|
||||
<div class="onboarding-tour__actions">
|
||||
<form method="post" action="{% url 'planner:onboarding-advance' %}">{% csrf_token %}<input type="hidden" name="action" value="next"><button class="button button--compact" type="submit">{% if onboarding_tour.is_last %}Finish tour{% else %}Next{% endif %}</button></form>
|
||||
<form method="post" action="{% url 'planner:onboarding-advance' %}">{% csrf_token %}<input type="hidden" name="action" value="skip"><button class="text-link" type="submit">Turn help off</button></form>
|
||||
</div>
|
||||
</section>
|
||||
@@ -1,4 +1,4 @@
|
||||
<section class="workout-panel" id="workout-section" aria-labelledby="workouts-heading">
|
||||
<section class="workout-panel{% if onboarding_tour.target == 'workouts' %} onboarding-highlight{% endif %}" id="workout-section" aria-labelledby="workouts-heading">
|
||||
<header class="workout-panel__header">
|
||||
<div><p class="eyebrow">Daily movement</p><h2 id="workouts-heading">Daily Workout</h2><p>Today, {{ workout_date|date:"l, j F" }}</p></div>
|
||||
<div class="workout-panel__summary">{% if workout_calories_total is not None %}<strong>{{ workout_calories_total }} kcal</strong><span>Total burned today</span>{% else %}<strong>—</strong><span>No calorie data yet</span>{% endif %}</div>
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% if onboarding_tour %}{% include 'planner/partials/onboarding_tour.html' %}{% endif %}
|
||||
|
||||
<div class="home-layout">
|
||||
<div class="home-main">
|
||||
<section class="task-panel" aria-label="Task list">
|
||||
<section class="task-panel{% if onboarding_tour.target == 'tasks' %} onboarding-highlight{% endif %}" aria-label="Task list">
|
||||
<form class="task-filters" method="get" hx-get="{% url 'planner:task-list' %}" hx-target="#task-list" hx-push-url="true" hx-trigger="change" hx-indicator="#loading-indicator">
|
||||
<div>
|
||||
<label for="status-filter">Show</label>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<section class="settings-page">
|
||||
<p class="eyebrow">Personal preferences</p><h1>Settings</h1>
|
||||
<section class="settings-card"><h2>Time zone</h2><p>Dates and displayed times, including fasting, use this time zone. Europe/Amsterdam is the default.</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="time-zone">{% for field in time_zone_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" type="submit">Save time zone</button></form></section>
|
||||
<section class="settings-card"><h2>First-run help</h2><p>{% if onboarding_enabled %}The guided tour is ready to continue on your dashboard.{% else %}Help is off. You can run the tour again whenever you want.{% endif %}</p><form method="post">{% csrf_token %}<input type="hidden" name="section" value="onboarding"><button class="button" type="submit" name="action" value="restart">Run feature tour</button><button class="text-link" type="submit" name="action" value="disable">Turn help off</button></form></section>
|
||||
<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 %}<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" type="submit">Save Sick Day settings</button></form></section>
|
||||
<section class="settings-card"><h2>Fasting</h2><form method="post">{% csrf_token %}<input type="hidden" name="section" value="fasting">{% for field in fasting_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" type="submit">Save fasting settings</button></form></section>
|
||||
|
||||
@@ -3,6 +3,7 @@ from zoneinfo import ZoneInfo
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
from django.urls import reverse
|
||||
@@ -668,6 +669,10 @@ class FastingServiceTests(TestCase):
|
||||
defaults.update(overrides)
|
||||
return FastingSettings.objects.create(**defaults)
|
||||
|
||||
def test_duration_display_uses_hours_and_remaining_minutes(self):
|
||||
self.assertEqual(duration_as_hours_and_minutes(16 * 60), "16 hours")
|
||||
self.assertEqual(duration_as_hours_and_minutes(90), "1 hour 30 min")
|
||||
|
||||
def test_current_phase_is_calculated_from_daily_schedule_across_midnight(self):
|
||||
settings = self.make_settings()
|
||||
|
||||
@@ -794,6 +799,10 @@ class FastingWidgetViewTests(TestCase):
|
||||
self.assertTrue(settings.enabled)
|
||||
self.assertEqual(settings.fasting_duration_minutes, 960)
|
||||
self.assertContains(response, 'Pause tracking')
|
||||
self.assertContains(response, 'Daily fast')
|
||||
self.assertContains(response, '16 hours')
|
||||
self.assertContains(response, 'window')
|
||||
self.assertNotContains(response, '960 min')
|
||||
|
||||
def test_htmx_pause_marks_tracking_paused(self):
|
||||
FastingSettings.objects.create(
|
||||
@@ -933,6 +942,87 @@ class UserSettingsTests(TestCase):
|
||||
self.assertFalse(UserSettings.objects.filter(user=self.user_b).exists())
|
||||
|
||||
|
||||
class OnboardingTests(TestCase):
|
||||
def setUp(self):
|
||||
self.user = get_user_model().objects.create_user(username="new-tour-user", password="password")
|
||||
self.other = get_user_model().objects.create_user(username="other-tour-user", password="password")
|
||||
self.client.force_login(self.user)
|
||||
|
||||
def test_new_user_sees_first_step_and_next_moves_to_the_next_component(self):
|
||||
response = self.client.get(reverse("planner:task-list"))
|
||||
|
||||
self.assertContains(response, "Getting started · 1 of 6")
|
||||
self.assertContains(response, "Start with one clear task")
|
||||
profile = UserSettings.objects.get(user=self.user)
|
||||
self.assertTrue(profile.onboarding_enabled)
|
||||
self.assertEqual(profile.onboarding_step, 0)
|
||||
|
||||
response = self.client.post(reverse("planner:onboarding-advance"), {"action": "next"})
|
||||
|
||||
self.assertRedirects(response, reverse("planner:task-list"))
|
||||
profile.refresh_from_db()
|
||||
self.assertEqual(profile.onboarding_step, 1)
|
||||
page = self.client.get(reverse("planner:task-list"))
|
||||
self.assertContains(page, "Use the Daily planner for a realistic next step")
|
||||
self.assertContains(page, "daily-planner-nav")
|
||||
|
||||
def test_tour_can_be_disabled_or_restarted_without_affecting_other_users(self):
|
||||
self.client.get(reverse("planner:task-list"))
|
||||
other_profile = UserSettings.objects.create(
|
||||
user=self.other, onboarding_enabled=True, onboarding_step=3
|
||||
)
|
||||
|
||||
self.client.post(reverse("planner:onboarding-advance"), {"action": "skip"})
|
||||
profile = UserSettings.objects.get(user=self.user)
|
||||
self.assertFalse(profile.onboarding_enabled)
|
||||
self.assertNotContains(self.client.get(reverse("planner:task-list")), "Getting started")
|
||||
|
||||
response = self.client.post(reverse("planner:user-settings"), {
|
||||
"section": "onboarding", "action": "restart",
|
||||
})
|
||||
self.assertRedirects(response, reverse("planner:task-list"))
|
||||
profile.refresh_from_db()
|
||||
other_profile.refresh_from_db()
|
||||
self.assertTrue(profile.onboarding_enabled)
|
||||
self.assertEqual(profile.onboarding_step, 0)
|
||||
self.assertEqual((other_profile.onboarding_enabled, other_profile.onboarding_step), (True, 3))
|
||||
|
||||
self.client.post(reverse("planner:user-settings"), {
|
||||
"section": "onboarding", "action": "disable",
|
||||
})
|
||||
profile.refresh_from_db()
|
||||
self.assertFalse(profile.onboarding_enabled)
|
||||
|
||||
|
||||
class DemoSeedCommandTests(TestCase):
|
||||
def test_command_creates_and_repeatedly_restores_only_the_demo_account(self):
|
||||
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()
|
||||
)
|
||||
|
||||
call_command("seed_demo")
|
||||
|
||||
demo = get_user_model().objects.get(username="demo")
|
||||
self.assertTrue(demo.check_password("demo"))
|
||||
self.assertEqual(Task.objects.filter(owner=demo).count(), 5)
|
||||
self.assertEqual(Workout.objects.filter(owner=demo).count(), 2)
|
||||
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)
|
||||
profile = UserSettings.objects.get(user=demo)
|
||||
self.assertEqual(profile.time_zone, "Europe/Amsterdam")
|
||||
self.assertFalse(profile.onboarding_enabled)
|
||||
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())
|
||||
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.assertTrue(Task.objects.filter(pk=private_task.pk, owner=other).exists())
|
||||
|
||||
|
||||
class UserTimeZoneTests(TestCase):
|
||||
def test_default_is_europe_amsterdam_and_fasting_uses_the_saved_zone(self):
|
||||
user = get_user_model().objects.create_user(username="timezone-user", password="password")
|
||||
@@ -1072,6 +1162,7 @@ class TaskForecastPresentationTests(TestCase):
|
||||
|
||||
from .models import Workout, WorkoutCompletion
|
||||
from .services.workouts import toggle_workout_completion, workouts_for_day
|
||||
from .views import duration_as_hours_and_minutes
|
||||
|
||||
|
||||
class WorkoutServiceTests(TestCase):
|
||||
|
||||
@@ -5,7 +5,7 @@ from .views import (
|
||||
DailyPlannerView, TaskCreateView, category_suggestions, TaskDeleteView, TaskDetailView, TaskListView,
|
||||
TaskUpdateView, WorkoutCreateView, WorkoutUpdateView, delete_workout, fasting_configure, neck_headache_checkin_panel,
|
||||
fasting_toggle_tracking, fasting_widget, logout_view, register, toggle_task_active, toggle_task_completed,
|
||||
save_neck_headache_checkin, save_sleep_checkin, toggle_workout_completed, user_settings, workout_today,
|
||||
save_neck_headache_checkin, save_sleep_checkin, advance_onboarding, toggle_workout_completed, user_settings, workout_today,
|
||||
)
|
||||
|
||||
app_name = 'planner'
|
||||
@@ -16,6 +16,7 @@ urlpatterns = [
|
||||
path('register/', register, name='register'),
|
||||
path('logout/', logout_view, name='logout'),
|
||||
path('settings/', user_settings, name='user-settings'),
|
||||
path('onboarding/advance/', advance_onboarding, name='onboarding-advance'),
|
||||
path('daily/', DailyPlannerView.as_view(), name='daily-planner'),
|
||||
path('fasting/widget/', fasting_widget, name='fasting-widget'),
|
||||
path('fasting/configure/', fasting_configure, name='fasting-configure'),
|
||||
|
||||
+107
-1
@@ -33,6 +33,52 @@ from .services.weather import (
|
||||
)
|
||||
|
||||
|
||||
ONBOARDING_STEPS = (
|
||||
{
|
||||
'target': 'tasks',
|
||||
'title': 'Start with one clear task',
|
||||
'copy': 'Add a task here, then use Mark complete when it is done. Subtasks appear after their parent task is completed.',
|
||||
},
|
||||
{
|
||||
'target': 'daily-planner',
|
||||
'title': 'Use the Daily planner for a realistic next step',
|
||||
'copy': 'Choose a day and energy level to see a short, prioritised plan for what fits today.',
|
||||
},
|
||||
{
|
||||
'target': 'workouts',
|
||||
'title': 'Track movement without turning it into a task',
|
||||
'copy': 'Add workouts here and mark them complete for the day. Their calorie totals stay separate from your task plan.',
|
||||
},
|
||||
{
|
||||
'target': 'wellbeing',
|
||||
'title': 'Keep a lightweight wellbeing record',
|
||||
'copy': 'The wellbeing panel keeps pain and sleep check-ins separate, while its calendar makes past days easy to revisit.',
|
||||
},
|
||||
{
|
||||
'target': 'fasting',
|
||||
'title': 'Optional routines stay separate from tasks',
|
||||
'copy': 'Fasting runs as an optional daily routine with clear start and end windows, separate from your tasks and wellbeing records.',
|
||||
},
|
||||
{
|
||||
'target': 'settings',
|
||||
'title': 'Make Tasknest yours',
|
||||
'copy': 'Settings holds your time zone, weather location, recovery options, and this tour if you want to run it again.',
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def onboarding_context(profile):
|
||||
if not profile.onboarding_enabled:
|
||||
return None
|
||||
step = min(profile.onboarding_step, len(ONBOARDING_STEPS) - 1)
|
||||
return {
|
||||
**ONBOARDING_STEPS[step],
|
||||
'number': step + 1,
|
||||
'total': len(ONBOARDING_STEPS),
|
||||
'is_last': step == len(ONBOARDING_STEPS) - 1,
|
||||
}
|
||||
|
||||
|
||||
def workout_context(user, selected_date=None):
|
||||
selected_date = selected_date or timezone.localdate()
|
||||
summary = workouts_for_day(user, selected_date)
|
||||
@@ -208,6 +254,16 @@ def dashboard_weather_context(user):
|
||||
}
|
||||
|
||||
|
||||
def duration_as_hours_and_minutes(minutes):
|
||||
hours, remaining_minutes = divmod(minutes, 60)
|
||||
parts = []
|
||||
if hours:
|
||||
parts.append(f'{hours} hour{"s" if hours != 1 else ""}')
|
||||
if remaining_minutes:
|
||||
parts.append(f'{remaining_minutes} min')
|
||||
return ' '.join(parts) or '0 min'
|
||||
|
||||
|
||||
def fasting_widget_context(user):
|
||||
"""Fetch widget state; schedule decisions remain in the fasting service."""
|
||||
fasting_settings = FastingSettings.objects.filter(user=user).first()
|
||||
@@ -219,7 +275,25 @@ def fasting_widget_context(user):
|
||||
'fasting_history': FastingPeriod.objects.filter(user=user)[:3],
|
||||
}
|
||||
if fasting_settings.enabled:
|
||||
context['fasting_phase'] = current_fasting_phase(fasting_settings)
|
||||
phase = current_fasting_phase(fasting_settings)
|
||||
fasting_duration = fasting_settings.fasting_duration_minutes
|
||||
if phase.is_fasting:
|
||||
current_window = ('Fasting window', phase.cycle_start, phase.cycle_end)
|
||||
next_window = ('Next eating window', phase.cycle_end, phase.scheduled_start + timedelta(days=1))
|
||||
else:
|
||||
current_window = ('Eating window', phase.cycle_start, phase.cycle_end)
|
||||
next_window = ('Next fasting window', phase.cycle_end, phase.cycle_end + timedelta(minutes=fasting_duration))
|
||||
context.update(
|
||||
fasting_phase=phase,
|
||||
fasting_duration_display=duration_as_hours_and_minutes(fasting_duration),
|
||||
eating_duration_display=duration_as_hours_and_minutes((24 * 60) - fasting_duration),
|
||||
current_window_label=current_window[0],
|
||||
current_window_start=current_window[1],
|
||||
current_window_end=current_window[2],
|
||||
next_window_label=next_window[0],
|
||||
next_window_start=next_window[1],
|
||||
next_window_end=next_window[2],
|
||||
)
|
||||
return context
|
||||
|
||||
|
||||
@@ -343,6 +417,8 @@ class TaskListView(LoginRequiredMixin, ListView):
|
||||
context.update(fasting_widget_context(self.request.user))
|
||||
context.update(dashboard_weather_context(self.request.user))
|
||||
context.update(workout_context(self.request.user))
|
||||
profile, _ = UserSettings.objects.get_or_create(user=self.request.user)
|
||||
context['onboarding_tour'] = onboarding_context(profile)
|
||||
context.update(check_in_context(
|
||||
self.request.user, selected_check_in_date(self.request.GET.get('check_in_date'), self.request.user),
|
||||
active_tab=self.request.GET.get('wellbeing_tab', 'pain')
|
||||
@@ -525,6 +601,23 @@ def toggle_task_active(request, pk):
|
||||
return render(request, 'planner/partials/task_card.html', {'task': task})
|
||||
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
def advance_onboarding(request):
|
||||
profile, _ = UserSettings.objects.get_or_create(user=request.user)
|
||||
action = request.POST.get('action')
|
||||
if action == 'skip':
|
||||
profile.onboarding_enabled = False
|
||||
elif action == 'next':
|
||||
if profile.onboarding_step >= len(ONBOARDING_STEPS) - 1:
|
||||
profile.onboarding_enabled = False
|
||||
else:
|
||||
profile.onboarding_step += 1
|
||||
profile.onboarding_enabled = True
|
||||
profile.save(update_fields=['onboarding_enabled', 'onboarding_step', 'updated_at'])
|
||||
return redirect('planner:task-list')
|
||||
|
||||
|
||||
@login_required
|
||||
@require_http_methods(['GET', 'POST'])
|
||||
def user_settings(request):
|
||||
@@ -556,6 +649,18 @@ def user_settings(request):
|
||||
time_zone_form.save()
|
||||
messages.success(request, 'Your time zone was saved.')
|
||||
return redirect('planner:user-settings')
|
||||
elif section == 'onboarding':
|
||||
action = request.POST.get('action')
|
||||
if action == 'restart':
|
||||
profile.onboarding_enabled = True
|
||||
profile.onboarding_step = 0
|
||||
profile.save(update_fields=['onboarding_enabled', 'onboarding_step', 'updated_at'])
|
||||
return redirect('planner:task-list')
|
||||
if action == 'disable':
|
||||
profile.onboarding_enabled = False
|
||||
profile.save(update_fields=['onboarding_enabled', 'updated_at'])
|
||||
messages.success(request, 'First-run help is off.')
|
||||
return redirect('planner:user-settings')
|
||||
elif section == 'fasting':
|
||||
fasting_form = FastingSettingsForm(request.POST, instance=fasting)
|
||||
if fasting_form.is_valid():
|
||||
@@ -570,6 +675,7 @@ def user_settings(request):
|
||||
'sick_form': sick_form,
|
||||
'fasting_form': fasting_form,
|
||||
'time_zone_form': time_zone_form,
|
||||
'onboarding_enabled': profile.onboarding_enabled,
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user