Showing
1 changed file
with
33 additions
and
22 deletions
| ... | @@ -187,28 +187,39 @@ class ItemViewSet(viewsets.ViewSet): | ... | @@ -187,28 +187,39 @@ class ItemViewSet(viewsets.ViewSet): |
| 187 | if request.method == 'POST': | 187 | if request.method == 'POST': |
| 188 | parent_id = request.POST.get('parent', '') | 188 | parent_id = request.POST.get('parent', '') |
| 189 | name = request.POST.get('name','') | 189 | name = request.POST.get('name','') |
| 190 | - parent = get_object_or_None(Item, item_id=parent_id) | 190 | + child = get_object_or_None(Item, item_id=pk) |
| 191 | - if parent != None and parent.is_folder == True: | 191 | + |
| 192 | - child = get_object_or_None(Item, item_id=pk) | 192 | + if child == None: |
| 193 | - if child == None: | 193 | + return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) |
| 194 | - return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | 194 | + |
| 195 | - child.parent = parent_id | 195 | + if parent_id != '': |
| 196 | - child.save() | 196 | + parent = get_object_or_None(Item, item_id=parent_id) |
| 197 | - child = Item.objects.filter(item_id = pk) | 197 | + |
| 198 | - child_data = serializers.serialize("json", child) | 198 | + if parent == None: |
| 199 | - json_child = json.loads(child_data) | 199 | + return Response({'message': 'parent is not existed.'}, status=status.HTTP_200_OK) |
| 200 | - res = json_child[0]['fields'] | 200 | + if parent.is_folder == False: |
| 201 | - res['id'] = pk | 201 | + return Response({'message': 'parent is not folder.'}, status=status.HTTP_200_OK) |
| 202 | - parent = Item.objects.filter(item_id = parent_id) | 202 | + |
| 203 | - parent_data = serializers.serialize("json", parent) | 203 | + if parent != None and parent.is_folder == True: |
| 204 | - json_parent = json.loads(parent_data)[0]['fields'] | 204 | + child.parent = parent_id |
| 205 | - res['parentInfo'] = json_parent | 205 | + else: |
| 206 | - return Response({'data': res}, status=status.HTTP_200_OK) | 206 | + parent_id = child.parent |
| 207 | - if parent == None: | 207 | + |
| 208 | - return Response({'message': 'parent is not existed.'}, status=status.HTTP_200_OK) | 208 | + if name != '': |
| 209 | - if parent.is_folder == False: | 209 | + child.name = name; |
| 210 | - return Response({'message': 'parent is not folder.'}, status=status.HTTP_200_OK) | 210 | + |
| 211 | - return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | 211 | + child.save() |
| 212 | + child = Item.objects.filter(item_id = pk) | ||
| 213 | + child_data = serializers.serialize("json", child) | ||
| 214 | + json_child = json.loads(child_data) | ||
| 215 | + res = json_child[0]['fields'] | ||
| 216 | + res['id'] = pk | ||
| 217 | + parent = Item.objects.filter(item_id = parent_id) | ||
| 218 | + parent_data = serializers.serialize("json", parent) | ||
| 219 | + json_parent = json.loads(parent_data)[0]['fields'] | ||
| 220 | + res['parentInfo'] = json_parent | ||
| 221 | + | ||
| 222 | + return Response({'data': res}, status=status.HTTP_200_OK) | ||
| 212 | 223 | ||
| 213 | @action(methods=['POST'], detail=True, permission_classes=[AllowAny], url_path='copy', url_name='copy') | 224 | @action(methods=['POST'], detail=True, permission_classes=[AllowAny], url_path='copy', url_name='copy') |
| 214 | def copy(self, request, pk): | 225 | def copy(self, request, pk): | ... | ... |
-
Please register or login to post a comment