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 22:36:23 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6a7261b5b0467ab523b0bfeaf56b86814f4488b6
6a7261b5
1 parent
4c7768f4
setting the default function
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
8 deletions
backend/api/serializers.py
backend/api/views.py
backend/api/serializers.py
View file @
6a7261b
...
...
@@ -18,7 +18,3 @@ class ItemSerializer(serializers.ModelSerializer):
model
=
Item
fields
=
'__all__'
class
SharedItemSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Item
fields
=
'__all__'
...
...
backend/api/views.py
View file @
6a7261b
...
...
@@ -13,7 +13,7 @@ from rest_framework.decorators import action
from
rest_framework.permissions
import
IsAuthenticated
,
AllowAny
from
api.models
import
Item
,
SharedItem
from
api.serializers
import
UserSerializer
,
GroupSerializer
,
ItemSerializer
,
SharedItemSerializer
from
api.serializers
import
UserSerializer
,
GroupSerializer
,
ItemSerializer
from
rest_framework
import
status
from
annoying.functions
import
get_object_or_None
...
...
@@ -26,13 +26,16 @@ class UserViewSet(viewsets.ModelViewSet):
permission_classes
=
[
permissions
.
IsAuthenticated
]
class
ItemViewSet
(
viewsets
.
Model
ViewSet
):
class
ItemViewSet
(
viewsets
.
ViewSet
):
queryset
=
Item
.
objects
.
all
()
serializer_class
=
ItemSerializer
permission_classes
=
[
permissions
.
IsAuthenticatedOrReadOnly
,
permissions
.
AllowAny
,
#IsOwnerOrReadOnly
]
permission_classes_by_action
=
{
'get'
:
[
permissions
.
AllowAny
],
'destroy'
:
[
permissions
.
AllowAny
]}
# url: items/search
@action
(
methods
=
[
'GET'
],
detail
=
False
,
permission_classes
=
[
AllowAny
],
url_path
=
'search'
,
url_name
=
'search'
)
def
search
(
self
,
request
):
...
...
@@ -44,12 +47,38 @@ class ItemViewSet(viewsets.ModelViewSet):
json_data
=
json
.
loads
(
data
)
return
Response
({
'data'
:
{
'list'
:
json_data
}},
status
=
status
.
HTTP_200_OK
)
# url: items/11/
# 마지막 slash도 써주어야함
def
get
(
self
,
request
,
pk
):
print
(
pk
)
return
Response
({
'message'
:
"info complete"
},
status
=
status
.
HTTP_200_OK
)
# url: items/11/
# 마지막 slash도 써주어야함
def
destroy
(
self
,
request
,
pk
):
if
request
.
method
==
'DELETE'
:
print
(
pk
)
# keyword = request.GET.get('keyword', '')
# item_list = Item.objects.filter(name__icontains=keyword)
#
# data = serializers.serialize("json", item_list)
# json_data = json.loads(data)
# return Response({'message': "delete complete"}, status=status.HTTP_200_OK)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
def
get_permissions
(
self
):
try
:
# return permission_classes depending on `action`
return
[
permission
()
for
permission
in
self
.
permission_classes_by_action
[
self
.
action
]]
except
KeyError
:
# action is not set return default permission_classes
return
[
permission
()
for
permission
in
self
.
permission_classes
]
class
SharedItemViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
SharedItem
.
objects
.
all
()
serializer_class
=
SharedItemSerializer
#
serializer_class = SharedItemSerializer
permission_classes
=
[
permissions
.
IsAuthenticatedOrReadOnly
,
permissions
.
AllowAny
,
# IsOwnerOrReadOnly
]
...
...
@@ -75,4 +104,8 @@ class SharedItemViewSet(viewsets.ModelViewSet):
item_json
=
serializers
.
serialize
(
"json"
,
item
)
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
return
Response
({
"shared"
:
sharedfile
.
created_time
,
'data'
:
json_data
},
status
=
status
.
HTTP_200_OK
)
item
=
ItemViewSet
.
as_view
({
'delete'
:
'destroy'
,
})
\ No newline at end of file
...
...
Please
register
or
login
to post a comment