Showing
2 changed files
with
32 additions
and
0 deletions
... | @@ -63,10 +63,41 @@ class ItemViewSet(viewsets.ViewSet): | ... | @@ -63,10 +63,41 @@ class ItemViewSet(viewsets.ViewSet): |
63 | if item.is_folder == True: # 폴더는 삭제 안되도록 처리 | 63 | if item.is_folder == True: # 폴더는 삭제 안되도록 처리 |
64 | return Response({'message': 'This item is folder.'}, status=status.HTTP_200_OK) | 64 | return Response({'message': 'This item is folder.'}, status=status.HTTP_200_OK) |
65 | item.is_deleted = True | 65 | item.is_deleted = True |
66 | + item.save() | ||
66 | # item.delete() 이거 하면 완전 삭제되어버림 is deleted True 면 휴지통에서 리스트 조회할 수 있도록! | 67 | # item.delete() 이거 하면 완전 삭제되어버림 is deleted True 면 휴지통에서 리스트 조회할 수 있도록! |
67 | return Response({'message': 'delete complete'},status=status.HTTP_200_OK) | 68 | return Response({'message': 'delete complete'},status=status.HTTP_200_OK) |
68 | return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | 69 | return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) |
69 | 70 | ||
71 | + # url: items/11/move | ||
72 | + # 마지막 slash도 써주어야함 | ||
73 | + @action(methods=['POST'], detail=True, permission_classes=[AllowAny], url_path='move', url_name='move') | ||
74 | + def move(self, request, pk): | ||
75 | + if request.method == 'POST': | ||
76 | + parent_id = request.POST.get('parent', '') | ||
77 | + name = request.POST.get('name','') | ||
78 | + parent = get_object_or_None(Item, item_id=parent_id) | ||
79 | + if parent != None and parent.is_folder == True: | ||
80 | + child = get_object_or_None(Item, item_id=pk) | ||
81 | + child.parent = parent_id | ||
82 | + child.save() | ||
83 | + child = Item.objects.filter(item_id = pk) | ||
84 | + child_data = serializers.serialize("json", child) | ||
85 | + json_child = json.loads(child_data) | ||
86 | + res = json_child[0]['fields'] | ||
87 | + res['id'] = pk | ||
88 | + parent = Item.objects.filter(item_id = parent_id) | ||
89 | + parent_data = serializers.serialize("json", parent) | ||
90 | + json_parent = json.loads(parent_data)[0]['fields'] | ||
91 | + res['parentInfo'] = json_parent | ||
92 | + return Response({'data': res}, status=status.HTTP_200_OK) | ||
93 | + if parent == None: | ||
94 | + return Response({'message': 'item is not existed.'}, status=status.HTTP_200_OK) | ||
95 | + if parent.is_folder == False: | ||
96 | + return Response({'message': 'item is not folder.'}, status=status.HTTP_200_OK) | ||
97 | + return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | ||
98 | + | ||
99 | + | ||
100 | + | ||
70 | def get_permissions(self): | 101 | def get_permissions(self): |
71 | try: | 102 | try: |
72 | # return permission_classes depending on `action` | 103 | # return permission_classes depending on `action` | ... | ... |
... | @@ -31,5 +31,6 @@ urlpatterns = [ | ... | @@ -31,5 +31,6 @@ urlpatterns = [ |
31 | path('', include(router.urls)), | 31 | path('', include(router.urls)), |
32 | url(r'^search/$', views.ItemViewSet.search, name='search'), | 32 | url(r'^search/$', views.ItemViewSet.search, name='search'), |
33 | url(r'^<int:pk>/share/$', views.SharedItemViewSet.share, name='share'), | 33 | url(r'^<int:pk>/share/$', views.SharedItemViewSet.share, name='share'), |
34 | + url(r'^<int:pk>/move/$', views.ItemViewSet.move, name='move'), | ||
34 | 35 | ||
35 | ] | 36 | ] | ... | ... |
-
Please register or login to post a comment