Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
권주희
2020-06-10 00:31:34 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
35ac26411a660d00e880d9c6ec472defa08fecc6
35ac2641
1 parent
443a9ab5
implement move api
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
backend/api/views.py
backend/khudrive/urls.py
backend/api/views.py
View file @
35ac264
...
...
@@ -63,10 +63,41 @@ class ItemViewSet(viewsets.ViewSet):
if
item
.
is_folder
==
True
:
# 폴더는 삭제 안되도록 처리
return
Response
({
'message'
:
'This item is folder.'
},
status
=
status
.
HTTP_200_OK
)
item
.
is_deleted
=
True
item
.
save
()
# item.delete() 이거 하면 완전 삭제되어버림 is deleted True 면 휴지통에서 리스트 조회할 수 있도록!
return
Response
({
'message'
:
'delete complete'
},
status
=
status
.
HTTP_200_OK
)
return
Response
({
'message'
:
'item is not existed.'
},
status
=
status
.
HTTP_204_NO_CONTENT
)
# url: items/11/move
# 마지막 slash도 써주어야함
@action
(
methods
=
[
'POST'
],
detail
=
True
,
permission_classes
=
[
AllowAny
],
url_path
=
'move'
,
url_name
=
'move'
)
def
move
(
self
,
request
,
pk
):
if
request
.
method
==
'POST'
:
parent_id
=
request
.
POST
.
get
(
'parent'
,
''
)
name
=
request
.
POST
.
get
(
'name'
,
''
)
parent
=
get_object_or_None
(
Item
,
item_id
=
parent_id
)
if
parent
!=
None
and
parent
.
is_folder
==
True
:
child
=
get_object_or_None
(
Item
,
item_id
=
pk
)
child
.
parent
=
parent_id
child
.
save
()
child
=
Item
.
objects
.
filter
(
item_id
=
pk
)
child_data
=
serializers
.
serialize
(
"json"
,
child
)
json_child
=
json
.
loads
(
child_data
)
res
=
json_child
[
0
][
'fields'
]
res
[
'id'
]
=
pk
parent
=
Item
.
objects
.
filter
(
item_id
=
parent_id
)
parent_data
=
serializers
.
serialize
(
"json"
,
parent
)
json_parent
=
json
.
loads
(
parent_data
)[
0
][
'fields'
]
res
[
'parentInfo'
]
=
json_parent
return
Response
({
'data'
:
res
},
status
=
status
.
HTTP_200_OK
)
if
parent
==
None
:
return
Response
({
'message'
:
'item is not existed.'
},
status
=
status
.
HTTP_200_OK
)
if
parent
.
is_folder
==
False
:
return
Response
({
'message'
:
'item is not folder.'
},
status
=
status
.
HTTP_200_OK
)
return
Response
({
'message'
:
'item is not existed.'
},
status
=
status
.
HTTP_204_NO_CONTENT
)
def
get_permissions
(
self
):
try
:
# return permission_classes depending on `action`
...
...
backend/khudrive/urls.py
View file @
35ac264
...
...
@@ -31,5 +31,6 @@ urlpatterns = [
path
(
''
,
include
(
router
.
urls
)),
url
(
r'^search/$'
,
views
.
ItemViewSet
.
search
,
name
=
'search'
),
url
(
r'^<int:pk>/share/$'
,
views
.
SharedItemViewSet
.
share
,
name
=
'share'
),
url
(
r'^<int:pk>/move/$'
,
views
.
ItemViewSet
.
move
,
name
=
'move'
),
]
...
...
Please
register
or
login
to post a comment