Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdt4242-ex2
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jørgen Hollum
tdt4242-ex2
Commits
27d01405
Commit
27d01405
authored
2 years ago
by
Sigurd
Browse files
Options
Downloads
Patches
Plain Diff
workouts/Serializer.py - refactor update, adjusted to pylint
parent
0b7f3272
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#169834
passed with stage
in 25 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend/secfit/workouts/serializers.py
+20
-14
20 additions, 14 deletions
backend/secfit/workouts/serializers.py
with
20 additions
and
14 deletions
backend/secfit/workouts/serializers.py
+
20
−
14
View file @
27d01405
...
...
@@ -162,29 +162,32 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
for
i
in
range
(
len
(
exercise_instances_data
),
len
(
exercise_instances
.
all
())):
exercise_instances
.
all
()[
i
].
delete
()
# Handle WorkoutFiles
if
"
files
"
in
validated_data
:
files_data
=
validated_data
.
pop
(
"
files
"
)
files
=
instance
.
files
self
.
handle_workout_files
(
instance
,
validated_data
)
for
file
,
file_data
in
zip
(
files
.
all
(),
files_data
):
file
.
file
=
file_data
.
get
(
"
file
"
,
file
.
file
)
return
instance
# Handle WorkoutFiles
def
handle_workout_files
(
self
,
instance
,
validated_data
):
files_data
=
validated_data
.
pop
(
"
files
"
)
files
=
instance
.
files
for
file
,
file_data
in
zip
(
files
.
all
(),
files_data
):
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
)):
WorkoutFile
.
objects
.
create
(
if
len
(
files_data
)
>
len
(
files
.
all
()):
for
i
in
range
(
len
(
files
.
all
()),
len
(
files_data
)):
WorkoutFile
.
objects
.
create
(
workout
=
instance
,
owner
=
instance
.
owner
,
file
=
files_data
[
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
())):
files
.
all
()[
i
].
delete
()
return
instance
elif
len
(
files_data
)
<
len
(
files
.
all
()):
for
i
in
range
(
len
(
files_data
),
len
(
files
.
all
())):
files
.
all
()[
i
].
delete
()
def
get_owner_username
(
self
,
obj
):
"""
Returns the owning user
'
s username
...
...
@@ -213,7 +216,10 @@ class ExerciseSerializer(serializers.HyperlinkedModelSerializer):
class
Meta
:
model
=
Exercise
fields
=
[
"
url
"
,
"
id
"
,
"
name
"
,
"
description
"
,
"
duration
"
,
"
calories
"
,
"
muscleGroup
"
,
"
unit
"
,
"
instances
"
]
fields
=
[
"
url
"
,
"
id
"
,
"
name
"
,
"
description
"
,
"
duration
"
,
"
calories
"
,
"
muscleGroup
"
,
"
unit
"
,
"
instances
"
]
class
GoalSerializer
(
serializers
.
HyperlinkedModelSerializer
):
"""
Serializer for an Goal. Hyperlinks are used for relationships by default.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment