Showing
1 changed file
with
18 additions
and
7 deletions
... | @@ -187,12 +187,27 @@ class ItemViewSet(viewsets.ViewSet): | ... | @@ -187,12 +187,27 @@ 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) | ||
191 | - if parent != None and parent.is_folder == True: | ||
192 | child = get_object_or_None(Item, item_id=pk) | 190 | child = get_object_or_None(Item, item_id=pk) |
191 | + | ||
193 | if child == None: | 192 | if child == None: |
194 | return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | 193 | return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) |
194 | + | ||
195 | + if parent_id != '': | ||
196 | + parent = get_object_or_None(Item, item_id=parent_id) | ||
197 | + | ||
198 | + if parent == None: | ||
199 | + return Response({'message': 'parent is not existed.'}, status=status.HTTP_200_OK) | ||
200 | + if parent.is_folder == False: | ||
201 | + return Response({'message': 'parent is not folder.'}, status=status.HTTP_200_OK) | ||
202 | + | ||
203 | + if parent != None and parent.is_folder == True: | ||
195 | child.parent = parent_id | 204 | child.parent = parent_id |
205 | + else: | ||
206 | + parent_id = child.parent | ||
207 | + | ||
208 | + if name != '': | ||
209 | + child.name = name; | ||
210 | + | ||
196 | child.save() | 211 | child.save() |
197 | child = Item.objects.filter(item_id = pk) | 212 | child = Item.objects.filter(item_id = pk) |
198 | child_data = serializers.serialize("json", child) | 213 | child_data = serializers.serialize("json", child) |
... | @@ -203,12 +218,8 @@ class ItemViewSet(viewsets.ViewSet): | ... | @@ -203,12 +218,8 @@ class ItemViewSet(viewsets.ViewSet): |
203 | parent_data = serializers.serialize("json", parent) | 218 | parent_data = serializers.serialize("json", parent) |
204 | json_parent = json.loads(parent_data)[0]['fields'] | 219 | json_parent = json.loads(parent_data)[0]['fields'] |
205 | res['parentInfo'] = json_parent | 220 | res['parentInfo'] = json_parent |
221 | + | ||
206 | return Response({'data': res}, status=status.HTTP_200_OK) | 222 | return Response({'data': res}, status=status.HTTP_200_OK) |
207 | - if parent == None: | ||
208 | - return Response({'message': 'parent is not existed.'}, status=status.HTTP_200_OK) | ||
209 | - if parent.is_folder == False: | ||
210 | - return Response({'message': 'parent is not folder.'}, status=status.HTTP_200_OK) | ||
211 | - return Response({'message': 'item is not existed.'}, status=status.HTTP_204_NO_CONTENT) | ||
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