권주희

return json object

...@@ -8,15 +8,12 @@ from django.core import serializers ...@@ -8,15 +8,12 @@ from django.core import serializers
8 from django.views.decorators.csrf import csrf_exempt 8 from django.views.decorators.csrf import csrf_exempt
9 from rest_framework import viewsets 9 from rest_framework import viewsets
10 from rest_framework import permissions 10 from rest_framework import permissions
11 -from rest_framework.views import APIView
12 from rest_framework.response import Response 11 from rest_framework.response import Response
13 from rest_framework.decorators import action 12 from rest_framework.decorators import action
14 -from rest_framework.parsers import JSONParser
15 from rest_framework.permissions import IsAuthenticated, AllowAny 13 from rest_framework.permissions import IsAuthenticated, AllowAny
16 14
17 from api.models import Item, SharedItem 15 from api.models import Item, SharedItem
18 from api.serializers import UserSerializer,GroupSerializer,ItemSerializer,SharedItemSerializer 16 from api.serializers import UserSerializer,GroupSerializer,ItemSerializer,SharedItemSerializer
19 -from rest_framework import generics
20 from rest_framework import status 17 from rest_framework import status
21 from annoying.functions import get_object_or_None 18 from annoying.functions import get_object_or_None
22 19
...@@ -36,7 +33,6 @@ class ItemViewSet(viewsets.ModelViewSet): ...@@ -36,7 +33,6 @@ class ItemViewSet(viewsets.ModelViewSet):
36 permission_classes = [permissions.IsAuthenticatedOrReadOnly, permissions.AllowAny, 33 permission_classes = [permissions.IsAuthenticatedOrReadOnly, permissions.AllowAny,
37 #IsOwnerOrReadOnly 34 #IsOwnerOrReadOnly
38 ] 35 ]
39 -
40 # url: items/search 36 # url: items/search
41 @action(methods=['GET'], detail=False, permission_classes=[AllowAny], url_path='search', url_name='search') 37 @action(methods=['GET'], detail=False, permission_classes=[AllowAny], url_path='search', url_name='search')
42 def search(self, request): 38 def search(self, request):
...@@ -45,7 +41,10 @@ class ItemViewSet(viewsets.ModelViewSet): ...@@ -45,7 +41,10 @@ class ItemViewSet(viewsets.ModelViewSet):
45 item_list = Item.objects.filter(name__icontains = keyword) 41 item_list = Item.objects.filter(name__icontains = keyword)
46 42
47 data = serializers.serialize("json", item_list) 43 data = serializers.serialize("json", item_list)
48 - return Response({'data': {'list' : data}}, status=status.HTTP_200_OK) 44 + json_data = json.loads(data)
45 + return Response({'data': {'list' : json_data}}, status=status.HTTP_200_OK)
46 +
47 +
49 48
50 class SharedItemViewSet(viewsets.ModelViewSet): 49 class SharedItemViewSet(viewsets.ModelViewSet):
51 50
...@@ -66,7 +65,7 @@ class SharedItemViewSet(viewsets.ModelViewSet): ...@@ -66,7 +65,7 @@ class SharedItemViewSet(viewsets.ModelViewSet):
66 sharedfile = get_object_or_None(SharedItem, item_id=pk) 65 sharedfile = get_object_or_None(SharedItem, item_id=pk)
67 if sharedfile != None: 66 if sharedfile != None:
68 # 서버는 정상이나 이미 공유객체로 등록된 파일임 67 # 서버는 정상이나 이미 공유객체로 등록된 파일임
69 - return Response({'Message': 'This file is already shared'}, status=status.HTTP_200_OK) 68 + return Response({'message': 'This file is already shared'}, status=status.HTTP_200_OK)
70 sharedfile = SharedItem(item_id =pk, password=password, expires = expires) 69 sharedfile = SharedItem(item_id =pk, password=password, expires = expires)
71 sharedfile.save() 70 sharedfile.save()
72 sharedfile = SharedItem.objects.get(item_id = pk) 71 sharedfile = SharedItem.objects.get(item_id = pk)
...@@ -75,5 +74,5 @@ class SharedItemViewSet(viewsets.ModelViewSet): ...@@ -75,5 +74,5 @@ class SharedItemViewSet(viewsets.ModelViewSet):
75 item = Item.objects.filter(item_id = pk) 74 item = Item.objects.filter(item_id = pk)
76 item_json = serializers.serialize("json", item) 75 item_json = serializers.serialize("json", item)
77 76
78 - # data = serializers.serialize("json", item_list)
79 - return Response({"shared": sharedfile.created_time , 'data': item_json}, status=status.HTTP_200_OK)
...\ No newline at end of file ...\ No newline at end of file
77 + json_data = json.loads(item_json)
78 + return Response({"shared": sharedfile.created_time , 'data': json_data}, status=status.HTTP_200_OK)
...\ No newline at end of file ...\ No newline at end of file
......