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-09 20:25:01 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4c7768f4f3ae6e4d811dc3cdcf72f9a5027a3239
4c7768f4
1 parent
e3201e7d
return json object
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
8 deletions
backend/api/views.py
backend/api/views.py
View file @
4c7768f
...
...
@@ -8,15 +8,12 @@ from django.core import serializers
from
django.views.decorators.csrf
import
csrf_exempt
from
rest_framework
import
viewsets
from
rest_framework
import
permissions
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework.decorators
import
action
from
rest_framework.parsers
import
JSONParser
from
rest_framework.permissions
import
IsAuthenticated
,
AllowAny
from
api.models
import
Item
,
SharedItem
from
api.serializers
import
UserSerializer
,
GroupSerializer
,
ItemSerializer
,
SharedItemSerializer
from
rest_framework
import
generics
from
rest_framework
import
status
from
annoying.functions
import
get_object_or_None
...
...
@@ -36,7 +33,6 @@ class ItemViewSet(viewsets.ModelViewSet):
permission_classes
=
[
permissions
.
IsAuthenticatedOrReadOnly
,
permissions
.
AllowAny
,
#IsOwnerOrReadOnly
]
# url: items/search
@action
(
methods
=
[
'GET'
],
detail
=
False
,
permission_classes
=
[
AllowAny
],
url_path
=
'search'
,
url_name
=
'search'
)
def
search
(
self
,
request
):
...
...
@@ -45,7 +41,10 @@ class ItemViewSet(viewsets.ModelViewSet):
item_list
=
Item
.
objects
.
filter
(
name__icontains
=
keyword
)
data
=
serializers
.
serialize
(
"json"
,
item_list
)
return
Response
({
'data'
:
{
'list'
:
data
}},
status
=
status
.
HTTP_200_OK
)
json_data
=
json
.
loads
(
data
)
return
Response
({
'data'
:
{
'list'
:
json_data
}},
status
=
status
.
HTTP_200_OK
)
class
SharedItemViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -66,7 +65,7 @@ class SharedItemViewSet(viewsets.ModelViewSet):
sharedfile
=
get_object_or_None
(
SharedItem
,
item_id
=
pk
)
if
sharedfile
!=
None
:
# 서버는 정상이나 이미 공유객체로 등록된 파일임
return
Response
({
'
M
essage'
:
'This file is already shared'
},
status
=
status
.
HTTP_200_OK
)
return
Response
({
'
m
essage'
:
'This file is already shared'
},
status
=
status
.
HTTP_200_OK
)
sharedfile
=
SharedItem
(
item_id
=
pk
,
password
=
password
,
expires
=
expires
)
sharedfile
.
save
()
sharedfile
=
SharedItem
.
objects
.
get
(
item_id
=
pk
)
...
...
@@ -75,5 +74,5 @@ class SharedItemViewSet(viewsets.ModelViewSet):
item
=
Item
.
objects
.
filter
(
item_id
=
pk
)
item_json
=
serializers
.
serialize
(
"json"
,
item
)
# data = serializers.serialize("json", item_list)
return
Response
({
"shared"
:
sharedfile
.
created_time
,
'data'
:
item_json
},
status
=
status
.
HTTP_200_OK
)
\ No newline at end of file
json_data
=
json
.
loads
(
item_json
)
return
Response
({
"shared"
:
sharedfile
.
created_time
,
'data'
:
json_data
},
status
=
status
.
HTTP_200_OK
)
\ No newline at end of file
...
...
Please
register
or
login
to post a comment