def remove(self, request, pk): """ Queues a task that creates a new RepositoryVersion by removing content units. """ remove_content_units = [] repository = self.get_object() serializer = serializers.RecursiveManageSerializer(data=request.data) serializer.is_valid(raise_exception=True) if "content_units" in request.data: for url in request.data["content_units"]: if url == "*": remove_content_units = [url] break content = NamedModelViewSet.get_resource(url, Content) remove_content_units.append(content.pk) result = enqueue_with_reservation( tasks.recursive_remove_content, [repository], kwargs={ "repository_pk": repository.pk, "content_units": remove_content_units }, ) return OperationPostponedResponse(result, request)
def add(self, request, pk): """ Queues a task that creates a new RepositoryVersion by adding content units. """ add_content_units = [] repository = self.get_object() serializer = serializers.RecursiveManageSerializer(data=request.data) serializer.is_valid(raise_exception=True) if "content_units" in request.data: for url in request.data["content_units"]: content = NamedModelViewSet.get_resource(url, Content) add_content_units.append(str(content.pk)) result = dispatch( tasks.recursive_add_content, [repository], kwargs={ "repository_pk": str(repository.pk), "content_units": add_content_units }, ) return OperationPostponedResponse(result, request)