Commit 10d45d73 authored by olavhdi's avatar olavhdi
Browse files

workouts logical naming #34

parent 2cdb711f
Pipeline #126371 failed with stage
in 13 seconds
......@@ -94,15 +94,15 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
Workout: A newly created Workout
"""
exercise_instances_data = validated_data.pop("exercise_instances")
files_data = []
validated_files = []
if "files" in validated_data:
files_data = validated_data.pop("files")
validated_files = validated_data.pop("files")
workout = Workout.objects.create(**validated_data)
for exercise_instance_data in exercise_instances_data:
ExerciseInstance.objects.create(workout=workout, **exercise_instance_data)
for file_data in files_data:
for file_data in validated_data:
WorkoutFile.objects.create(
workout=workout, owner=workout.owner, file=file_data.get("file")
)
......@@ -165,23 +165,23 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
# Handle WorkoutFiles
if "files" in validated_data:
files_data = validated_data.pop("files")
validated_files = validated_data.pop("files")
files = instance.files
for file, file_data in zip(files.all(), files_data):
for file, file_data in zip(files.all(), validated_files):
file.file = file_data.get("file", file.file)
# If new files have been added, creating new WorkoutFiles
if len(files_data) > len(files.all()):
for i in range(len(files.all()), len(files_data)):
for i in range(len(files.all()), len(validated_files)):
WorkoutFile.objects.create(
workout=instance,
owner=instance.owner,
file=files_data[i].get("file"),
file=validated_files[i].get("file"),
)
# Else if files have been removed, delete WorkoutFiles
elif len(files_data) < len(files.all()):
for i in range(len(files_data), len(files.all())):
elif len(validated_files) < len(files.all()):
for i in range(len(validated_files), len(files.all())):
files.all()[i].delete()
return instance
......
......@@ -164,18 +164,18 @@ class WorkoutList(
"""
Return all workouts you should be able to view
"""
qs = Workout.objects.none()
query_set = Workout.objects.none()
if self.request.user:
# A workout should be visible to the requesting user if any of the following hold:
# - The workout has public visibility
# - The owner of the workout is the requesting user
# - The workout has coach visibility and the requesting user is the owner's coach
qs = Workout.objects.filter(
query_set = Workout.objects.filter(
Q(visibility="PU")
| (Q(visibility="CO") & Q(owner__coach=self.request.user))
).distinct()
return qs
return query_set
class WorkoutDetail(
......@@ -312,9 +312,9 @@ class ExerciseInstanceList(
"""
Return all exercise instances you should be able to view
"""
qs = ExerciseInstance.objects.none()
query_set = ExerciseInstance.objects.none()
if self.request.user:
qs = ExerciseInstance.objects.filter(
query_set = ExerciseInstance.objects.filter(
Q(workout__owner=self.request.user)
| (
(Q(workout__visibility="CO") | Q(workout__visibility="PU"))
......@@ -322,7 +322,7 @@ class ExerciseInstanceList(
)
).distinct()
return qs
return query_set
class ExerciseInstanceDetail(
......@@ -408,9 +408,9 @@ class WorkoutFileList(
"""
Return all workout files you should be able to view
"""
qs = WorkoutFile.objects.none()
query_set = WorkoutFile.objects.none()
if self.request.user:
qs = WorkoutFile.objects.filter(
query_set = WorkoutFile.objects.filter(
Q(owner=self.request.user)
| Q(workout__owner=self.request.user)
| (
......@@ -419,7 +419,7 @@ class WorkoutFileList(
)
).distinct()
return qs
return query_set
class WorkoutFileDetail(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment