Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Allow need_log_to_apply to be nullable as well

Roland Geider1af701b47692
diff --git a/wger/manager/api/serializers.py b/wger/manager/api/serializers.py
index 9c8fb0c64..68d0585b3 100644
--- a/wger/manager/api/serializers.py
+++ b/wger/manager/api/serializers.py
@@ -226,6 +226,7 @@ class DayStructureSerializer(serializers.ModelSerializer):
model = Day
fields = (
'id',
+ 'routine',
'next_day',
'name',
'description',
diff --git a/wger/manager/api/views.py b/wger/manager/api/views.py
index ebd9e334a..0c03bec2f 100644
--- a/wger/manager/api/views.py
+++ b/wger/manager/api/views.py
@@ -21,7 +21,6 @@ from datetime import datetime
# Django
from django.shortcuts import get_object_or_404
-
# Third Party
from rest_framework import viewsets
from rest_framework.decorators import action
@@ -32,6 +31,7 @@ from wger.exercises.models import ExerciseBase
from wger.manager.api.consts import CONFIG_FIELDS
from wger.manager.api.serializers import (
DaySerializer,
+ DayStructureSerializer,
LogDataSerializer,
MaxRepsConfigSerializer,
MaxRestConfigSerializer,
@@ -53,6 +53,7 @@ from wger.manager.api.serializers import (
WorkoutTemplateSerializer,
)
from wger.manager.models import (
+ Day,
MaxRepsConfig,
MaxRestConfig,
MaxWeightConfig,
@@ -151,7 +152,8 @@ class RoutineViewSet(viewsets.ModelViewSet):
"""
return Response(
WorkoutDayDataDisplayModeSerializer(
- self.get_object().data_for_iteration(), many=True
+ self.get_object().data_for_iteration(),
+ many=True,
).data
)
@@ -436,6 +438,48 @@ class WorkoutLogViewSet(WgerOwnerObjectModelViewSet):
return [(Workout, 'workout')]
+class RoutineDayViewSet(WgerOwnerObjectModelViewSet):
+ """
+ API endpoint for routine day objects
+ """
+
+ serializer_class = DayStructureSerializer
+ is_private = True
+ ordering_fields = '__all__'
+ filterset_fields = (
+ 'id',
+ 'next_day',
+ 'name',
+ 'description',
+ 'is_rest',
+ 'last_day_in_week',
+ 'need_logs_to_advance',
+ 'slots',
+ )
+
+ def get_queryset(self):
+ """
+ Only allow access to appropriate objects
+ """
+ # REST API generation
+ if getattr(self, 'swagger_fake_view', False):
+ return Day.objects.none()
+
+ return Day.objects.filter(routine__user=self.request.user)
+
+ def perform_create(self, serializer):
+ """
+ Set the owner
+ """
+ serializer.save(user=self.request.user)
+
+ def get_owner_objects(self):
+ """
+ Return objects to check for ownership permission
+ """
+ return [(Routine, 'routine')]
+
+
class AbstractConfigViewSet(WgerOwnerObjectModelViewSet):
"""
API endpoint for weight config objects
diff --git a/wger/manager/migrations/0018_flexible_routines.py b/wger/manager/migrations/0018_flexible_routines.py
index 1695e0e9f..e9d1b37b1 100644
--- a/wger/manager/migrations/0018_flexible_routines.py
+++ b/wger/manager/migrations/0018_flexible_routines.py
@@ -1,9 +1,10 @@
# Generated by Django 4.2.6 on 2024-03-12 15:17
import datetime
+
+import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
-import django.db.models.deletion
class Migration(migrations.Migration):
@@ -359,7 +360,7 @@ class Migration(migrations.Migration):
),
),
('replace', models.BooleanField(default=False)),
- ('need_log_to_apply', models.BooleanField(default=False)),
+ ('need_log_to_apply', models.BooleanField(default=False, null=True)),
(
'slot_config',
models.ForeignKey(
diff --git a/wger/manager/models/abstract_config.py b/wger/manager/models/abstract_config.py
index b2247421a..b4bac66ff 100644
--- a/wger/manager/models/abstract_config.py
+++ b/wger/manager/models/abstract_config.py
@@ -80,6 +80,7 @@ class AbstractChangeConfig(models.Model):
need_log_to_apply = models.BooleanField(
default=False,
+ null=True,
)
"""
Only apply the change if the user logged the last weight, otherwise
@@ -87,13 +88,19 @@ class AbstractChangeConfig(models.Model):
"""
def save(self, **kwargs):
- # Override values for the first iteration. While these would be ignored
- # in the calculations anyway, this is cleaner
+ # Cleanup some combinations. While these would be ignored in the
+ # calculations anyway, this makes it cleaner
+
+ # Override values for the first iteration.
if self.iteration == 1:
self.replace = True
- self.need_log_to_apply = False
+
+ # Override values for replace
+ if self.replace:
+ self.need_log_to_apply = None
self.step = None
self.operation = None
+
super().save(**kwargs)
def get_owner_object(self):
diff --git a/wger/urls.py b/wger/urls.py
index 9f8845442..4ff616563 100644
--- a/wger/urls.py
+++ b/wger/urls.py
@@ -25,7 +25,6 @@ from django.contrib.sitemaps.views import (
sitemap,
)
from django.urls import path
-
# Third Party
from django_email_verification import urls as email_urls
from drf_spectacular.views import (
@@ -48,11 +47,9 @@ from wger.gallery.api import views as gallery_api_views
from wger.manager.api import views as manager_api_views
from wger.measurements.api import views as measurements_api_views
from wger.nutrition.api import views as nutrition_api_views
-from wger.nutrition.sitemap import NutritionSitemap
from wger.utils.generic_views import TextTemplateView
from wger.weight.api import views as weight_api_views
-
#
# REST API
#
@@ -76,6 +73,7 @@ router.register(
manager_api_views.WorkoutSessionViewSet,
basename='workoutsession',
)
+router.register(r'day', manager_api_views.RoutineDayViewSet, basename='day')
router.register(r'workoutlog', manager_api_views.WorkoutLogViewSet, basename='workoutlog')
router.register(r'weight-config', manager_api_views.WeightConfigViewSet, basename='weight-config')
router.register(