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 21:22:41 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4615d42d1fcfde1742858a8e3c5b96ba01ff8f7b
4615d42d
1 parent
197b1146
implement copy item api
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
5 deletions
backend/api/migrations/0005_auto_20200610_1150.py
backend/api/migrations/0006_auto_20200610_1209.py
backend/api/migrations/0007_auto_20200610_1217.py
backend/api/models.py
backend/api/views.py
backend/khudrive/urls.py
backend/api/migrations/0005_auto_20200610_1150.py
0 → 100644
View file @
4615d42
# Generated by Django 3.0.6 on 2020-06-10 11:50
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0004_auto_20200606_0824'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'item'
,
name
=
'item_id'
,
field
=
models
.
IntegerField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
),
),
]
backend/api/migrations/0006_auto_20200610_1209.py
0 → 100644
View file @
4615d42
# Generated by Django 3.0.6 on 2020-06-10 12:09
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0005_auto_20200610_1150'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'item'
,
name
=
'item_id'
,
field
=
models
.
AutoField
(
primary_key
=
True
,
serialize
=
False
),
),
]
backend/api/migrations/0007_auto_20200610_1217.py
0 → 100644
View file @
4615d42
# Generated by Django 3.0.6 on 2020-06-10 12:17
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0006_auto_20200610_1209'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'item'
,
name
=
'updated_time'
,
field
=
models
.
DateTimeField
(
null
=
True
),
),
]
backend/api/models.py
View file @
4615d42
...
...
@@ -2,7 +2,7 @@ from django.db import models
# Create your models here.
class
Item
(
models
.
Model
):
item_id
=
models
.
Integer
Field
(
primary_key
=
True
)
item_id
=
models
.
Auto
Field
(
primary_key
=
True
)
is_folder
=
models
.
BooleanField
(
default
=
False
)
name
=
models
.
CharField
(
max_length
=
50
)
path
=
models
.
TextField
()
...
...
@@ -12,7 +12,7 @@ class Item(models.Model):
size
=
models
.
IntegerField
()
is_deleted
=
models
.
BooleanField
(
default
=
False
)
created_time
=
models
.
DateTimeField
(
auto_now
=
True
)
updated_time
=
models
.
DateTimeField
()
updated_time
=
models
.
DateTimeField
(
null
=
True
)
status
=
models
.
BooleanField
()
#file = models.FileField(upload_to = \path)
...
...
backend/api/views.py
View file @
4615d42
import
mimetypes
import
json
import
os
from
datetime
import
datetime
import
boto3
from
django.contrib.auth.models
import
User
...
...
@@ -83,6 +85,8 @@ class ItemViewSet(viewsets.ViewSet):
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
)
if
child
==
None
:
return
Response
({
'message'
:
'item is not existed.'
},
status
=
status
.
HTTP_204_NO_CONTENT
)
child
.
parent
=
parent_id
child
.
save
()
child
=
Item
.
objects
.
filter
(
item_id
=
pk
)
...
...
@@ -96,12 +100,41 @@ class ItemViewSet(viewsets.ViewSet):
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
)
return
Response
({
'message'
:
'
parent
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'
:
'
parent
is not folder.'
},
status
=
status
.
HTTP_200_OK
)
return
Response
({
'message'
:
'item is not existed.'
},
status
=
status
.
HTTP_204_NO_CONTENT
)
@action
(
methods
=
[
'POST'
],
detail
=
True
,
permission_classes
=
[
AllowAny
],
url_path
=
'copy'
,
url_name
=
'copy'
)
def
copy
(
self
,
request
,
pk
):
if
request
.
method
==
'POST'
:
parent_id
=
request
.
POST
.
get
(
'parent'
,
''
)
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
)
if
child
==
None
:
return
Response
({
'message'
:
'item is not existed.'
},
status
=
status
.
HTTP_204_NO_CONTENT
)
if
child
.
is_folder
==
True
:
return
Response
({
'message'
:
'item is folder'
},
status
=
status
.
HTTP_204_NO_CONTENT
)
copiedName
=
child
.
name
+
"_복사본_"
+
str
(
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M'
))
copiedItem
=
Item
(
is_folder
=
False
,
name
=
copiedName
,
path
=
child
.
path
,
parent
=
parent_id
,
user_id
=
child
.
user_id
,
size
=
child
.
size
,
status
=
child
.
status
)
copiedItem
.
save
()
copiedItem
=
Item
.
objects
.
filter
(
name
=
copiedName
)
copied_data
=
serializers
.
serialize
(
"json"
,
copiedItem
)
json_data
=
json
.
loads
(
copied_data
)
res
=
json_data
[
0
][
'fields'
]
res
[
'id'
]
=
json_data
[
0
][
'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'
:
'parent is not existed.'
},
status
=
status
.
HTTP_200_OK
)
if
parent
.
is_folder
==
False
:
return
Response
({
'message'
:
'parent 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
:
...
...
backend/khudrive/urls.py
View file @
4615d42
...
...
@@ -32,5 +32,6 @@ urlpatterns = [
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'
),
url
(
r'^<int:pk>/copy/$'
,
views
.
ItemViewSet
.
copy
,
name
=
'copy'
),
]
...
...
Please
register
or
login
to post a comment