Showing
2 changed files
with
25 additions
and
0 deletions
... | @@ -144,6 +144,30 @@ class ItemViewSet(viewsets.ViewSet): | ... | @@ -144,6 +144,30 @@ class ItemViewSet(viewsets.ViewSet): |
144 | # action is not set return default permission_classes | 144 | # action is not set return default permission_classes |
145 | return [permission() for permission in self.permission_classes] | 145 | return [permission() for permission in self.permission_classes] |
146 | 146 | ||
147 | + #url: items/{key}/children/ | ||
148 | + @action(methods=['GET', 'POST'], detail=True, permission_classes=[AllowAny], | ||
149 | + url_path='children', url_name='children') | ||
150 | + def children(self, request, pk, *args, **kwargs): | ||
151 | + if request.method == 'GET': | ||
152 | + parent_item = Item.objects.get(pk = pk) | ||
153 | + try: | ||
154 | + parent_item = get_object_or_404(Item, pk = pk) | ||
155 | + except parent_item.DoesNotExist: | ||
156 | + return Response({'Error': 'Folder does not exist.'}) | ||
157 | + items = Item.objects.get(parent = parent_item.pk) | ||
158 | + return Response(items) | ||
159 | + | ||
160 | + if request.method == 'POST': | ||
161 | + data = JSONParser().parse(request) | ||
162 | + serializer = ItemSerializer(data=data) | ||
163 | + if serializer.is_valid(): | ||
164 | + serializer.save() | ||
165 | + return Response(serializer.data) | ||
166 | + return Response(serializer.errors) | ||
167 | + | ||
168 | + | ||
169 | + | ||
170 | + | ||
147 | 171 | ||
148 | class SharedItemViewSet(viewsets.ModelViewSet): | 172 | class SharedItemViewSet(viewsets.ModelViewSet): |
149 | 173 | ... | ... |
... | @@ -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'^children/$', views.ItemViewSet.children, name='children'), | ||
36 | 37 | ||
37 | ] | 38 | ] | ... | ... |
-
Please register or login to post a comment