Showing
2 changed files
with
26 additions
and
1 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 | ||
... | @@ -181,4 +205,4 @@ class SharedItemViewSet(viewsets.ModelViewSet): | ... | @@ -181,4 +205,4 @@ class SharedItemViewSet(viewsets.ModelViewSet): |
181 | 205 | ||
182 | item = ItemViewSet.as_view({ | 206 | item = ItemViewSet.as_view({ |
183 | 'delete': 'destroy', | 207 | 'delete': 'destroy', |
184 | -}) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
208 | +}) | ... | ... |
... | @@ -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