latest changes

This commit is contained in:
Joren de Graaf
2026-10-22 10:32:41 +02:00
parent 5799b542c8
commit 5b986134be
63 changed files with 2412 additions and 77 deletions
+34 -5
View File
@@ -1,14 +1,43 @@
"""Template context shared by Tasknest pages."""
from .models import UserSettings
from django.urls import reverse
def appearance(request):
"""Expose the signed-in user’s saved colour preference without creating settings."""
user = getattr(request, "user", None)
if user is not None and user.is_authenticated:
saved_appearance = (
UserSettings.objects.filter(user=user).values_list("appearance", flat=True).first()
)
return {"user_appearance": saved_appearance or UserSettings.Appearance.LIGHT}
return {"user_appearance": UserSettings.Appearance.LIGHT}
profile = UserSettings.objects.filter(user=user).values('appearance', 'is_demo').first()
return {"user_appearance": profile['appearance'] if profile else UserSettings.Appearance.LIGHT,
"is_demo_account": bool(profile and profile['is_demo'])}
return {"user_appearance": UserSettings.Appearance.LIGHT, "is_demo_account": False}
def navigation(request):
"""A single site navigation tree for desktop and mobile."""
user = getattr(request, 'user', None)
if not user or not user.is_authenticated:
return {'nav_groups': ()}
current = request.path
definitions = (
('tasks', 'My tasks', 'planner:task-list', (('Daily planner', 'planner:daily-planner'),)),
('health', 'Health', 'planner:health', (('Stress', 'stress:journal'), ('Dreams', 'dreams:journal'))),
('food', 'Food', 'food:diary', (('Recipes', 'recipes:list'),
('Kitchen Inventory', 'food:inventory'),
('Groceries', 'groceries:index'))),
)
groups = []
for key, label, route, children in definitions:
url = reverse(route)
items = [{'label': child_label, 'url': reverse(child_route),
'active': current.startswith(reverse(child_route))}
for child_label, child_route in children]
# Food's root URL is a prefix of its children; exact match keeps its parent state clear.
parent_active = current == url or (key == 'food' and
getattr(request.resolver_match, 'namespace', '') == 'food' and
not any(item['active'] for item in items))
groups.append({'key': key, 'label': label, 'url': url, 'items': items,
'parent_active': parent_active,
'active': parent_active or any(item['active'] for item in items)})
return {'nav_groups': groups}