Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
AURA
steering
Commits
490b9072
Verified
Commit
490b9072
authored
4 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: raise ValidationError when a playlist has multiple null duration entries
parent
8bd297ee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!59
Add playlists
Pipeline
#8721
passed
4 months ago
Stage: check
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/serializers.py
+37
-23
37 additions, 23 deletions
program/serializers.py
with
37 additions
and
23 deletions
program/serializers.py
+
37
−
23
View file @
490b9072
...
...
@@ -30,7 +30,7 @@ from rest_framework.permissions import exceptions
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db
import
IntegrityError
from
django.db
import
IntegrityError
,
transaction
from
django.db.models
import
Q
from
django.utils
import
text
,
timezone
from
program.models
import
(
...
...
@@ -1522,15 +1522,22 @@ class PlaylistSerializer(serializers.ModelSerializer):
entries
=
validated_data
.
pop
(
"
entries
"
,
[])
playlist
=
Playlist
.
objects
.
create
(
created_by
=
user
.
username
,
**
validated_data
)
with
transaction
.
atomic
():
playlist
=
Playlist
.
objects
.
create
(
created_by
=
user
.
username
,
**
validated_data
)
for
entry_data
in
entries
:
try
:
PlaylistEntry
.
objects
.
create
(
playlist
=
playlist
,
**
entry_data
)
except
IntegrityError
:
for
entry_data
in
entries
:
try
:
PlaylistEntry
.
objects
.
create
(
playlist
=
playlist
,
**
entry_data
)
except
IntegrityError
:
raise
exceptions
.
ValidationError
(
code
=
"
playlist-entry-file-id-or-uri
"
,
detail
=
"
playlist entries must either have file id or uri.
"
,
)
if
playlist
.
entries
.
filter
(
duration__isnull
=
True
).
count
()
>
1
:
raise
exceptions
.
ValidationError
(
code
=
"
playlist-entry-file-id-or-uri
"
,
detail
=
"
playlist
entries must either have file id or uri.
"
,
code
=
"
multiple-null-duration-playlist-entries
"
,
detail
=
"
playlist
may only have one entry without duration
"
,
)
return
playlist
...
...
@@ -1547,26 +1554,33 @@ class PlaylistSerializer(serializers.ModelSerializer):
detail
=
"
You are not allowed to update this playlist.
"
)
if
"
description
"
in
validated_data
:
instance
.
description
=
validated_data
.
pop
(
"
description
"
)
with
transaction
.
atomic
():
if
"
description
"
in
validated_data
:
instance
.
description
=
validated_data
.
pop
(
"
description
"
)
if
"
playout_mode
"
in
validated_data
:
instance
.
playout_mode
=
validated_data
.
pop
(
"
playout_mode
"
)
if
"
playout_mode
"
in
validated_data
:
instance
.
playout_mode
=
validated_data
.
pop
(
"
playout_mode
"
)
if
"
entries
"
in
validated_data
:
if
instance
.
entries
.
count
()
>
0
:
for
entry
in
instance
.
entries
.
all
():
entry
.
delete
(
keep_parents
=
True
)
if
"
entries
"
in
validated_data
:
if
instance
.
entries
.
count
()
>
0
:
for
entry
in
instance
.
entries
.
all
():
entry
.
delete
(
keep_parents
=
True
)
for
entry_data
in
validated_data
.
get
(
"
entries
"
):
try
:
PlaylistEntry
.
objects
.
create
(
playlist
=
instance
,
**
entry_data
)
except
IntegrityError
:
for
entry_data
in
validated_data
.
get
(
"
entries
"
):
try
:
PlaylistEntry
.
objects
.
create
(
playlist
=
instance
,
**
entry_data
)
except
IntegrityError
:
raise
exceptions
.
ValidationError
(
code
=
"
playlist-entry-file-id-or-uri
"
,
detail
=
"
playlist entries must either have file id or uri.
"
,
)
if
instance
.
entries
.
filter
(
duration__isnull
=
True
).
count
()
>
1
:
raise
exceptions
.
ValidationError
(
code
=
"
playlist-entry-file-id-or-uri
"
,
detail
=
"
playlist
entries must either have file id or uri.
"
,
code
=
"
multiple-null-duration-playlist-entries
"
,
detail
=
"
playlist
may only have one entry without duration
"
,
)
instance
.
save
()
instance
.
save
()
return
instance
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