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
4b2feaa8
"README.md" did not exist on "6322e5c114a0c454cca94d3bfd0c70f9b286bcb7"
Commit
4b2feaa8
authored
5 years ago
by
Samuel GAIST
Committed by
Samuel GAIST
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[common][api] Simplify deletion of object using perform_destroy hook
parent
31cbe188
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
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 @
4b2feaa8
...
@@ -263,32 +263,12 @@ class RetrieveUpdateDestroyContributionView(
...
@@ -263,32 +263,12 @@ class RetrieveUpdateDestroyContributionView(
serializer
=
self
.
get_serializer
(
db_object
,
fields
=
fields_to_return
)
serializer
=
self
.
get_serializer
(
db_object
,
fields
=
fields_to_return
)
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
def
perform_destroy
(
self
,
instance
):
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
,
)
# Check that the object can be deleted
# Check that the object can be deleted
if
not
(
db_object
.
deletable
()):
if
not
(
instance
.
deletable
()):
raise
drf_exceptions
.
MethodNotAllowed
(
raise
drf_exceptions
.
MethodNotAllowed
(
"
The {} can
'
t be deleted anymore (needed by an attestation, an algorithm or another data format)
"
.
format
(
"
The {} can
'
t be deleted anymore (needed by an attestation, an algorithm or another data format)
"
.
format
(
db_object
.
model_name
()
instance
.
model_name
()
)
)
)
)
return
super
().
perform_destroy
(
instance
)
# Deletion of the object
db_object
.
delete
()
return
Response
(
status
=
204
)
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