enhanced uploader
This commit is contained in:
@@ -13,6 +13,71 @@ htmx.on('htmx:configRequest', (event) => {
|
|||||||
event.detail.headers['X-CSRFToken'] = getCookie('csrftoken');
|
event.detail.headers['X-CSRFToken'] = getCookie('csrftoken');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function initialiseMobileNavigation() {
|
||||||
|
const toggle = document.querySelector('[data-nav-toggle]');
|
||||||
|
const closeButton = document.querySelector('[data-nav-close]');
|
||||||
|
const nav = document.querySelector('#primary-navigation');
|
||||||
|
const backdrop = document.querySelector('[data-nav-backdrop]');
|
||||||
|
if (!toggle || !closeButton || !nav || !backdrop) return;
|
||||||
|
|
||||||
|
const mobile = window.matchMedia('(max-width: 700px)');
|
||||||
|
document.body.classList.add('js-nav-ready');
|
||||||
|
|
||||||
|
function closeMenu(restoreFocus = true) {
|
||||||
|
if (!document.body.classList.contains('mobile-nav-open')) return;
|
||||||
|
document.body.classList.remove('mobile-nav-open');
|
||||||
|
toggle.setAttribute('aria-expanded', 'false');
|
||||||
|
toggle.setAttribute('aria-label', 'Open menu');
|
||||||
|
backdrop.hidden = true;
|
||||||
|
nav.inert = mobile.matches;
|
||||||
|
if (restoreFocus) toggle.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function openMenu() {
|
||||||
|
if (!mobile.matches) return;
|
||||||
|
document.body.classList.add('mobile-nav-open');
|
||||||
|
toggle.setAttribute('aria-expanded', 'true');
|
||||||
|
toggle.setAttribute('aria-label', 'Close menu');
|
||||||
|
backdrop.hidden = false;
|
||||||
|
nav.inert = false;
|
||||||
|
closeButton.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncViewport() {
|
||||||
|
closeMenu(false);
|
||||||
|
nav.inert = mobile.matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle.addEventListener('click', () => {
|
||||||
|
if (document.body.classList.contains('mobile-nav-open')) closeMenu();
|
||||||
|
else openMenu();
|
||||||
|
});
|
||||||
|
closeButton.addEventListener('click', () => closeMenu());
|
||||||
|
backdrop.addEventListener('click', () => closeMenu());
|
||||||
|
document.addEventListener('keydown', (event) => {
|
||||||
|
if (!document.body.classList.contains('mobile-nav-open')) return;
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
event.preventDefault();
|
||||||
|
closeMenu();
|
||||||
|
} else if (event.key === 'Tab') {
|
||||||
|
const focusable = Array.from(nav.querySelectorAll('a, button:not([disabled])'));
|
||||||
|
const first = focusable[0];
|
||||||
|
const last = focusable[focusable.length - 1];
|
||||||
|
if (event.shiftKey && document.activeElement === first) {
|
||||||
|
event.preventDefault();
|
||||||
|
last.focus();
|
||||||
|
} else if (!event.shiftKey && document.activeElement === last) {
|
||||||
|
event.preventDefault();
|
||||||
|
first.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mobile.addEventListener('change', syncViewport);
|
||||||
|
syncViewport();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', initialiseMobileNavigation);
|
||||||
|
|
||||||
|
|
||||||
let fastingTimerInterval;
|
let fastingTimerInterval;
|
||||||
|
|
||||||
|
|||||||
@@ -383,3 +383,40 @@ body[data-theme="dark"] .brushing-widget, body[data-theme="dark"] .bowel-period
|
|||||||
body[data-theme="dark"] .brushing-control button { color: #edf5ef; }
|
body[data-theme="dark"] .brushing-control button { color: #edf5ef; }
|
||||||
body[data-theme="dark"] .brushing-control__mark { color: #9adab0; }
|
body[data-theme="dark"] .brushing-control__mark { color: #9adab0; }
|
||||||
body[data-theme="dark"] .checkin-form--bowel .field textarea { border-color: #536159; color: #edf5ef; background: #161d19; }
|
body[data-theme="dark"] .checkin-form--bowel .field textarea { border-color: #536159; color: #edf5ef; background: #161d19; }
|
||||||
|
.checkin-calendar__exports { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
|
||||||
|
.checkin-calendar__exports .button:focus-visible { outline: 2px solid $forest; outline-offset: 2px; }
|
||||||
|
.health-layout { max-width: 920px; margin: 0 auto; }
|
||||||
|
.health-layout .checkin-panel { margin-top: 24px; }
|
||||||
|
.mobile-weather-slot { display: none; }
|
||||||
|
@media (max-width: 820px) {
|
||||||
|
.mobile-weather-slot { display: block; }
|
||||||
|
.desktop-weather-slot { display: none; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-nav-toggle, .mobile-nav-close, .mobile-nav-backdrop { display: none; }
|
||||||
|
@media (max-width: 700px) {
|
||||||
|
.site-header { backdrop-filter: none; z-index: 20; }
|
||||||
|
.site-header__inner { justify-content: flex-start; min-height: 62px; padding-left: 18px; padding-right: 18px; }
|
||||||
|
.js-nav-ready .mobile-nav-toggle { display: grid; place-items: center; flex: 0 0 42px; width: 42px; height: 42px; padding: 9px; border: 1px solid $line; border-radius: 10px; color: $ink; background: $surface; }
|
||||||
|
.mobile-nav-toggle__bars { display: grid; gap: 4px; width: 20px; }
|
||||||
|
.mobile-nav-toggle__bars span { display: block; height: 2px; border-radius: 2px; background: currentColor; }
|
||||||
|
.mobile-nav-toggle:hover { border-color: $forest; color: $forest; }
|
||||||
|
.mobile-nav-toggle:focus-visible, .mobile-nav-close:focus-visible, .primary-nav a:focus-visible, .primary-nav button:focus-visible { outline: 3px solid $forest; outline-offset: 3px; }
|
||||||
|
.js-nav-ready .primary-nav { position: fixed; top: 0; left: 0; z-index: 2; display: flex; flex-direction: column; align-items: stretch; gap: 0; width: min(86vw, 310px); height: 100dvh; padding: 16px 20px 28px; overflow-y: auto; border-right: 1px solid $line; background: $surface; box-shadow: 16px 0 35px rgba(0, 0, 0, .18); transform: translateX(-105%); visibility: hidden; transition: transform .24s ease, visibility .24s; }
|
||||||
|
.js-nav-ready.mobile-nav-open .primary-nav { transform: translateX(0); visibility: visible; }
|
||||||
|
.js-nav-ready .primary-nav > a:not(.button) { display: block; padding: 12px 8px; border-radius: 7px; }
|
||||||
|
.js-nav-ready .primary-nav > a:not(.button):hover { background: $mint; }
|
||||||
|
.js-nav-ready .mobile-nav-close { display: flex; align-items: center; justify-content: space-between; min-height: 43px; margin-bottom: 12px; padding: 4px 8px; border: 0; border-bottom: 1px solid $line; color: $ink; background: transparent; font-weight: 700; text-align: left; }
|
||||||
|
.mobile-nav-close span { font-size: 1.5rem; line-height: 1; }
|
||||||
|
.js-nav-ready .primary-nav .theme-toggle { margin: 12px 8px; }
|
||||||
|
.js-nav-ready .primary-nav .nav-logout { margin: 8px; }
|
||||||
|
.js-nav-ready .primary-nav .nav-logout button { min-height: 40px; }
|
||||||
|
.js-nav-ready .mobile-nav-backdrop:not([hidden]) { position: fixed; inset: 0; z-index: 19; display: block; background: rgba(15, 22, 18, .52); }
|
||||||
|
.mobile-nav-open { overflow: hidden; }
|
||||||
|
body[data-theme="dark"] .mobile-nav-toggle, body[data-theme="dark"].js-nav-ready .primary-nav { border-color: #46544b; color: #e8eee9; background: #242d27; }
|
||||||
|
body[data-theme="dark"] .mobile-nav-close { border-color: #46544b; color: #e8eee9; }
|
||||||
|
body[data-theme="dark"].js-nav-ready .primary-nav > a:not(.button):hover { background: #355a45; }
|
||||||
|
}
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.js-nav-ready .primary-nav { transition: none; }
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
"""Explicit CSV exports for the two independent symptom trackers."""
|
||||||
|
|
||||||
|
import calendar
|
||||||
|
import csv
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from django.utils.dateparse import parse_date
|
||||||
|
from django.views.decorators.http import require_GET
|
||||||
|
|
||||||
|
from .models import BowelHealthCheckIn, NeckHeadacheCheckIn
|
||||||
|
from .timezones import localdate_for_user
|
||||||
|
|
||||||
|
|
||||||
|
def safe_csv_text(value):
|
||||||
|
"""Keep spreadsheet software from evaluating a user-entered note."""
|
||||||
|
text = value or ''
|
||||||
|
if text.lstrip().startswith(('=', '+', '-', '@')):
|
||||||
|
return "'" + text
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def export_range(period, selected_date):
|
||||||
|
if period == 'week':
|
||||||
|
start = selected_date - timedelta(days=selected_date.weekday())
|
||||||
|
end = start + timedelta(days=6)
|
||||||
|
suffix = f'week_{start.isoformat()}_to_{end.isoformat()}'
|
||||||
|
elif period == 'month':
|
||||||
|
start = selected_date.replace(day=1)
|
||||||
|
end = selected_date.replace(day=calendar.monthrange(selected_date.year, selected_date.month)[1])
|
||||||
|
suffix = f'month_{selected_date:%Y-%m}'
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
return start, end, suffix
|
||||||
|
|
||||||
|
|
||||||
|
def csv_response(filename, headings, rows):
|
||||||
|
response = HttpResponse(content_type='text/csv; charset=utf-8')
|
||||||
|
response['Content-Disposition'] = f'attachment; filename="{filename}"'
|
||||||
|
response.write('\ufeff')
|
||||||
|
writer = csv.writer(response)
|
||||||
|
writer.writerow(headings)
|
||||||
|
writer.writerows(rows)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def selected_export_range(request, period):
|
||||||
|
raw_date = request.GET.get('date')
|
||||||
|
try:
|
||||||
|
selected_date = parse_date(raw_date) if raw_date else localdate_for_user(request.user)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
if selected_date is None or (raw_date and selected_date.isoformat() != raw_date):
|
||||||
|
return None
|
||||||
|
return export_range(period, selected_date)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@require_GET
|
||||||
|
def export_pain_csv(request, period):
|
||||||
|
date_range = selected_export_range(request, period)
|
||||||
|
if date_range is None:
|
||||||
|
return HttpResponse('Invalid date or export period.', status=400)
|
||||||
|
start, end, suffix = date_range
|
||||||
|
records = NeckHeadacheCheckIn.objects.filter(
|
||||||
|
user=request.user, check_in_date__range=(start, end)
|
||||||
|
).order_by('check_in_date')
|
||||||
|
headings = ('Date', 'Morning neck pain', 'Morning headache', 'Morning notes',
|
||||||
|
'Afternoon neck pain', 'Afternoon headache', 'Afternoon notes',
|
||||||
|
'Evening neck pain', 'Evening headache', 'Evening notes',
|
||||||
|
'Physiotherapy session', 'Daily severity')
|
||||||
|
rows = []
|
||||||
|
for record in records:
|
||||||
|
row = [record.check_in_date.isoformat()]
|
||||||
|
complete_scores = []
|
||||||
|
for period_name in ('morning', 'afternoon', 'evening'):
|
||||||
|
neck = getattr(record, f'{period_name}_neck_pain_severity')
|
||||||
|
headache = getattr(record, f'{period_name}_headache_severity')
|
||||||
|
row.extend((neck, headache, safe_csv_text(getattr(record, f'{period_name}_note'))))
|
||||||
|
if neck is not None and headache is not None:
|
||||||
|
complete_scores.append(max(neck, headache))
|
||||||
|
row.extend(('Yes' if record.had_physiotherapy else 'No',
|
||||||
|
max(complete_scores) if complete_scores else ''))
|
||||||
|
rows.append(row)
|
||||||
|
return csv_response(f'pain-tracker_{suffix}.csv', headings, rows)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@require_GET
|
||||||
|
def export_bowel_csv(request, period):
|
||||||
|
date_range = selected_export_range(request, period)
|
||||||
|
if date_range is None:
|
||||||
|
return HttpResponse('Invalid date or export period.', status=400)
|
||||||
|
start, end, suffix = date_range
|
||||||
|
records = BowelHealthCheckIn.objects.filter(
|
||||||
|
user=request.user, check_in_date__range=(start, end)
|
||||||
|
).order_by('check_in_date')
|
||||||
|
headings = ('Date', 'Morning severity', 'Morning notes', 'Afternoon severity',
|
||||||
|
'Afternoon notes', 'Evening severity', 'Evening notes', 'Daily severity')
|
||||||
|
rows = []
|
||||||
|
for record in records:
|
||||||
|
scores = [getattr(record, f'{period_name}_severity') for period_name in ('morning', 'afternoon', 'evening')]
|
||||||
|
rows.append((record.check_in_date.isoformat(), scores[0], safe_csv_text(record.morning_note),
|
||||||
|
scores[1], safe_csv_text(record.afternoon_note), scores[2],
|
||||||
|
safe_csv_text(record.evening_note), max((score for score in scores if score is not None), default='')))
|
||||||
|
return csv_response(f'bowel-health_{suffix}.csv', headings, rows)
|
||||||
@@ -12,14 +12,17 @@
|
|||||||
<div class="app-shell">
|
<div class="app-shell">
|
||||||
<header class="site-header">
|
<header class="site-header">
|
||||||
<div class="site-header__inner">
|
<div class="site-header__inner">
|
||||||
|
<button class="mobile-nav-toggle" type="button" aria-label="Open menu" aria-controls="primary-navigation" aria-expanded="false" data-nav-toggle><span class="mobile-nav-toggle__bars" aria-hidden="true"><span></span><span></span><span></span></span></button>
|
||||||
<a class="brand" href="{% url 'planner:task-list' %}" aria-label="Tasknest home">
|
<a class="brand" href="{% url 'planner:task-list' %}" aria-label="Tasknest home">
|
||||||
<span class="brand__mark" aria-hidden="true">✓</span>
|
<span class="brand__mark" aria-hidden="true">✓</span>
|
||||||
<span>tasknest</span>
|
<span>tasknest</span>
|
||||||
</a>
|
</a>
|
||||||
<nav class="primary-nav" aria-label="Primary navigation">
|
<nav class="primary-nav" id="primary-navigation" aria-label="Primary navigation">
|
||||||
|
<button class="mobile-nav-close" type="button" data-nav-close>Close menu <span aria-hidden="true">×</span></button>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<a href="{% url 'planner:task-list' %}">My tasks</a>
|
<a href="{% url 'planner:task-list' %}">My tasks</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="daily-planner-nav" class="{% if onboarding_tour.target == 'daily-planner' %}onboarding-highlight{% endif %}" href="{% url 'planner:daily-planner' %}">Daily planner</a>
|
||||||
|
<a id="health-nav" class="{% if onboarding_tour.target == 'wellbeing' %}onboarding-highlight{% endif %}" href="{% url 'planner:health' %}">Health</a>
|
||||||
<a id="settings-nav" class="{% if onboarding_tour.target == 'settings' %}onboarding-highlight{% endif %}" href="{% url 'planner:user-settings' %}">Settings</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:user-settings' %}" class="theme-toggle">{% csrf_token %}<input type="hidden" name="section" value="appearance"><input type="hidden" name="next" value="{{ request.path }}">{% if user_appearance == 'dark' %}<input type="hidden" name="appearance" value="light"><button type="submit" aria-label="Use light mode" title="Use light mode"><span aria-hidden="true">☀</span><span class="sr-only">Use light mode</span></button>{% else %}<input type="hidden" name="appearance" value="dark"><button type="submit" aria-label="Use dark mode" title="Use dark mode"><span aria-hidden="true">☾</span><span class="sr-only">Use dark mode</span></button>{% endif %}</form>
|
<form method="post" action="{% url 'planner:user-settings' %}" class="theme-toggle">{% csrf_token %}<input type="hidden" name="section" value="appearance"><input type="hidden" name="next" value="{{ request.path }}">{% if user_appearance == 'dark' %}<input type="hidden" name="appearance" value="light"><button type="submit" aria-label="Use light mode" title="Use light mode"><span aria-hidden="true">☀</span><span class="sr-only">Use light mode</span></button>{% else %}<input type="hidden" name="appearance" value="dark"><button type="submit" aria-label="Use dark mode" title="Use dark mode"><span aria-hidden="true">☾</span><span class="sr-only">Use dark mode</span></button>{% endif %}</form>
|
||||||
<form method="post" action="{% url 'planner:logout' %}" class="nav-logout">{% csrf_token %}<button type="submit">Log out</button></form>
|
<form method="post" action="{% url 'planner:logout' %}" class="nav-logout">{% csrf_token %}<button type="submit">Log out</button></form>
|
||||||
@@ -30,6 +33,7 @@
|
|||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
<div class="mobile-nav-backdrop" data-nav-backdrop hidden></div>
|
||||||
<main class="page-content">
|
<main class="page-content">
|
||||||
{% if messages %}{% for message in messages %}<p class="flash-message" role="status">{{ message }}</p>{% endfor %}{% endif %}
|
{% if messages %}{% for message in messages %}<p class="flash-message" role="status">{{ message }}</p>{% endfor %}{% endif %}
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{% extends 'planner/base.html' %}
|
||||||
|
|
||||||
|
{% block title %}Health · Tasknest{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<section class="hero" aria-labelledby="health-heading">
|
||||||
|
<div>
|
||||||
|
<p class="eyebrow">Personal health tracking</p>
|
||||||
|
<h1 id="health-heading">Health</h1>
|
||||||
|
<p class="hero__copy">Record symptoms and review earlier days.</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<div class="health-layout">
|
||||||
|
{% include 'planner/partials/neck_headache_checkin.html' %}
|
||||||
|
{% include 'planner/partials/bowel_health_checkin.html' %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -10,8 +10,8 @@
|
|||||||
</div><div class="form-actions"><button class="button button--compact" type="submit">Save bowel check-in</button></div>
|
</div><div class="form-actions"><button class="button button--compact" type="submit">Save bowel check-in</button></div>
|
||||||
</form>
|
</form>
|
||||||
<section class="checkin-calendar" aria-labelledby="bowel-calendar-heading"><header class="checkin-calendar__header">
|
<section class="checkin-calendar" aria-labelledby="bowel-calendar-heading"><header class="checkin-calendar__header">
|
||||||
<a class="text-link" href="{% url 'planner:task-list' %}?bowel_date={{ bowel_previous_month|date:'Y-m-d' }}#bowel-health-checkin" hx-get="{% url 'planner:bowel-health-panel' %}?date={{ bowel_previous_month|date:'Y-m-d' }}" hx-target="#bowel-health-checkin" hx-swap="outerHTML" aria-label="Previous month">←</a><h3 id="bowel-calendar-heading">{{ bowel_selected_date|date:'F Y' }}</h3><a class="text-link" href="{% url 'planner:task-list' %}?bowel_date={{ bowel_next_month|date:'Y-m-d' }}#bowel-health-checkin" hx-get="{% url 'planner:bowel-health-panel' %}?date={{ bowel_next_month|date:'Y-m-d' }}" hx-target="#bowel-health-checkin" hx-swap="outerHTML" aria-label="Next month">→</a>
|
<a class="text-link" href="{% url 'planner:health' %}?bowel_date={{ bowel_previous_month|date:'Y-m-d' }}#bowel-health-checkin" hx-get="{% url 'planner:bowel-health-panel' %}?date={{ bowel_previous_month|date:'Y-m-d' }}" hx-target="#bowel-health-checkin" hx-swap="outerHTML" aria-label="Previous month">←</a><h3 id="bowel-calendar-heading">{{ bowel_selected_date|date:'F Y' }}</h3><a class="text-link" href="{% url 'planner:health' %}?bowel_date={{ bowel_next_month|date:'Y-m-d' }}#bowel-health-checkin" hx-get="{% url 'planner:bowel-health-panel' %}?date={{ bowel_next_month|date:'Y-m-d' }}" hx-target="#bowel-health-checkin" hx-swap="outerHTML" aria-label="Next month">→</a>
|
||||||
</header><div class="checkin-calendar__weekdays" aria-hidden="true"><span>Mon</span><span>Tue</span><span>Wed</span><span>Thu</span><span>Fri</span><span>Sat</span><span>Sun</span></div>
|
</header><div class="checkin-calendar__exports" aria-label="Export bowel tracker data"><a class="button button--secondary button--compact" href="{% url 'planner:bowel-export' 'week' %}?date={{ bowel_selected_date|date:'Y-m-d' }}">Export week</a><a class="button button--secondary button--compact" href="{% url 'planner:bowel-export' 'month' %}?date={{ bowel_selected_date|date:'Y-m-d' }}">Export month</a></div><div class="checkin-calendar__weekdays" aria-hidden="true"><span>Mon</span><span>Tue</span><span>Wed</span><span>Thu</span><span>Fri</span><span>Sat</span><span>Sun</span></div>
|
||||||
<div class="checkin-calendar__grid">{% for week in bowel_calendar_weeks %}{% for day in week %}<a class="checkin-day{% if day.is_today %} checkin-day--today{% endif %}{% if day.is_selected %} checkin-day--selected{% endif %}{% if day.is_outside_month %} checkin-day--outside{% endif %}" href="{% url 'planner:task-list' %}?bowel_date={{ day.date|date:'Y-m-d' }}#bowel-health-checkin" hx-get="{% url 'planner:bowel-health-panel' %}?date={{ day.date|date:'Y-m-d' }}" hx-target="#bowel-health-checkin" hx-swap="outerHTML" aria-label="{{ day.label }}"><span class="checkin-day__number">{{ day.date|date:'j' }}</span><span class="checkin-day__periods" aria-hidden="true">{% for period in day.periods %}<span class="checkin-day__period checkin-day__period--{{ period.level }}"><span>{{ period.short_label }}</span><strong>{% if period.score is not None %}{{ period.score }}{% else %}—{% endif %}</strong></span>{% endfor %}</span></a>{% endfor %}{% endfor %}</div>
|
<div class="checkin-calendar__grid">{% for week in bowel_calendar_weeks %}{% for day in week %}<a class="checkin-day{% if day.is_today %} checkin-day--today{% endif %}{% if day.is_selected %} checkin-day--selected{% endif %}{% if day.is_outside_month %} checkin-day--outside{% endif %}" href="{% url 'planner:health' %}?bowel_date={{ day.date|date:'Y-m-d' }}#bowel-health-checkin" hx-get="{% url 'planner:bowel-health-panel' %}?date={{ day.date|date:'Y-m-d' }}" hx-target="#bowel-health-checkin" hx-swap="outerHTML" aria-label="{{ day.label }}"><span class="checkin-day__number">{{ day.date|date:'j' }}</span><span class="checkin-day__periods" aria-hidden="true">{% for period in day.periods %}<span class="checkin-day__period checkin-day__period--{{ period.level }}"><span>{{ period.short_label }}</span><strong>{% if period.score is not None %}{{ period.score }}{% else %}—{% endif %}</strong></span>{% endfor %}</span></a>{% endfor %}{% endfor %}</div>
|
||||||
<p class="checkin-calendar__legend">M = morning · A = afternoon · E = evening · 0 = no symptoms · 10 = worst symptoms</p></section>
|
<p class="checkin-calendar__legend">M = morning · A = afternoon · E = evening · 0 = no symptoms · 10 = worst symptoms</p></section>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<nav class="checkin-tabs" role="tablist" aria-label="Wellbeing check-ins">
|
<nav class="checkin-tabs" role="tablist" aria-label="Wellbeing check-ins">
|
||||||
<a class="checkin-tabs__tab{% if check_in_active_tab == 'pain' %} is-active{% endif %}" id="pain-checkin-tab" role="tab" aria-selected="{% if check_in_active_tab == 'pain' %}true{% else %}false{% endif %}" aria-controls="pain-checkin-panel" href="{% url 'planner:task-list' %}?check_in_date={{ check_in_selected_date|date:'Y-m-d' }}&wellbeing_tab=pain" hx-get="{% url 'planner:neck-headache-checkin-panel' %}?date={{ check_in_selected_date|date:'Y-m-d' }}&tab=pain" hx-target="#neck-headache-checkin" hx-swap="outerHTML">Neck & headache</a>
|
<a class="checkin-tabs__tab{% if check_in_active_tab == 'pain' %} is-active{% endif %}" id="pain-checkin-tab" role="tab" aria-selected="{% if check_in_active_tab == 'pain' %}true{% else %}false{% endif %}" aria-controls="pain-checkin-panel" href="{% url 'planner:health' %}?check_in_date={{ check_in_selected_date|date:'Y-m-d' }}&wellbeing_tab=pain" hx-get="{% url 'planner:neck-headache-checkin-panel' %}?date={{ check_in_selected_date|date:'Y-m-d' }}&tab=pain" hx-target="#neck-headache-checkin" hx-swap="outerHTML">Neck & headache</a>
|
||||||
<a class="checkin-tabs__tab{% if check_in_active_tab == 'sleep' %} is-active{% endif %}" id="sleep-checkin-tab" role="tab" aria-selected="{% if check_in_active_tab == 'sleep' %}true{% else %}false{% endif %}" aria-controls="sleep-checkin-panel" href="{% url 'planner:task-list' %}?check_in_date={{ check_in_selected_date|date:'Y-m-d' }}&wellbeing_tab=sleep" hx-get="{% url 'planner:neck-headache-checkin-panel' %}?date={{ check_in_selected_date|date:'Y-m-d' }}&tab=sleep" hx-target="#neck-headache-checkin" hx-swap="outerHTML">Sleep</a>
|
<a class="checkin-tabs__tab{% if check_in_active_tab == 'sleep' %} is-active{% endif %}" id="sleep-checkin-tab" role="tab" aria-selected="{% if check_in_active_tab == 'sleep' %}true{% else %}false{% endif %}" aria-controls="sleep-checkin-panel" href="{% url 'planner:health' %}?check_in_date={{ check_in_selected_date|date:'Y-m-d' }}&wellbeing_tab=sleep" hx-get="{% url 'planner:neck-headache-checkin-panel' %}?date={{ check_in_selected_date|date:'Y-m-d' }}&tab=sleep" hx-target="#neck-headache-checkin" hx-swap="outerHTML">Sleep</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
{% if check_in_active_tab == 'pain' %}
|
{% if check_in_active_tab == 'pain' %}
|
||||||
@@ -54,10 +54,11 @@
|
|||||||
|
|
||||||
<section class="checkin-calendar" aria-labelledby="checkin-calendar-heading">
|
<section class="checkin-calendar" aria-labelledby="checkin-calendar-heading">
|
||||||
<header class="checkin-calendar__header">
|
<header class="checkin-calendar__header">
|
||||||
<a class="text-link" href="{% url 'planner:task-list' %}?check_in_date={{ check_in_previous_month|date:'Y-m-d' }}&wellbeing_tab={{ check_in_active_tab }}" hx-get="{% url 'planner:neck-headache-checkin-panel' %}?date={{ check_in_previous_month|date:'Y-m-d' }}&tab={{ check_in_active_tab }}" hx-target="#neck-headache-checkin" hx-swap="outerHTML" aria-label="Previous month">←</a><h3 id="checkin-calendar-heading">{{ check_in_selected_date|date:"F Y" }}</h3><a class="text-link" href="{% url 'planner:task-list' %}?check_in_date={{ check_in_next_month|date:'Y-m-d' }}&wellbeing_tab={{ check_in_active_tab }}" hx-get="{% url 'planner:neck-headache-checkin-panel' %}?date={{ check_in_next_month|date:'Y-m-d' }}&tab={{ check_in_active_tab }}" hx-target="#neck-headache-checkin" hx-swap="outerHTML" aria-label="Next month">→</a>
|
<a class="text-link" href="{% url 'planner:health' %}?check_in_date={{ check_in_previous_month|date:'Y-m-d' }}&wellbeing_tab={{ check_in_active_tab }}" hx-get="{% url 'planner:neck-headache-checkin-panel' %}?date={{ check_in_previous_month|date:'Y-m-d' }}&tab={{ check_in_active_tab }}" hx-target="#neck-headache-checkin" hx-swap="outerHTML" aria-label="Previous month">←</a><h3 id="checkin-calendar-heading">{{ check_in_selected_date|date:"F Y" }}</h3><a class="text-link" href="{% url 'planner:health' %}?check_in_date={{ check_in_next_month|date:'Y-m-d' }}&wellbeing_tab={{ check_in_active_tab }}" hx-get="{% url 'planner:neck-headache-checkin-panel' %}?date={{ check_in_next_month|date:'Y-m-d' }}&tab={{ check_in_active_tab }}" hx-target="#neck-headache-checkin" hx-swap="outerHTML" aria-label="Next month">→</a>
|
||||||
</header>
|
</header>
|
||||||
|
<div class="checkin-calendar__exports" aria-label="Export pain tracker data"><a class="button button--secondary button--compact" href="{% url 'planner:pain-export' 'week' %}?date={{ check_in_selected_date|date:'Y-m-d' }}">Export week</a><a class="button button--secondary button--compact" href="{% url 'planner:pain-export' 'month' %}?date={{ check_in_selected_date|date:'Y-m-d' }}">Export month</a></div>
|
||||||
<div class="checkin-calendar__weekdays" aria-hidden="true"><span>Mon</span><span>Tue</span><span>Wed</span><span>Thu</span><span>Fri</span><span>Sat</span><span>Sun</span></div>
|
<div class="checkin-calendar__weekdays" aria-hidden="true"><span>Mon</span><span>Tue</span><span>Wed</span><span>Thu</span><span>Fri</span><span>Sat</span><span>Sun</span></div>
|
||||||
<div class="checkin-calendar__grid">{% for week in check_in_calendar_weeks %}{% for day in week %}<a class="checkin-day{% if day.is_today %} checkin-day--today{% endif %}{% if day.is_selected %} checkin-day--selected{% endif %}{% if day.is_outside_month %} checkin-day--outside{% endif %}" href='{% url "planner:task-list" %}?check_in_date={{ day.date|date:"Y-m-d" }}&wellbeing_tab={{ check_in_active_tab }}' hx-get='{% url "planner:neck-headache-checkin-panel" %}?date={{ day.date|date:"Y-m-d" }}&tab={{ check_in_active_tab }}' hx-target="#neck-headache-checkin" hx-swap="outerHTML" aria-label="{{ day.label }}"><span class="checkin-day__number">{{ day.date|date:"j" }}</span><span class="checkin-day__periods" aria-hidden="true">{% for period in day.periods %}<span class="checkin-day__period checkin-day__period--{{ period.level }}"><span>{{ period.short_label }}</span><strong>{% if period.score is not None %}{{ period.score }}{% else %}—{% endif %}</strong></span>{% endfor %}</span>{% if day.check_in and day.check_in.had_physiotherapy %}<span class="checkin-day__physio" aria-hidden="true">✚</span>{% endif %}{% if day.sleep_check_in %}<span class="checkin-day__sleep" aria-hidden="true">☾</span>{% endif %}</a>{% endfor %}{% endfor %}</div>
|
<div class="checkin-calendar__grid">{% for week in check_in_calendar_weeks %}{% for day in week %}<a class="checkin-day{% if day.is_today %} checkin-day--today{% endif %}{% if day.is_selected %} checkin-day--selected{% endif %}{% if day.is_outside_month %} checkin-day--outside{% endif %}" href='{% url "planner:health" %}?check_in_date={{ day.date|date:"Y-m-d" }}&wellbeing_tab={{ check_in_active_tab }}' hx-get='{% url "planner:neck-headache-checkin-panel" %}?date={{ day.date|date:"Y-m-d" }}&tab={{ check_in_active_tab }}' hx-target="#neck-headache-checkin" hx-swap="outerHTML" aria-label="{{ day.label }}"><span class="checkin-day__number">{{ day.date|date:"j" }}</span><span class="checkin-day__periods" aria-hidden="true">{% for period in day.periods %}<span class="checkin-day__period checkin-day__period--{{ period.level }}"><span>{{ period.short_label }}</span><strong>{% if period.score is not None %}{{ period.score }}{% else %}—{% endif %}</strong></span>{% endfor %}</span>{% if day.check_in and day.check_in.had_physiotherapy %}<span class="checkin-day__physio" aria-hidden="true">✚</span>{% endif %}{% if day.sleep_check_in %}<span class="checkin-day__sleep" aria-hidden="true">☾</span>{% endif %}</a>{% endfor %}{% endfor %}</div>
|
||||||
<p class="checkin-calendar__legend"><span><i class="checkin-legend checkin-legend--unrecorded"></i> Unrecorded period</span><span><i class="checkin-legend checkin-legend--zero"></i> Recorded: 0</span><span>Three bands: morning, afternoon, evening</span><span><i class="checkin-legend checkin-legend--sleep">☾</i> Sleep check-in</span></p>
|
<p class="checkin-calendar__legend"><span><i class="checkin-legend checkin-legend--unrecorded"></i> Unrecorded period</span><span><i class="checkin-legend checkin-legend--zero"></i> Recorded: 0</span><span>Three bands: morning, afternoon, evening</span><span><i class="checkin-legend checkin-legend--sleep">☾</i> Sleep check-in</span></p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -18,15 +18,17 @@
|
|||||||
<p class="subtask-count"><span aria-hidden="true">↳</span> {{ task.subtasks.count }} subtask{{ task.subtasks.count|pluralize }}{% if task.is_completed %} unlocked{% else %} — complete this task to unlock{% endif %}</p>
|
<p class="subtask-count"><span aria-hidden="true">↳</span> {{ task.subtasks.count }} subtask{{ task.subtasks.count|pluralize }}{% if task.is_completed %} unlocked{% else %} — complete this task to unlock{% endif %}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<footer class="task-card__footer">
|
<footer class="task-card__footer">
|
||||||
<form method="post" action="{% url 'planner:task-toggle-completed' task.pk %}" hx-post="{% url 'planner:task-toggle-completed' task.pk %}" hx-target="#task-{{ task.pk }}" hx-swap="outerHTML">
|
<form method="post" action="{% url 'planner:task-toggle-completed' task.pk %}" hx-post="{% url 'planner:task-toggle-completed' task.pk %}" hx-target="#task-list" hx-swap="innerHTML">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="status" value="{{ current_filter|default:'active' }}">
|
||||||
<button class="{% if task.is_completed %}status-button{% else %}button button--compact{% endif %} task-completion-button" type="submit">
|
<button class="{% if task.is_completed %}status-button{% else %}button button--compact{% endif %} task-completion-button" type="submit">
|
||||||
{% if task.is_completed %}<span class="status-button__dot" aria-hidden="true"></span>{% endif %}
|
{% if task.is_completed %}<span class="status-button__dot" aria-hidden="true"></span>{% endif %}
|
||||||
{% if task.is_completed %}Completed — reopen{% else %}Mark complete{% endif %}
|
{% if task.is_completed %}Completed — reopen{% else %}Mark complete{% endif %}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
<form method="post" action="{% url 'planner:task-toggle-active' task.pk %}" hx-post="{% url 'planner:task-toggle-active' task.pk %}" hx-target="#task-{{ task.pk }}" hx-swap="outerHTML">
|
<form method="post" action="{% url 'planner:task-toggle-active' task.pk %}" hx-post="{% url 'planner:task-toggle-active' task.pk %}" hx-target="#task-list" hx-swap="innerHTML">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="status" value="{{ current_filter|default:'active' }}">
|
||||||
<button class="status-button" type="submit" aria-label="Mark {{ task.title }} as {% if task.is_active %}inactive{% else %}active{% endif %}">
|
<button class="status-button" type="submit" aria-label="Mark {{ task.title }} as {% if task.is_active %}inactive{% else %}active{% endif %}">
|
||||||
{% if task.is_active %}Active{% else %}Paused{% endif %}
|
{% if task.is_active %}Active{% else %}Paused{% endif %}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<section class="weather-widget" aria-labelledby="weather-heading">
|
<section class="weather-widget" aria-labelledby="{{ weather_heading_id|default:'weather-heading' }}">
|
||||||
<div class="weather-widget__topline"><div><p class="eyebrow">Your forecast</p><h2 id="weather-heading">Weather</h2></div>{% if weather_forecast %}<span class="weather-widget__icon" aria-hidden="true">{{ weather_icon }}</span>{% endif %}</div>
|
<div class="weather-widget__topline"><div><p class="eyebrow">Your forecast</p><h2 id="{{ weather_heading_id|default:'weather-heading' }}">Weather</h2></div>{% if weather_forecast %}<span class="weather-widget__icon" aria-hidden="true">{{ weather_icon }}</span>{% endif %}</div>
|
||||||
{% if weather_forecast %}<p class="weather-widget__reading"><strong>{% if weather_forecast.temperature_max_c is not None %}{{ weather_forecast.temperature_max_c|floatformat:0 }} °C{% else %}—{% endif %}</strong> {{ weather_label }}</p><p class="weather-widget__detail">{% if weather_forecast.precipitation_probability is not None %}{{ weather_forecast.precipitation_probability|floatformat:0 }}% chance of precipitation{% else %}Daily forecast{% endif %}</p>{% elif weather_location_configured %}<p class="weather-widget__detail">Forecast temporarily unavailable. Your tasks will continue as normal.</p>{% else %}<p class="weather-widget__detail">Add a location to see weather-aware plans.</p><a class="text-link" href="{% url 'planner:user-settings' %}">Set location</a>{% endif %}
|
{% if weather_forecast %}<p class="weather-widget__reading"><strong>{% if weather_forecast.temperature_max_c is not None %}{{ weather_forecast.temperature_max_c|floatformat:0 }} °C{% else %}—{% endif %}</strong> {{ weather_label }}</p><p class="weather-widget__detail">{% if weather_forecast.precipitation_probability is not None %}{{ weather_forecast.precipitation_probability|floatformat:0 }}% chance of precipitation{% else %}Daily forecast{% endif %}</p>{% elif weather_location_configured %}<p class="weather-widget__detail">Forecast temporarily unavailable. Your tasks will continue as normal.</p>{% else %}<p class="weather-widget__detail">Add a location to see weather-aware plans.</p><a class="text-link" href="{% url 'planner:user-settings' %}">Set location</a>{% endif %}
|
||||||
</section>
|
</section>
|
||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
{% if onboarding_tour %}{% include 'planner/partials/onboarding_tour.html' %}{% endif %}
|
{% if onboarding_tour %}{% include 'planner/partials/onboarding_tour.html' %}{% endif %}
|
||||||
|
|
||||||
|
{% if user.is_authenticated %}<div class="mobile-weather-slot">{% include 'planner/partials/weather_widget.html' with weather_heading_id='mobile-weather-heading' %}</div>{% endif %}
|
||||||
|
|
||||||
<div class="home-layout">
|
<div class="home-layout">
|
||||||
<div class="home-main">
|
<div class="home-main">
|
||||||
<section class="task-panel{% if onboarding_tour.target == 'tasks' %} onboarding-highlight{% endif %}" aria-label="Task list">
|
<section class="task-panel{% if onboarding_tour.target == 'tasks' %} onboarding-highlight{% endif %}" aria-label="Task list">
|
||||||
@@ -20,9 +22,9 @@
|
|||||||
<div>
|
<div>
|
||||||
<label for="status-filter">Show</label>
|
<label for="status-filter">Show</label>
|
||||||
<select id="status-filter" name="status">
|
<select id="status-filter" name="status">
|
||||||
<option value="all" {% if current_filter == 'all' %}selected{% endif %}>All tasks</option>
|
|
||||||
<option value="active" {% if current_filter == 'active' %}selected{% endif %}>Active tasks</option>
|
<option value="active" {% if current_filter == 'active' %}selected{% endif %}>Active tasks</option>
|
||||||
<option value="inactive" {% if current_filter == 'inactive' %}selected{% endif %}>Inactive tasks</option>
|
<option value="all" {% if current_filter == 'all' %}selected{% endif %}>All tasks</option>
|
||||||
|
<option value="past" {% if current_filter == 'past' %}selected{% endif %}>Past tasks</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="task-filters__actions">
|
<div class="task-filters__actions">
|
||||||
@@ -39,12 +41,10 @@
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
{% include 'planner/partials/workout_section.html' %}
|
{% include 'planner/partials/workout_section.html' %}
|
||||||
{% include 'planner/partials/neck_headache_checkin.html' %}
|
|
||||||
{% include 'planner/partials/bowel_health_checkin.html' %}
|
|
||||||
</div>
|
</div>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<aside class="homepage-sidebar" aria-label="Personal routines">
|
<aside class="homepage-sidebar" aria-label="Personal routines">
|
||||||
{% include 'planner/partials/weather_widget.html' %}
|
<div class="desktop-weather-slot">{% include 'planner/partials/weather_widget.html' %}</div>
|
||||||
{% include 'planner/partials/tooth_brushing_widget.html' %}
|
{% include 'planner/partials/tooth_brushing_widget.html' %}
|
||||||
{% include 'planner/partials/fasting_widget.html' %}
|
{% include 'planner/partials/fasting_widget.html' %}
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import csv
|
||||||
|
import io
|
||||||
|
from datetime import date
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from .models import BowelHealthCheckIn, NeckHeadacheCheckIn
|
||||||
|
|
||||||
|
|
||||||
|
class HealthCsvExportTests(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
User = get_user_model()
|
||||||
|
self.user = User.objects.create_user(username='csv-owner', password='password')
|
||||||
|
self.other = User.objects.create_user(username='csv-other', password='password')
|
||||||
|
for day in (date(2026, 9, 30), date(2026, 10, 1), date(2026, 10, 15), date(2026, 11, 1)):
|
||||||
|
NeckHeadacheCheckIn.objects.create(user=self.user, check_in_date=day,
|
||||||
|
morning_neck_pain_severity=1, morning_headache_severity=2, morning_note='Owner note')
|
||||||
|
BowelHealthCheckIn.objects.create(user=self.user, check_in_date=day,
|
||||||
|
morning_severity=0, afternoon_severity=5, morning_note='Owner note')
|
||||||
|
NeckHeadacheCheckIn.objects.create(user=self.other, check_in_date=date(2026, 10, 2),
|
||||||
|
morning_neck_pain_severity=9, morning_headache_severity=9, morning_note='Private pain')
|
||||||
|
BowelHealthCheckIn.objects.create(user=self.other, check_in_date=date(2026, 10, 2),
|
||||||
|
morning_severity=9, morning_note='Private bowel')
|
||||||
|
|
||||||
|
def download(self, name, period, selected='2026-10-02'):
|
||||||
|
response = self.client.get(reverse(f'planner:{name}-export', args=[period]), {'date': selected})
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(response['Content-Type'], 'text/csv; charset=utf-8')
|
||||||
|
self.assertTrue(response.content.startswith(b'\xef\xbb\xbf'))
|
||||||
|
rows = list(csv.DictReader(io.StringIO(response.content.decode('utf-8-sig'))))
|
||||||
|
return response, rows
|
||||||
|
|
||||||
|
def test_anonymous_exports_require_login(self):
|
||||||
|
for name in ('pain', 'bowel'):
|
||||||
|
self.assertEqual(self.client.get(reverse(f'planner:{name}-export', args=['month'])).status_code, 302)
|
||||||
|
|
||||||
|
def test_month_selection_order_and_privacy(self):
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
for name in ('pain', 'bowel'):
|
||||||
|
response, rows = self.download(name, 'month', '2026-10-15')
|
||||||
|
self.assertEqual([row['Date'] for row in rows], ['2026-10-01', '2026-10-15'])
|
||||||
|
self.assertIn('month_2026-10.csv', response['Content-Disposition'])
|
||||||
|
self.assertNotIn('Private', response.content.decode())
|
||||||
|
self.assertEqual(rows[0]['Daily severity'], '2' if name == 'pain' else '5')
|
||||||
|
|
||||||
|
def test_week_crosses_month_boundary(self):
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
for name in ('pain', 'bowel'):
|
||||||
|
response, rows = self.download(name, 'week')
|
||||||
|
self.assertEqual([row['Date'] for row in rows], ['2026-09-30', '2026-10-01'])
|
||||||
|
self.assertIn('week_2026-09-28_to_2026-10-04.csv', response['Content-Disposition'])
|
||||||
|
|
||||||
|
def test_notes_quoting_unicode_formula_safety_and_blank_periods(self):
|
||||||
|
pain = NeckHeadacheCheckIn.objects.get(user=self.user, check_in_date=date(2026, 10, 1))
|
||||||
|
pain.morning_note = 'Buik, "gevoelig"\nen pijnlijk'
|
||||||
|
pain.afternoon_note = '=SUM(A1:A3)'
|
||||||
|
pain.evening_note = ' +123'
|
||||||
|
pain.save()
|
||||||
|
bowel = BowelHealthCheckIn.objects.get(user=self.user, check_in_date=date(2026, 10, 1))
|
||||||
|
bowel.morning_note = "Buik voelde opgeblazen; 's avonds erger."
|
||||||
|
bowel.afternoon_note = '-123'
|
||||||
|
bowel.evening_note = '@something'
|
||||||
|
bowel.save()
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
_, pain_rows = self.download('pain', 'month')
|
||||||
|
_, bowel_rows = self.download('bowel', 'month')
|
||||||
|
self.assertEqual(pain_rows[0]['Morning notes'], 'Buik, "gevoelig"\nen pijnlijk')
|
||||||
|
self.assertEqual(pain_rows[0]['Afternoon notes'], "'=SUM(A1:A3)")
|
||||||
|
self.assertEqual(pain_rows[0]['Evening notes'], "' +123")
|
||||||
|
self.assertEqual(pain_rows[0]['Afternoon neck pain'], '')
|
||||||
|
self.assertEqual(bowel_rows[0]['Morning notes'], "Buik voelde opgeblazen; 's avonds erger.")
|
||||||
|
self.assertEqual(bowel_rows[0]['Afternoon notes'], "'-123")
|
||||||
|
self.assertEqual(bowel_rows[0]['Evening notes'], "'@something")
|
||||||
|
pain.refresh_from_db()
|
||||||
|
self.assertEqual(pain.afternoon_note, '=SUM(A1:A3)')
|
||||||
|
|
||||||
|
def test_bad_parameters_and_local_date_fallback(self):
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
for name in ('pain', 'bowel'):
|
||||||
|
url = reverse(f'planner:{name}-export', args=['month'])
|
||||||
|
for raw in ('2026-02-30', 'bad', '2026-10-02junk'):
|
||||||
|
self.assertEqual(self.client.get(url, {'date': raw}).status_code, 400)
|
||||||
|
self.assertEqual(self.client.get(reverse(f'planner:{name}-export', args=['year'])).status_code, 400)
|
||||||
|
with patch('planner.health_exports.localdate_for_user', return_value=date(2026, 10, 2)):
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertIn('month_2026-10.csv', response['Content-Disposition'])
|
||||||
|
|
||||||
|
def test_calendar_links_follow_selected_date(self):
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
response = self.client.get(reverse('planner:neck-headache-checkin-panel'), {'date': '2026-09-30'})
|
||||||
|
self.assertContains(response, 'check-ins/export/month/?date=2026-09-30')
|
||||||
|
response = self.client.get(reverse('planner:bowel-health-panel'), {'date': '2026-09-30'})
|
||||||
|
self.assertContains(response, 'bowel-health/export/week/?date=2026-09-30')
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
from datetime import date
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from .models import BowelHealthCheckIn, NeckHeadacheCheckIn, SleepCheckIn
|
||||||
|
|
||||||
|
|
||||||
|
class HealthPageTests(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
User = get_user_model()
|
||||||
|
self.user = User.objects.create_user(username='health-page-user', password='password')
|
||||||
|
self.other = User.objects.create_user(username='other-health-page-user', password='password')
|
||||||
|
self.day = date(2026, 10, 2)
|
||||||
|
|
||||||
|
@patch('planner.views.localdate_for_user', return_value=date(2026, 10, 2))
|
||||||
|
def test_page_reuses_both_panels_and_keeps_records_private(self, _):
|
||||||
|
url = reverse('planner:health')
|
||||||
|
self.assertEqual(url, '/health/')
|
||||||
|
self.assertEqual(self.client.get(url).status_code, 302)
|
||||||
|
NeckHeadacheCheckIn.objects.create(user=self.user, check_in_date=self.day,
|
||||||
|
morning_neck_pain_severity=1, morning_headache_severity=2, morning_note='My neck note')
|
||||||
|
SleepCheckIn.objects.create(user=self.user, wake_up_date=self.day, rested_score=7, note='My sleep note')
|
||||||
|
BowelHealthCheckIn.objects.create(user=self.user, check_in_date=self.day,
|
||||||
|
morning_severity=3, morning_note='My bowel note')
|
||||||
|
NeckHeadacheCheckIn.objects.create(user=self.other, check_in_date=self.day,
|
||||||
|
morning_neck_pain_severity=9, morning_headache_severity=9, morning_note='Other neck note')
|
||||||
|
BowelHealthCheckIn.objects.create(user=self.other, check_in_date=self.day,
|
||||||
|
morning_severity=9, morning_note='Other bowel note')
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
response = self.client.get(url, {'wellbeing_tab': 'sleep', 'check_in_date': self.day.isoformat(),
|
||||||
|
'bowel_date': self.day.isoformat()})
|
||||||
|
self.assertContains(response, 'id="neck-headache-checkin"')
|
||||||
|
self.assertContains(response, 'id="bowel-health-checkin"')
|
||||||
|
self.assertContains(response, 'My bowel note')
|
||||||
|
self.assertContains(response, 'Sleep scores over time')
|
||||||
|
self.assertNotContains(response, 'Other neck note')
|
||||||
|
self.assertNotContains(response, 'Other bowel note')
|
||||||
|
self.assertContains(response, 'href="/health/?check_in_date=')
|
||||||
|
dashboard = self.client.get(reverse('planner:task-list'))
|
||||||
|
self.assertContains(dashboard, 'href="/health/"')
|
||||||
|
self.assertNotContains(dashboard, 'id="neck-headache-checkin"')
|
||||||
|
self.assertNotContains(dashboard, 'id="bowel-health-checkin"')
|
||||||
|
|
||||||
|
@patch('planner.views.localdate_for_user', return_value=date(2026, 10, 2))
|
||||||
|
@patch('planner.forms.localdate_for_user', return_value=date(2026, 10, 2))
|
||||||
|
def test_non_htmx_saves_return_to_health(self, _form_today, _view_today):
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
pain = self.client.post(reverse('planner:neck-headache-checkin-save'), {
|
||||||
|
'check_in_date': '2026-10-02', 'morning_neck_pain_severity': '1',
|
||||||
|
'morning_headache_severity': '2',
|
||||||
|
})
|
||||||
|
self.assertEqual(pain.status_code, 302)
|
||||||
|
self.assertTrue(pain['Location'].startswith('/health/?check_in_date=2026-10-02'))
|
||||||
|
sleep = self.client.post(reverse('planner:sleep-checkin-save'), {
|
||||||
|
'wake_up_date': '2026-10-02', 'rested_score': '7',
|
||||||
|
})
|
||||||
|
self.assertEqual(sleep.status_code, 302)
|
||||||
|
self.assertIn('wellbeing_tab=sleep', sleep['Location'])
|
||||||
|
bowel = self.client.post(reverse('planner:bowel-health-save'), {
|
||||||
|
'check_in_date': '2026-10-02', 'morning_severity': '3',
|
||||||
|
})
|
||||||
|
self.assertEqual(bowel.status_code, 302)
|
||||||
|
self.assertTrue(bowel['Location'].startswith('/health/?bowel_date=2026-10-02'))
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
from datetime import date
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from .models import Task
|
||||||
|
|
||||||
|
|
||||||
|
class TaskFilterTests(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
User = get_user_model()
|
||||||
|
self.user = User.objects.create_user(username='filter-owner', password='password')
|
||||||
|
self.other = User.objects.create_user(username='filter-other', password='password')
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
self.active = Task.objects.create(owner=self.user, title='Current work', scheduled_for=date(2026, 10, 2))
|
||||||
|
self.past = Task.objects.create(owner=self.user, title='Finished work', scheduled_for=date(2026, 10, 1), is_completed=True)
|
||||||
|
self.paused = Task.objects.create(owner=self.user, title='Paused work', scheduled_for=date(2026, 10, 3), is_active=False)
|
||||||
|
Task.objects.create(owner=self.other, title='Private work', scheduled_for=date(2026, 10, 2))
|
||||||
|
|
||||||
|
def test_active_is_default_and_filter_order_is_active_all_past(self):
|
||||||
|
response = self.client.get(reverse('planner:task-list'))
|
||||||
|
self.assertEqual(response.context['current_filter'], 'active')
|
||||||
|
self.assertContains(response, 'Current work')
|
||||||
|
self.assertNotContains(response, 'Finished work')
|
||||||
|
self.assertNotContains(response, 'Paused work')
|
||||||
|
self.assertNotContains(response, 'Private work')
|
||||||
|
html = response.content.decode()
|
||||||
|
self.assertLess(html.index('value="active"'), html.index('value="all"'))
|
||||||
|
self.assertLess(html.index('value="all"'), html.index('value="past"'))
|
||||||
|
|
||||||
|
def test_all_includes_every_owned_task_and_past_only_completed(self):
|
||||||
|
all_response = self.client.get(reverse('planner:task-list'), {'status': 'all'})
|
||||||
|
for title in ('Current work', 'Finished work', 'Paused work'):
|
||||||
|
self.assertContains(all_response, title)
|
||||||
|
self.assertNotContains(all_response, 'Private work')
|
||||||
|
past_response = self.client.get(reverse('planner:task-list'), {'status': 'past'}, HTTP_HX_REQUEST='true')
|
||||||
|
self.assertContains(past_response, 'Finished work')
|
||||||
|
self.assertNotContains(past_response, 'Current work')
|
||||||
|
self.assertNotContains(past_response, 'Paused work')
|
||||||
|
|
||||||
|
def test_completion_moves_task_from_active_to_past_without_reload(self):
|
||||||
|
response = self.client.post(reverse('planner:task-toggle-completed', args=[self.active.pk]),
|
||||||
|
{'status': 'active'}, HTTP_HX_REQUEST='true')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertNotContains(response, 'Current work')
|
||||||
|
self.active.refresh_from_db()
|
||||||
|
self.assertTrue(self.active.is_completed)
|
||||||
|
self.assertContains(self.client.get(reverse('planner:task-list'), {'status': 'past'}), 'Current work')
|
||||||
|
response = self.client.post(reverse('planner:task-toggle-completed', args=[self.active.pk]),
|
||||||
|
{'status': 'past'}, HTTP_HX_REQUEST='true')
|
||||||
|
self.assertNotContains(response, 'Current work')
|
||||||
|
self.active.refresh_from_db()
|
||||||
|
self.assertFalse(self.active.is_completed)
|
||||||
|
|
||||||
|
def test_pausing_last_active_task_shows_empty_state(self):
|
||||||
|
response = self.client.post(reverse('planner:task-toggle-active', args=[self.active.pk]),
|
||||||
|
{'status': 'active'}, HTTP_HX_REQUEST='true')
|
||||||
|
self.assertContains(response, 'No tasks here')
|
||||||
|
self.assertNotContains(response, 'Current work')
|
||||||
@@ -201,7 +201,7 @@ class TaskCRUDViewTests(TestCase):
|
|||||||
self.assertNotContains(response, inactive.title)
|
self.assertNotContains(response, inactive.title)
|
||||||
self.assertTemplateUsed(response, 'planner/partials/task_list_content.html')
|
self.assertTemplateUsed(response, 'planner/partials/task_list_content.html')
|
||||||
|
|
||||||
def test_htmx_toggle_active_replaces_task_card(self):
|
def test_htmx_toggle_active_refreshes_filtered_list(self):
|
||||||
task = self.create_task()
|
task = self.create_task()
|
||||||
|
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
@@ -212,8 +212,8 @@ class TaskCRUDViewTests(TestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
task.refresh_from_db()
|
task.refresh_from_db()
|
||||||
self.assertFalse(task.is_active)
|
self.assertFalse(task.is_active)
|
||||||
self.assertContains(response, 'Paused')
|
self.assertContains(response, 'No tasks here')
|
||||||
self.assertContains(response, f'id="task-{task.pk}"')
|
self.assertNotContains(response, f'id="task-{task.pk}"')
|
||||||
|
|
||||||
def test_form_only_offers_top_level_tasks_as_parents(self):
|
def test_form_only_offers_top_level_tasks_as_parents(self):
|
||||||
parent = self.create_task('Parent')
|
parent = self.create_task('Parent')
|
||||||
@@ -1477,7 +1477,9 @@ class TaskCompletionViewTests(TestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.parent.refresh_from_db()
|
self.parent.refresh_from_db()
|
||||||
self.assertTrue(self.parent.is_completed)
|
self.assertTrue(self.parent.is_completed)
|
||||||
self.assertContains(response, 'subtask unlocked')
|
self.assertNotContains(response, 'Wash clothes')
|
||||||
|
past = self.client.get(reverse('planner:task-list'), {'status': 'past'})
|
||||||
|
self.assertContains(past, 'subtask unlocked')
|
||||||
|
|
||||||
after = self.client.get(reverse('planner:daily-planner'), {
|
after = self.client.get(reverse('planner:daily-planner'), {
|
||||||
'selected_date': self.today.isoformat(), 'energy_level': 3,
|
'selected_date': self.today.isoformat(), 'energy_level': 3,
|
||||||
@@ -1509,4 +1511,3 @@ class TaskCompletionViewTests(TestCase):
|
|||||||
self.client.post(reverse('planner:task-toggle-completed', args=[foreign.pk])).status_code,
|
self.client.post(reverse('planner:task-toggle-completed', args=[foreign.pk])).status_code,
|
||||||
404,
|
404,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from .health_exports import export_bowel_csv, export_pain_csv
|
||||||
|
|
||||||
from .views import (
|
from .views import (
|
||||||
DailyPlannerView, TaskCreateView, category_suggestions, TaskDeleteView, TaskDetailView, TaskListView,
|
DailyPlannerView, HealthView, TaskCreateView, category_suggestions, TaskDeleteView, TaskDetailView, TaskListView,
|
||||||
TaskUpdateView, WorkoutCreateView, WorkoutUpdateView, delete_workout, fasting_configure, neck_headache_checkin_panel,
|
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,
|
fasting_toggle_tracking, fasting_widget, logout_view, register, toggle_task_active, toggle_task_completed,
|
||||||
save_neck_headache_checkin, save_sleep_checkin, advance_onboarding, toggle_workout_completed, user_settings, workout_today,
|
save_neck_headache_checkin, save_sleep_checkin, advance_onboarding, toggle_workout_completed, user_settings, workout_today,
|
||||||
@@ -13,6 +15,7 @@ app_name = 'planner'
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', TaskListView.as_view(), name='task-list'),
|
path('', TaskListView.as_view(), name='task-list'),
|
||||||
|
path('health/', HealthView.as_view(), name='health'),
|
||||||
path('login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'),
|
path('login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'),
|
||||||
path('register/', register, name='register'),
|
path('register/', register, name='register'),
|
||||||
path('logout/', logout_view, name='logout'),
|
path('logout/', logout_view, name='logout'),
|
||||||
@@ -28,6 +31,8 @@ urlpatterns = [
|
|||||||
path('teeth/toggle/', toggle_tooth_brushing, name='tooth-brushing-toggle'),
|
path('teeth/toggle/', toggle_tooth_brushing, name='tooth-brushing-toggle'),
|
||||||
path('bowel-health/panel/', bowel_health_panel, name='bowel-health-panel'),
|
path('bowel-health/panel/', bowel_health_panel, name='bowel-health-panel'),
|
||||||
path('bowel-health/save/', save_bowel_health_checkin, name='bowel-health-save'),
|
path('bowel-health/save/', save_bowel_health_checkin, name='bowel-health-save'),
|
||||||
|
path('check-ins/export/<str:period>/', export_pain_csv, name='pain-export'),
|
||||||
|
path('bowel-health/export/<str:period>/', export_bowel_csv, name='bowel-export'),
|
||||||
path('workouts/today/', workout_today, name='workout-today'),
|
path('workouts/today/', workout_today, name='workout-today'),
|
||||||
path('workouts/new/', WorkoutCreateView.as_view(), name='workout-create'),
|
path('workouts/new/', WorkoutCreateView.as_view(), name='workout-create'),
|
||||||
path('workouts/<int:pk>/edit/', WorkoutUpdateView.as_view(), name='workout-update'),
|
path('workouts/<int:pk>/edit/', WorkoutUpdateView.as_view(), name='workout-update'),
|
||||||
|
|||||||
+47
-19
@@ -53,7 +53,7 @@ ONBOARDING_STEPS = (
|
|||||||
{
|
{
|
||||||
'target': 'wellbeing',
|
'target': 'wellbeing',
|
||||||
'title': 'Keep a lightweight wellbeing record',
|
'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.',
|
'copy': 'Open Health for pain, sleep, and bowel check-ins, with calendars that make past days easy to revisit.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'target': 'fasting',
|
'target': 'fasting',
|
||||||
@@ -398,7 +398,7 @@ def save_neck_headache_checkin(request):
|
|||||||
if request.headers.get('HX-Request') == 'true':
|
if request.headers.get('HX-Request') == 'true':
|
||||||
return render_check_in_panel(request, check_in.check_in_date)
|
return render_check_in_panel(request, check_in.check_in_date)
|
||||||
return redirect(
|
return redirect(
|
||||||
reverse('planner:task-list') + '?check_in_date=' + check_in.check_in_date.isoformat()
|
reverse('planner:health') + '?check_in_date=' + check_in.check_in_date.isoformat() + '#neck-headache-checkin'
|
||||||
)
|
)
|
||||||
return render_check_in_panel(request, selected_date, form)
|
return render_check_in_panel(request, selected_date, form)
|
||||||
|
|
||||||
@@ -419,7 +419,7 @@ def save_sleep_checkin(request):
|
|||||||
if request.headers.get('HX-Request') == 'true':
|
if request.headers.get('HX-Request') == 'true':
|
||||||
return render_check_in_panel(request, check_in.wake_up_date, active_tab='sleep')
|
return render_check_in_panel(request, check_in.wake_up_date, active_tab='sleep')
|
||||||
return redirect(
|
return redirect(
|
||||||
reverse('planner:task-list') + '?check_in_date=' + check_in.wake_up_date.isoformat()
|
reverse('planner:health') + '?check_in_date=' + check_in.wake_up_date.isoformat() + '&wellbeing_tab=sleep#neck-headache-checkin'
|
||||||
)
|
)
|
||||||
return render_check_in_panel(request, selected_date, sleep_form=form, active_tab='sleep')
|
return render_check_in_panel(request, selected_date, sleep_form=form, active_tab='sleep')
|
||||||
|
|
||||||
@@ -460,7 +460,7 @@ def save_bowel_health_checkin(request):
|
|||||||
entry.save()
|
entry.save()
|
||||||
if request.headers.get('HX-Request') == 'true':
|
if request.headers.get('HX-Request') == 'true':
|
||||||
return render(request, 'planner/partials/bowel_health_checkin.html', bowel_context(request.user, entry.check_in_date))
|
return render(request, 'planner/partials/bowel_health_checkin.html', bowel_context(request.user, entry.check_in_date))
|
||||||
return redirect(reverse('planner:task-list') + '?bowel_date=' + entry.check_in_date.isoformat() + '#bowel-health-checkin')
|
return redirect(reverse('planner:health') + '?bowel_date=' + entry.check_in_date.isoformat() + '#bowel-health-checkin')
|
||||||
return render(request, 'planner/partials/bowel_health_checkin.html', bowel_context(request.user, selected_date, form))
|
return render(request, 'planner/partials/bowel_health_checkin.html', bowel_context(request.user, selected_date, form))
|
||||||
|
|
||||||
|
|
||||||
@@ -471,19 +471,34 @@ class OwnedTaskQuerysetMixin(LoginRequiredMixin):
|
|||||||
return Task.objects.filter(owner=self.request.user).prefetch_related('subtasks')
|
return Task.objects.filter(owner=self.request.user).prefetch_related('subtasks')
|
||||||
|
|
||||||
|
|
||||||
|
def task_filter_status(value):
|
||||||
|
return value if value in {'active', 'all', 'past'} else 'active'
|
||||||
|
|
||||||
|
|
||||||
|
def tasks_for_filter(user, status):
|
||||||
|
tasks = Task.objects.filter(owner=user, parent_task__isnull=True).prefetch_related('subtasks')
|
||||||
|
if status == 'active':
|
||||||
|
return tasks.filter(is_active=True, is_completed=False)
|
||||||
|
if status == 'past':
|
||||||
|
return tasks.filter(is_completed=True).order_by('-scheduled_for', 'title')
|
||||||
|
return tasks
|
||||||
|
|
||||||
|
|
||||||
|
def render_task_list(request, status):
|
||||||
|
tasks = add_predicted_weather(request.user, tasks_for_filter(request.user, status))
|
||||||
|
return render(request, 'planner/partials/task_list_content.html', {'tasks': tasks, 'current_filter': status})
|
||||||
|
|
||||||
|
|
||||||
class TaskListView(LoginRequiredMixin, ListView):
|
class TaskListView(LoginRequiredMixin, ListView):
|
||||||
model = Task
|
model = Task
|
||||||
context_object_name = 'tasks'
|
context_object_name = 'tasks'
|
||||||
template_name = 'planner/task_list.html'
|
template_name = 'planner/task_list.html'
|
||||||
|
|
||||||
|
def task_filter(self):
|
||||||
|
return task_filter_status(self.request.GET.get('status', 'active'))
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = Task.objects.filter(owner=self.request.user, parent_task__isnull=True).prefetch_related('subtasks')
|
return tasks_for_filter(self.request.user, self.task_filter())
|
||||||
status = self.request.GET.get('status')
|
|
||||||
if status == 'active':
|
|
||||||
queryset = queryset.filter(is_active=True)
|
|
||||||
elif status == 'inactive':
|
|
||||||
queryset = queryset.filter(is_active=False)
|
|
||||||
return queryset
|
|
||||||
|
|
||||||
def get_template_names(self):
|
def get_template_names(self):
|
||||||
if self.request.headers.get('HX-Request') == 'true':
|
if self.request.headers.get('HX-Request') == 'true':
|
||||||
@@ -493,18 +508,28 @@ class TaskListView(LoginRequiredMixin, ListView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['tasks'] = add_predicted_weather(self.request.user, context['tasks'])
|
context['tasks'] = add_predicted_weather(self.request.user, context['tasks'])
|
||||||
context['current_filter'] = self.request.GET.get('status', 'all')
|
context['current_filter'] = self.task_filter()
|
||||||
context.update(fasting_widget_context(self.request.user))
|
context.update(fasting_widget_context(self.request.user))
|
||||||
context.update(dashboard_weather_context(self.request.user))
|
context.update(dashboard_weather_context(self.request.user))
|
||||||
context.update(workout_context(self.request.user))
|
context.update(workout_context(self.request.user))
|
||||||
context.update(brushing_context(self.request.user))
|
context.update(brushing_context(self.request.user))
|
||||||
profile, _ = UserSettings.objects.get_or_create(user=self.request.user)
|
profile, _ = UserSettings.objects.get_or_create(user=self.request.user)
|
||||||
context['onboarding_tour'] = onboarding_context(profile)
|
context['onboarding_tour'] = onboarding_context(profile)
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class HealthView(LoginRequiredMixin, TemplateView):
|
||||||
|
template_name = 'planner/health.html'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
context.update(check_in_context(
|
context.update(check_in_context(
|
||||||
self.request.user, selected_check_in_date(self.request.GET.get('check_in_date'), self.request.user),
|
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')
|
active_tab=self.request.GET.get('wellbeing_tab', 'pain'),
|
||||||
|
))
|
||||||
|
context.update(bowel_context(
|
||||||
|
self.request.user, selected_check_in_date(self.request.GET.get('bowel_date'), self.request.user),
|
||||||
))
|
))
|
||||||
context.update(bowel_context(self.request.user, selected_check_in_date(self.request.GET.get('bowel_date'), self.request.user)))
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
@@ -561,8 +586,7 @@ class TaskCreateView(LoginRequiredMixin, CreateView):
|
|||||||
form.instance.owner = self.request.user
|
form.instance.owner = self.request.user
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
if self.request.headers.get('HX-Request') == 'true':
|
if self.request.headers.get('HX-Request') == 'true':
|
||||||
tasks = Task.objects.filter(owner=self.request.user, parent_task__isnull=True).prefetch_related('subtasks')
|
return render_task_list(self.request, 'active')
|
||||||
return render(self.request, 'planner/partials/task_list_content.html', {'tasks': add_predicted_weather(self.request.user, tasks)})
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@@ -669,9 +693,10 @@ def toggle_task_completed(request, pk):
|
|||||||
response['HX-Redirect'] = destination
|
response['HX-Redirect'] = destination
|
||||||
return response
|
return response
|
||||||
return redirect(destination)
|
return redirect(destination)
|
||||||
|
current_filter = task_filter_status(request.POST.get('status'))
|
||||||
if request.headers.get('HX-Request') != 'true':
|
if request.headers.get('HX-Request') != 'true':
|
||||||
return redirect('planner:task-list')
|
return redirect(reverse('planner:task-list') + '?status=' + current_filter)
|
||||||
return render(request, 'planner/partials/task_card.html', {'task': task})
|
return render_task_list(request, current_filter)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -680,7 +705,10 @@ def toggle_task_active(request, pk):
|
|||||||
task = get_object_or_404(Task.objects.prefetch_related('subtasks'), pk=pk, owner=request.user)
|
task = get_object_or_404(Task.objects.prefetch_related('subtasks'), pk=pk, owner=request.user)
|
||||||
task.is_active = not task.is_active
|
task.is_active = not task.is_active
|
||||||
task.save(update_fields=['is_active', 'updated_at'])
|
task.save(update_fields=['is_active', 'updated_at'])
|
||||||
return render(request, 'planner/partials/task_card.html', {'task': task})
|
current_filter = task_filter_status(request.POST.get('status'))
|
||||||
|
if request.headers.get('HX-Request') != 'true':
|
||||||
|
return redirect(reverse('planner:task-list') + '?status=' + current_filter)
|
||||||
|
return render_task_list(request, current_filter)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
Reference in New Issue
Block a user