From d891aa65ccd68d6ca8c5d53c8c9b625ce01712bf Mon Sep 17 00:00:00 2001 From: Joren de Graaf Date: Wed, 30 Sep 2026 18:01:34 +0200 Subject: [PATCH] added demo account data seeding --- main/README.md | 28 +++ .../deploy/systemd/tasknest-demo-seed.service | 12 ++ main/deploy/systemd/tasknest-demo-seed.timer | 10 + main/frontend/src/styles/main.scss | 5 + main/planner/management/__init__.py | 0 main/planner/management/commands/__init__.py | 0 main/planner/management/commands/seed_demo.py | 171 ++++++++++++++++++ ...sersettings_onboarding_enabled_and_more.py | 37 ++++ main/planner/models.py | 2 + main/planner/templates/planner/base.html | 4 +- .../planner/partials/fasting_widget.html | 73 ++------ .../partials/neck_headache_checkin.html | 2 +- .../planner/partials/onboarding_tour.html | 9 + .../planner/partials/workout_section.html | 2 +- main/planner/templates/planner/task_list.html | 4 +- .../templates/planner/user_settings.html | 1 + main/planner/tests.py | 91 ++++++++++ main/planner/urls.py | 3 +- main/planner/views.py | 108 ++++++++++- 19 files changed, 493 insertions(+), 69 deletions(-) create mode 100644 main/deploy/systemd/tasknest-demo-seed.service create mode 100644 main/deploy/systemd/tasknest-demo-seed.timer create mode 100644 main/planner/management/__init__.py create mode 100644 main/planner/management/commands/__init__.py create mode 100644 main/planner/management/commands/seed_demo.py create mode 100644 main/planner/migrations/0012_usersettings_onboarding_enabled_and_more.py create mode 100644 main/planner/templates/planner/partials/onboarding_tour.html diff --git a/main/README.md b/main/README.md index 8361227..c796de6 100644 --- a/main/README.md +++ b/main/README.md @@ -16,3 +16,31 @@ Deferral precedence is: manual, missed, and Sick Day state are evaluated before ## Legacy ownership migration Migration `0006` assigns old unowned tasks only when the database has exactly one active user. This local development database met that condition and its two existing tasks were assigned to that account. In a multi-user deployment the migration deliberately leaves legacy rows unowned instead of guessing; claim them explicitly before making ownership non-null at the database level. + +## Demo account reset + +Create or reset the public demonstration account and its dummy data with: + +```sh +/home/jorenmartijn/django/tasksnest/bin/python /home/jorenmartijn/django/main/manage.py seed_demo +``` + +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. + +A daily systemd timer template is provided in `main/deploy/systemd/`. Adjust the +`User`, `WorkingDirectory`, and `ExecStart` paths in the service file if needed, +then install it with: + +```sh +sudo cp main/deploy/systemd/tasknest-demo-seed.service /etc/systemd/system/ +sudo cp main/deploy/systemd/tasknest-demo-seed.timer /etc/systemd/system/ +sudo systemctl daemon-reload +sudo systemctl enable --now tasknest-demo-seed.timer +systemctl list-timers tasknest-demo-seed.timer +``` + +The supplied timer runs daily at 03:15 Europe/Amsterdam and catches up after a +missed scheduled run when the host comes back online. diff --git a/main/deploy/systemd/tasknest-demo-seed.service b/main/deploy/systemd/tasknest-demo-seed.service new file mode 100644 index 0000000..47c9781 --- /dev/null +++ b/main/deploy/systemd/tasknest-demo-seed.service @@ -0,0 +1,12 @@ +[Unit] +Description=Reset Tasknest demo account data +After=network.target + +[Service] +Type=oneshot +User=jorenmartijn +WorkingDirectory=/home/jorenmartijn/django/main +Environment=DJANGO_SETTINGS_MODULE=tasksnest.settings +Environment=VIRTUAL_ENV=/home/jorenmartijn/django/tasksnest +Environment=PATH=/home/jorenmartijn/django/tasksnest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +ExecStart=/home/jorenmartijn/django/tasksnest/bin/python manage.py seed_demo diff --git a/main/deploy/systemd/tasknest-demo-seed.timer b/main/deploy/systemd/tasknest-demo-seed.timer new file mode 100644 index 0000000..af22a56 --- /dev/null +++ b/main/deploy/systemd/tasknest-demo-seed.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run the Tasknest demo-data reset every day + +[Timer] +OnCalendar=*-*-* 03:15:00 Europe/Amsterdam +Persistent=true +Unit=tasknest-demo-seed.service + +[Install] +WantedBy=timers.target diff --git a/main/frontend/src/styles/main.scss b/main/frontend/src/styles/main.scss index f05ab64..174d6e9 100644 --- a/main/frontend/src/styles/main.scss +++ b/main/frontend/src/styles/main.scss @@ -142,3 +142,8 @@ h2 { font-family: Fraunces, Georgia, serif; letter-spacing: -.03em; } @media (max-width: 700px) { .sleep-trend header { display: block; }.sleep-trend header p { margin-top: 5px; text-align: left; } } .checkin-tabs { display: flex; gap: 6px; margin-top: 22px; padding-bottom: 1px; border-bottom: 1px solid $line; }.checkin-tabs__tab { padding: 9px 12px 10px; border-bottom: 2px solid transparent; color: $muted; font-size: .84rem; font-weight: 700; text-decoration: none; }.checkin-tabs__tab:hover { color: $forest; }.checkin-tabs__tab:focus-visible { outline: 2px solid $forest; outline-offset: -2px; }.checkin-tabs__tab.is-active { border-color: $forest; color: $forest; } + +.fasting-widget__windows { display: grid; gap: 9px; margin: 0 0 14px; padding: 12px; border-radius: 10px; background: #f6f8f4; }.fasting-widget__windows div { display: grid; gap: 2px; }.fasting-widget__windows dt { color: $muted; font-size: .68rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }.fasting-widget__windows dd { margin: 0; font-size: .79rem; font-weight: 600; }.fasting-widget__windows time { white-space: nowrap; } + +.onboarding-tour { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px 24px; max-width: 760px; margin: 0 auto 26px; padding: 21px 23px; border: 1px solid #b8d6c1; border-radius: 17px; color: $ink; background: linear-gradient(135deg, #f3fbf5, $surface); box-shadow: $shadow; }.onboarding-tour .eyebrow { grid-column: 1 / -1; margin: 0; color: $forest; }.onboarding-tour h2 { margin: 0; font-size: 1.3rem; }.onboarding-tour > p:not(.eyebrow) { grid-column: 1 / -1; margin: 0; color: $muted; }.onboarding-tour__actions { display: flex; align-items: center; gap: 16px; }.onboarding-tour__actions form { margin: 0; }.onboarding-tour__actions .text-link { padding: 0; border: 0; background: transparent; }.onboarding-highlight { position: relative; z-index: 2; outline: 3px solid rgba($forest, .52); outline-offset: 4px; border-radius: 12px; box-shadow: 0 0 0 8px rgba($mint, .75), $shadow; }.primary-nav .onboarding-highlight { outline-offset: 3px; border-radius: 5px; } +@media (max-width: 560px) { .onboarding-tour { display: block; padding: 19px; }.onboarding-tour > p:not(.eyebrow) { margin-top: 7px; }.onboarding-tour__actions { margin-top: 15px; } } diff --git a/main/planner/management/__init__.py b/main/planner/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/planner/management/commands/__init__.py b/main/planner/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/planner/management/commands/seed_demo.py b/main/planner/management/commands/seed_demo.py new file mode 100644 index 0000000..2934b13 --- /dev/null +++ b/main/planner/management/commands/seed_demo.py @@ -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.' + )) diff --git a/main/planner/migrations/0012_usersettings_onboarding_enabled_and_more.py b/main/planner/migrations/0012_usersettings_onboarding_enabled_and_more.py new file mode 100644 index 0000000..e17842d --- /dev/null +++ b/main/planner/migrations/0012_usersettings_onboarding_enabled_and_more.py @@ -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), + ] diff --git a/main/planner/models.py b/main/planner/models.py index 8b2367b..9118750 100644 --- a/main/planner/models.py +++ b/main/planner/models.py @@ -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) diff --git a/main/planner/templates/planner/base.html b/main/planner/templates/planner/base.html index a61222c..e85485a 100644 --- a/main/planner/templates/planner/base.html +++ b/main/planner/templates/planner/base.html @@ -19,8 +19,8 @@