권주희

return json object

......@@ -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({'Message': 'This file is already shared'}, status=status.HTTP_200_OK)
return Response({'message': '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
......