From 47453b78c50a90442d5f76fb85bb3cf531a92aee Mon Sep 17 00:00:00 2001 From: Christian Glatthard Date: Mon, 31 Aug 2015 09:21:32 +0200 Subject: [PATCH] fix create image over api --- ipynbsrv/api/serializer.py | 11 +++++++++++ ipynbsrv/api/views.py | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ipynbsrv/api/serializer.py b/ipynbsrv/api/serializer.py index cc7337f..dc58473 100644 --- a/ipynbsrv/api/serializer.py +++ b/ipynbsrv/api/serializer.py @@ -206,6 +206,17 @@ class Meta: model = ContainerImage +class FlatContainerImageSerializer(serializers.ModelSerializer): + """ + Todo: write doc. + """ + friendly_name = serializers.CharField(read_only=True, source='get_friendly_name') + access_groups = FlatCollaborationGroupSerializer(many=True, read_only=True) + + class Meta: + model = ContainerImage + + class ContainerSnapshotSerializer(serializers.ModelSerializer): """ Todo: write doc. diff --git a/ipynbsrv/api/views.py b/ipynbsrv/api/views.py index 545433c..44cf685 100644 --- a/ipynbsrv/api/views.py +++ b/ipynbsrv/api/views.py @@ -712,7 +712,11 @@ class ContainerImageList(generics.ListCreateAPIView): """ Get a list of all the container images. """ - serializer_class = ContainerImageSerializer + + def get_serializer_class(self, *args, **kwargs): + if self.request.method in ['PATCH', 'POST', 'PUT']: + return FlatContainerImageSerializer + return ContainerImageSerializer def get_queryset(self): if self.request.user.is_superuser: