Merge branch 'feature/folder' into 'develop'
Feature/folder See merge request !8
Showing
2 changed files
with
35 additions
and
0 deletions
... | @@ -148,6 +148,40 @@ class ItemViewSet(viewsets.ViewSet): | ... | @@ -148,6 +148,40 @@ class ItemViewSet(viewsets.ViewSet): |
148 | # action is not set return default permission_classes | 148 | # action is not set return default permission_classes |
149 | return [permission() for permission in self.permission_classes] | 149 | return [permission() for permission in self.permission_classes] |
150 | 150 | ||
151 | + # url: items/{key}/children/ | ||
152 | + @action(methods=['GET', 'POST'], detail=True, permission_classes=[AllowAny], | ||
153 | + url_path='children', url_name='children') | ||
154 | + def children(self, request, pk): | ||
155 | + if request.method == 'GET': | ||
156 | + children = Item.objects.filter(parent = pk) | ||
157 | + children_data = serializers.serialize("json", children) | ||
158 | + json_children = json.loads(children_data) | ||
159 | + parent = Item.objects.filter(item_id=pk) #item | ||
160 | + parent_data = serializers.serialize("json", parent) | ||
161 | + json_parent = json.loads(parent_data)[0]['fields'] | ||
162 | + res = json_parent | ||
163 | + res['id'] = pk | ||
164 | + children_list = [] | ||
165 | + for i in json_children: | ||
166 | + t = i['fields'] | ||
167 | + t['id'] = i['pk'] | ||
168 | + children_list.append(t) | ||
169 | + res['list'] = children_list | ||
170 | + return Response({'data': res}, status=status.HTTP_200_OK) | ||
171 | + if request.method == 'POST': | ||
172 | + name = request.POST.get('name', ''함) | ||
173 | + #TODO: user_id 수정해야 | ||
174 | + item = Item(is_folder=True, name=name, file_type="folder", path="", parent=pk, user_id=1, size=0, status=True) | ||
175 | + item.save() | ||
176 | + item = Item.objects.filter(item_id = item.item_id) | ||
177 | + item_data = serializers.serialize("json", item) | ||
178 | + json_item = json.loads(item_data) | ||
179 | + res = json_item[0]['fields'] | ||
180 | + res['id']=json_item[0]['pk'] | ||
181 | + res['inside_folder_list'] = [] | ||
182 | + res['inside_file_list'] = [] | ||
183 | + return Response({'data': res}, status=status.HTTP_200_OK) | ||
184 | + | ||
151 | 185 | ||
152 | class SharedItemViewSet(viewsets.ModelViewSet): | 186 | class SharedItemViewSet(viewsets.ModelViewSet): |
153 | 187 | ... | ... |
... | @@ -33,5 +33,6 @@ urlpatterns = [ | ... | @@ -33,5 +33,6 @@ urlpatterns = [ |
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 | url(r'^<int:pk>/move/$', views.ItemViewSet.move, name='move'), |
35 | url(r'^<int:pk>/copy/$', views.ItemViewSet.copy, name='copy'), | 35 | url(r'^<int:pk>/copy/$', views.ItemViewSet.copy, name='copy'), |
36 | + url(r'^<int:pk>/children/$', views.ItemViewSet.children, name='copy'), | ||
36 | 37 | ||
37 | ] | 38 | ] | ... | ... |
-
Please register or login to post a comment