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
0c202527
Verified
Commit
0c202527
authored
11 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: raise a ValidationError if a note for this timeslot already exists
parent
bce12fd6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/serializers.py
+19
-13
19 additions, 13 deletions
program/serializers.py
with
19 additions
and
13 deletions
program/serializers.py
+
19
−
13
View file @
0c202527
...
@@ -28,6 +28,7 @@ from rest_framework.permissions import exceptions
...
@@ -28,6 +28,7 @@ from rest_framework.permissions import exceptions
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db
import
IntegrityError
from
django.utils
import
text
,
timezone
from
django.utils
import
text
,
timezone
from
program.models
import
(
from
program.models
import
(
Category
,
Category
,
...
@@ -1023,22 +1024,27 @@ class NoteSerializer(serializers.ModelSerializer):
...
@@ -1023,22 +1024,27 @@ class NoteSerializer(serializers.ModelSerializer):
# optional foreign key
# optional foreign key
validated_data
[
"
image
"
]
=
validated_data
.
pop
(
"
image
"
,
None
)
validated_data
[
"
image
"
]
=
validated_data
.
pop
(
"
image
"
,
None
)
note
=
Note
.
objects
.
create
(
try
:
created_by
=
self
.
context
.
get
(
"
request
"
).
user
.
username
,
note
=
Note
.
objects
.
create
(
**
validated_data
,
created_by
=
self
.
context
.
get
(
"
request
"
).
user
.
username
,
)
**
validated_data
,
)
note
.
contributors
.
set
(
contributors
)
except
IntegrityError
:
note
.
language
.
set
(
language
)
raise
exceptions
.
ValidationError
(
note
.
topic
.
set
(
topic
)
code
=
"
duplicate
"
,
detail
=
"
note for this timeslot already exists.
"
)
else
:
note
.
contributors
.
set
(
contributors
)
note
.
language
.
set
(
language
)
note
.
topic
.
set
(
topic
)
# optional nested objects
# optional nested objects
for
link_data
in
links_data
:
for
link_data
in
links_data
:
NoteLink
.
objects
.
create
(
note
=
note
,
**
link_data
)
NoteLink
.
objects
.
create
(
note
=
note
,
**
link_data
)
note
.
save
()
note
.
save
()
return
note
return
note
def
update
(
self
,
instance
,
validated_data
):
def
update
(
self
,
instance
,
validated_data
):
"""
Update and return an existing Note instance, given the validated data.
"""
"""
Update and return an existing Note instance, given the validated data.
"""
...
...
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