Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iric-data
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
bioinfo_iric
iric-data
Commits
afdac0e6
Commit
afdac0e6
authored
4 years ago
by
Xiao Ju
Browse files
Options
Downloads
Plain Diff
Merge branch '136-add-delete-datafile-api-endpoint' into 'master'
Resolve "add delete datafile api endpoint" Closes
#136
See merge request
!70
parents
0cec5a13
c6516f3f
Branches
15-allow-to-keep-file-content-in-memory
No related tags found
1 merge request
!70
Resolve "add delete datafile api endpoint"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
portal/urls.py
+5
-3
5 additions, 3 deletions
portal/urls.py
portal/views/secure/api.py
+32
-3
32 additions, 3 deletions
portal/views/secure/api.py
with
37 additions
and
6 deletions
portal/urls.py
+
5
−
3
View file @
afdac0e6
...
...
@@ -8,11 +8,13 @@ from .views.public import IndexView
from
.views.secure.alert
import
(
AlertCreateView
,
AlertDeleteView
,
AlertJSONListView
,
AlertListView
,
AlertUpdateView
)
from
.views.secure.api
import
(
AdminDataSetJSONListView
,
from
.views.secure.api
import
(
APIView
,
AdminDataSetJSONListView
,
DataFileAnnotationJSONView
,
DataFileLookupJSONListView
,
DataFileMetadataJSONView
,
UserDataSetJSONListView
)
UserDataSetJSONListView
,
DataFileDeleteJSONView
)
from
.views.secure.dashboard
import
AdminDashboardView
,
DashboardView
from
.views.secure.datafile
import
(
DataFileAnnotateView
,
DataFileAnnotationDownloadView
,
...
...
@@ -53,7 +55,6 @@ from .views.secure.user_profile import (AdminUserView, LDAPUserCreateView,
ProfileUpdateView
,
UserCreateView
,
UserDeleteView
,
UserJSONListView
,
UserUpdateView
)
from
.views.secure.api
import
APIView
urlpatterns
=
[
# Landing Pages
...
...
@@ -83,6 +84,7 @@ urlpatterns = [
path
(
'
api/v1/datafiles/json/annotation/<slug:iric_data_id>
'
,
DataFileAnnotationJSONView
.
as_view
(),
name
=
'
user.datafile-annotation-json-iric-data-id
'
),
path
(
'
api/v1/datafiles/json/metadata/<int:pk>
'
,
DataFileMetadataJSONView
.
as_view
(),
name
=
'
user.datafile-metadata-json
'
),
path
(
'
api/v1/datafiles/json/metadata/<slug:iric_data_id>
'
,
DataFileMetadataJSONView
.
as_view
(),
name
=
'
user.datafile-metadata-json-iric-data-id
'
),
path
(
'
api/v1/datafiles/json/delete/<slug:iric_data_id>
'
,
DataFileDeleteJSONView
.
as_view
(),
name
=
'
user.datafile-delete-json
'
),
path
(
'
api/v1/admin/<str:sim>/datasets/list/json/
'
,
AdminDataSetJSONListView
.
as_view
(),
name
=
'
admin.user-dataset-json-list
'
),
path
(
'
api/v1/my-datasets/list/json/
'
,
UserDataSetJSONListView
.
as_view
(),
name
=
'
secure.user-dataset-json-list
'
),
...
...
This diff is collapsed.
Click to expand it.
portal/views/secure/api.py
+
32
−
3
View file @
afdac0e6
import
logging
from
django.contrib.auth.mixins
import
LoginRequiredMixin
from
django.db.models
import
Q
from
django.shortcuts
import
get_object_or_404
from
django.views.generic
import
TemplateView
from
django.http
import
JsonResponse
from
django.views.generic.detail
import
BaseDetailView
from
django.utils.translation
import
ugettext_lazy
as
_
from
portal.views
import
TokenLoginMixin
from
portal.views
import
TokenLoginMixin
,
SlugMixin
from
django.views.decorators.csrf
import
csrf_exempt
from
django.utils.decorators
import
method_decorator
from
...models
import
DataFile
,
DataSet
,
Profile
from
...views
import
JSONListView
,
JSONView
,
StaffViewMixin
,
ActivePageViewMixin
...
...
@@ -89,6 +91,33 @@ class DataFileMetadataJSONView(TokenLoginMixin, JSONView):
return
metadata
class
DataFileDeleteJSONView
(
TokenLoginMixin
,
SlugMixin
,
BaseDetailView
):
model
=
DataFile
http_method_names
=
[
"
delete
"
]
@method_decorator
(
csrf_exempt
,
name
=
'
dispatch
'
)
def
dispatch
(
self
,
*
args
,
**
kwargs
):
method
=
self
.
request
.
POST
.
get
(
'
_method
'
,
''
).
lower
()
if
method
==
'
delete
'
:
return
self
.
delete
(
*
args
,
**
kwargs
)
return
super
(
DataFileDeleteJSONView
,
self
).
dispatch
(
*
args
,
**
kwargs
)
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
o
=
self
.
get_object
()
except
Exception
as
e
:
return
JsonResponse
({
'
error
'
:
_
(
'
File cannot be found
'
)},
status
=
403
)
if
o
in
DataFile
.
objects
.
editable_by_profile
(
self
.
request
.
user
.
profile
).
all
():
iric_data_id
=
o
.
iric_data_id
try
:
o
.
delete
()
return
JsonResponse
({
'
success
'
:
_
(
f
'
DataFile
{
iric_data_id
}
succesfully deleted
'
)},
status
=
202
)
except
Exception
as
e
:
return
JsonResponse
({
'
error
'
:
e
.
msg
},
status
=
500
)
return
JsonResponse
({
'
error
'
:
_
(
'
You are not authorized to delete this file
'
)},
status
=
403
)
# DataSet API Views #######
class
AdminDataSetJSONListView
(
TokenLoginMixin
,
JSONListView
):
model
=
DataSet
...
...
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