Fix OAuth page

This commit is contained in:
Joren de Graaf
2026-10-19 16:51:53 +02:00
parent a8418cdba7
commit 743785c2e0
54 changed files with 1794 additions and 27 deletions
+27 -2
View File
@@ -1,5 +1,5 @@
from datetime import timedelta
from decimal import Decimal
from decimal import Decimal, ROUND_HALF_UP
from django.utils import timezone
from django.utils.dateparse import parse_date
@@ -11,6 +11,26 @@ from planner.timezones import localdate_for_user
ZERO = Decimal('0')
def ring_progress(amount, goal):
"""Presentation values for a two-lap ring; totals and goals stay untouched.
After two laps, the inner arc shows progress in the current lap. The
accompanying text states how many full laps have already been completed.
"""
progress = max(ZERO, amount * 100 / goal)
whole_laps = int(progress // 100)
current_lap = progress % 100
if progress and current_lap == 0:
current_lap = Decimal('100')
return {
'percent': int(progress.quantize(Decimal('1'), rounding=ROUND_HALF_UP)),
'base_lap': format(min(progress, Decimal('100')), '.2f'),
'extra_lap': format(current_lap if progress > 100 else ZERO, '.2f'),
'full_laps': whole_laps,
'current_lap': current_lap,
}
NUTRIENT_NAMES = ('calories_kcal', 'carbohydrates_g', 'protein_g', 'fat_g', 'fibre_g', 'sugars_g', 'salt_g')
NUTRIENT_LABELS = {'calories_kcal': 'calories', 'carbohydrates_g': 'carbs',
'protein_g': 'protein', 'fat_g': 'fat', 'fibre_g': 'fibre',
@@ -72,10 +92,15 @@ def diary_context(user, day, language='en'):
):
eaten = totals[name]
is_incomplete = incomplete[name]
ring = ring_progress(eaten, goal) if goal and (known_counts[name] or not entries) else None
macros.append({'label': label, 'slug': name, 'guidance': nutrient_guidance(name, language),
'eaten': eaten if known_counts[name] or not entries else None, 'goal': goal,
'remaining': goal - eaten if goal is not None and not is_incomplete else None,
'percent': min(100, int(eaten * 100 / goal)) if goal and (known_counts[name] or not entries) else None,
'percent': ring['percent'] if ring else None,
'base_lap': ring['base_lap'] if ring else ZERO,
'extra_lap': ring['extra_lap'] if ring else ZERO,
'full_laps': ring['full_laps'] if ring else 0,
'current_lap': ring['current_lap'] if ring else ZERO,
'color': color, 'incomplete': is_incomplete})
calorie_goal = goals.daily_calorie_goal
calories = totals['calories_kcal']