Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
beat
beat.web
Commits
4b6ad3c3
Commit
4b6ad3c3
authored
5 years ago
by
Samuel GAIST
Browse files
Options
Downloads
Patches
Plain Diff
[common][api] Simplify deletion of object using perform_destroy hook
parent
23e9e6eb
No related branches found
No related tags found
1 merge request
!327
Refactor update creation api
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/common/api.py
+4
-24
4 additions, 24 deletions
beat/web/common/api.py
with
4 additions
and
24 deletions
beat/web/common/api.py
+
4
−
24
View file @
4b6ad3c3
...
...
@@ -263,32 +263,12 @@ class RetrieveUpdateDestroyContributionView(
serializer
=
self
.
get_serializer
(
db_object
,
fields
=
fields_to_return
)
return
Response
(
serializer
.
data
)
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
author_name
=
self
.
kwargs
.
get
(
"
author_name
"
)
object_name
=
self
.
kwargs
.
get
(
"
object_name
"
)
version
=
self
.
kwargs
.
get
(
"
version
"
,
None
)
# Retrieve the object
if
version
is
None
:
raise
drf_exceptions
.
ValidationError
(
{
"
version
"
:
"
A version number must be provided
"
}
)
db_object
=
get_object_or_404
(
self
.
model
,
author__username__iexact
=
author_name
,
name__iexact
=
object_name
,
version
=
version
,
)
def
perform_destroy
(
self
,
instance
):
# Check that the object can be deleted
if
not
(
db_object
.
deletable
()):
if
not
(
instance
.
deletable
()):
raise
drf_exceptions
.
MethodNotAllowed
(
"
The {} can
'
t be deleted anymore (needed by an attestation, an algorithm or another data format)
"
.
format
(
db_object
.
model_name
()
instance
.
model_name
()
)
)
# Deletion of the object
db_object
.
delete
()
return
Response
(
status
=
204
)
return
super
().
perform_destroy
(
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