added demo account data seeding
This commit is contained in:
+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