Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신은섭(Shin Eun Seop)
/
2018-1-d.cloud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
10
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
신은섭(Shin Eun Seop)
2018-05-31 11:26:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a507c7666773eff1de0e2abcedbbf707ebd3a938
a507c766
1 parent
8131b6af
add file delete restapi, close
#11
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
27 deletions
dcloud/dcloud/settings.py
dcloud/restful/s3_interface.py
dcloud/restful/urls.py
dcloud/restful/views.py
dcloud/dcloud/settings.py
View file @
a507c76
import
os
import
aws_conf
from
dcloud
import
aws_conf
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
...
...
dcloud/restful/s3_interface.py
View file @
a507c76
...
...
@@ -27,4 +27,5 @@ def list_path(bucket, user, path):
return
{
'files'
:
files
}
# print(list_path(BUCKET, 'test1', ''))
\ No newline at end of file
def
delete_path
(
bucket
,
user
,
path
):
return
S3
.
delete_object
(
Bucket
=
bucket
,
Key
=
'{}/{}'
.
format
(
user
,
path
))
...
...
dcloud/restful/urls.py
View file @
a507c76
...
...
@@ -4,8 +4,10 @@ from rest_framework.urlpatterns import format_suffix_patterns
from
restful
import
views
urlpatterns
=
[
url
(
r'^files/(?P<path>([a-zA-z0-9가-힣._-]*/)*)$'
,
views
.
FileList
.
as_view
(),
name
=
'file-list'
),
url
(
r'^files/(?P<pk>[0-9]+)/$'
,
views
.
FileDetail
.
as_view
()),
url
(
r'^list/(?P<path>([a-zA-z0-9가-힣._-]*/)*)$'
,
views
.
FileList
.
as_view
(),
name
=
'file-list'
),
# url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()),
url
(
r'^file/(?P<path>([a-zA-z0-9가-힣._-]*/*)*)$'
,
views
.
FileDetail
.
as_view
(),
name
=
'file-detail'
)
]
urlpatterns
=
format_suffix_patterns
(
urlpatterns
)
\ No newline at end of file
...
...
dcloud/restful/views.py
View file @
a507c76
...
...
@@ -34,27 +34,30 @@ class FileDetail(APIView):
"""
Retrieve, update or delete a file instance.
"""
def
get_object
(
self
,
pk
):
try
:
return
File
.
objects
.
get
(
pk
=
pk
)
except
File
.
DoesNotExist
:
raise
Http404
def
get
(
self
,
request
,
pk
,
format
=
None
):
file
=
self
.
get_object
(
pk
)
serializer
=
FileSerializer
(
file
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
def
put
(
self
,
request
,
pk
,
format
=
None
):
file
=
self
.
get_object
(
pk
)
serializer
=
FileSerializer
(
file
,
data
=
request
.
data
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_204_NO_CONTENT
)
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
def
delete
(
self
,
request
,
pk
,
format
=
None
):
file
=
self
.
get_object
(
pk
)
file
.
delete
()
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
# def get_object(self, pk):
# try:
# return File.objects.get(pk=pk)
# except File.DoesNotExist:
# raise Http404
def
get
(
self
,
request
,
path
=
"/"
,
format
=
None
):
# file = self.get_object(pk)
# serializer = FileSerializer(file)
# return Response(serializer.data, status=status.HTTP_200_OK)
# TODO
return
def
put
(
self
,
request
,
path
=
"/"
,
format
=
None
):
# file = self.get_object(pk)
# serializer = FileSerializer(file, data=request.data)
# if serializer.is_valid():
# serializer.save()
# return Response(serializer.data, status=status.HTTP_204_NO_CONTENT)
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
# TODO
return
def
delete
(
self
,
request
,
path
=
"/"
,
format
=
None
):
result
=
s3_interface
.
delete_path
(
s3_interface
.
BUCKET
,
'test1'
,
path
)
return
Response
(
result
)
...
...
Please
register
or
login
to post a comment