mirror of
https://github.com/wger-project/wger.git
synced 2026-02-18 23:42:04 +01:00
Use the date and user information from the session
This will need to be cleaned up a bit more in the future since there's still redundant information
This commit is contained in:
@@ -385,7 +385,19 @@ class WorkoutLogSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = WorkoutLog
|
||||
exclude = ('user',)
|
||||
fields = [
|
||||
'session',
|
||||
'routine',
|
||||
'slot_config',
|
||||
'next_log',
|
||||
'exercise',
|
||||
'reps',
|
||||
'repetition_unit',
|
||||
'weight',
|
||||
'weight_unit',
|
||||
'rir',
|
||||
'iteration',
|
||||
]
|
||||
|
||||
|
||||
class LogDataSerializer(serializers.Serializer):
|
||||
|
||||
@@ -423,9 +423,9 @@ class WorkoutLogViewSet(WgerOwnerObjectModelViewSet):
|
||||
if getattr(self, 'swagger_fake_view', False):
|
||||
return WorkoutLog.objects.none()
|
||||
|
||||
return WorkoutLog.objects.filter(user=self.request.user)
|
||||
return WorkoutLog.objects.filter(session__user=self.request.user)
|
||||
|
||||
def perform_create(self, serializer):
|
||||
def perform_create(self, serializer: WorkoutLogSerializer):
|
||||
"""
|
||||
Set the owner
|
||||
"""
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
# Standard Library
|
||||
import datetime
|
||||
|
||||
@@ -30,12 +29,10 @@ from wger.core.models import (
|
||||
WeightUnit,
|
||||
)
|
||||
from wger.exercises.models import ExerciseBase
|
||||
from wger.manager.consts import RIR_OPTIONS
|
||||
from wger.manager.models.session import WorkoutSession
|
||||
from wger.utils.cache import reset_workout_log
|
||||
|
||||
# Local
|
||||
from ..consts import RIR_OPTIONS
|
||||
from .session import WorkoutSession
|
||||
|
||||
|
||||
class WorkoutLog(models.Model):
|
||||
"""
|
||||
@@ -173,9 +170,6 @@ class WorkoutLog(models.Model):
|
||||
Plumbing
|
||||
"""
|
||||
|
||||
# Reset cache
|
||||
reset_workout_log(self.user_id, self.date.year, self.date.month, self.date.day)
|
||||
|
||||
# If the routine does not belong to this user, do not save
|
||||
if self.routine and self.routine.user != self.user:
|
||||
return
|
||||
@@ -192,6 +186,14 @@ class WorkoutLog(models.Model):
|
||||
routine=self.routine,
|
||||
)[0]
|
||||
|
||||
# Reset cache
|
||||
reset_workout_log(
|
||||
self.user_id,
|
||||
self.session.date.year,
|
||||
self.session.date.month,
|
||||
self.session.date.day,
|
||||
)
|
||||
|
||||
# If the user of next_log is not this user, remove foreign key
|
||||
if self.next_log and self.next_log.user != self.user:
|
||||
self.next_log = None
|
||||
@@ -208,5 +210,10 @@ class WorkoutLog(models.Model):
|
||||
"""
|
||||
Reset cache
|
||||
"""
|
||||
reset_workout_log(self.user_id, self.date.year, self.date.month, self.date.day)
|
||||
reset_workout_log(
|
||||
self.user_id,
|
||||
self.session.date.year,
|
||||
self.session.date.month,
|
||||
self.session.date.day,
|
||||
)
|
||||
super(WorkoutLog, self).delete(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user