Self hosted FLOSS fitness/workout, nutrition and weight tracker
Merge PR #2422 (WorkoutSession overnight refactor) for 2.7 integration testing
Roland Geidercbfab7ca3944
diff --cc CHANGELOG.mdindex 79d8e4d03,a6862965a..a82f7a853--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -2,34 -2,24 +2,56 @@@## New features+* Improved openAPI spec. The spec now properly describes the different parts of+ the API and can be used to generate clients.++### OAuth2 provider++wger can now act as an OAuth2 provider itself, so that other applications can let+their users log in with their wger account and access the API on their behalf. This+is switched off by default unless configured, see the docs for the setup.++* <https://wger.readthedocs.io/en/latest/administration/oauth2_provider.html>++ ### Others++ * Reworked internal structure for workout sessions. This now allows sessions to span+ midnight, and to log more than one session per day, e.g. morning cardio and evening+ gym.++## Bug fixes++* Gated progressions (configs with `requirements`) now advance exactly one step+ per qualifying workout instead of back-filling increments for skipped,+ non-qualifying iterations+* Gated progressions now reach configs scheduled for later iterations, so+ multi-phase plans (e.g. bigger increments from week 6 on) work when the+ requirements are only met intermittently+* Ungated configs no longer back-apply increments of earlier gated configs+ whose requirements were never met+* Progression requirements are now checked against the rounded values as they+ are displayed, so reaching the shown prescription always counts+* The min and max configs of a field now advance together, following the+ requirements of the base config++ ## Breaking changes++ *(only relevant if you have your own scripts or interact with the REST API)*++ **`/api/v2/workoutsession/` now uses `datetime_start` and `datetime_end`.** The+ old `date`, `time_start` and `time_end` fields are gone from the responses and+ can no longer be filtered or sorted by. They are still accepted when writing so+ that offline writes queued by an older app version still arrive, but that is a+ temporary measure and will be removed in the next release.++ * Sessions are no longer unique per user, day and routine.++ * `datetime_start` and `datetime_end` support `gt`, `gte`, `lt`, `lte` and+ `date`, so a single day is selected with `?datetime_start__date=2026-01-15`+ and a range with `?datetime_start__gte=...`.+++## Removed++* Removed the temporary `/api/v2/issue-refresh-token` endpoint. It existed only+ so the mobile app could exchange a permanent DRF token for a JWT refresh+ token. That migration has shipped and the app no longer calls it.diff --cc settings/main.pyindex b7319c0c7,85828dd11..5c7e0d317--- a/settings/main.py+++ b/settings/main.py@@@ -197,7 -192,7 +197,8 @@@ WGER_SETTINGS['CACHE_API_EXERCISES_CELEWGER_SETTINGS['CACHE_API_EXERCISES_CELERY_FORCE_UPDATE'] = env.bool('CACHE_API_EXERCISES_CELERY_FORCE_UPDATE', False)+WGER_SHOW_APP_STORE_LINKS = env.bool('WGER_SHOW_APP_STORE_LINKS', True)+ WGER_MAX_SESSION_LENGTH_HOURS = env.int('WGER_MAX_SESSION_LENGTH_HOURS', 5)## Auth Proxy Authenticationdiff --cc wger/manager/models/log.pyindex 0ab157720,9fa4f2f1e..137fb0471--- a/wger/manager/models/log.py+++ b/wger/manager/models/log.py@@@ -248,6 -254,52 +254,58 @@@ class WorkoutLog(models.Model)if self.weight is not None and self.weight_unit is None:raise ValidationError('Weight unit must be present if weight has a value.')+ def assign_session(self):+ """+ Attach this log to a session, creating one if nothing fits++ In order: a session the log falls into, then the most recent session that+ is still open and started no longer than a session may last ago, otherwise+ a new one.+ """+ log_date = self.date+ if isinstance(log_date, datetime.date) and not isinstance(log_date, datetime.datetime):+ log_date = timezone.make_aware(datetime.datetime.combine(log_date, datetime.time()))+ elif timezone.is_naive(log_date):+ log_date = timezone.make_aware(log_date)++ # Looking up and creating has to happen as one step, otherwise a batch+ # upload creates a session per log. There is no row yet that could be+ # locked, so the user row stands in for it.+ with transaction.atomic():+ User.objects.select_for_update().filter(pk=self.user_id).first()++ session = WorkoutSession.objects.filter(+ user=self.user,+ routine=self.routine,+ datetime_start__lte=log_date,+ datetime_end__gte=log_date,+ ).first()++ if not session:+ session = (+ WorkoutSession.objects.filter(+ user=self.user,+ routine=self.routine,+ datetime_end__isnull=True,+ datetime_start__gte=log_date - WorkoutSession.max_duration(),+ datetime_start__lte=log_date,+ )+ .order_by('-datetime_start')+ .first()+ )+++ # The day is only a default for new sessions, existing ones keep theirs++ day = None++ if self.slot_entry and self.slot_entry.slot.day.routine_id == self.routine_id:++ day = self.slot_entry.slot.day+++ self.session = session or WorkoutSession.objects.create(+ user=self.user,+ datetime_start=log_date,+ routine=self.routine,++ day=day,+ )+def save(self, *args, **kwargs):"""Plumbing