Beispiel #1
0
 def _get_paginated_results(self, obj_class, pk, request, serializer):
     collection = get_collection(pk, request, mode='api')
     queryset = obj_class.objects.filter(collection=collection)
     paginator = StandardResultPagination()
     page = paginator.paginate_queryset(queryset, request)
     serializer = serializer(page, context={'request': request}, many=True)
     return paginator.get_paginated_response(serializer.data)
Beispiel #2
0
 def images(self, request, pk=None):
     collection = get_collection(pk,request,mode='api')
     queryset = Image.objects.filter(collection=collection)
     paginator = StandardResultPagination()
     page = paginator.paginate_queryset(queryset, request)
     serializer = ImageSerializer(page, context={'request': request}, many=True)
     return paginator.get_paginated_response(serializer.data)
Beispiel #3
0
 def datatable(self, request, pk=None):
     collection = get_collection(pk, request, mode='api')
     data = CollectionSerializer(
         collection, context={'request': request}).data
     if data and 'description' in data and data['description']:
         data['description'] = data['description'].replace('\n', '<br />')
     return APIHelper.wrap_for_datatables(data, ['owner', 'modify_date', 'images'])
Beispiel #4
0
 def _get_paginated_results(self, obj_class, pk, request, serializer):
     collection = get_collection(pk, request, mode='api')
     queryset = obj_class.objects.filter(collection=collection).order_by('id')
     paginator = StandardResultPagination()
     page = paginator.paginate_queryset(queryset, request)
     serializer = serializer(
         page, context={'request': request}, many=True)
     return paginator.get_paginated_response(serializer.data)
Beispiel #5
0
 def datatable(self, request, pk=None):
     collection = get_collection(pk, request, mode='api')
     data = CollectionSerializer(
         collection, context={'request': request}).data
     if data and 'description' in data and data['description']:
         data['description'] = data['description'].replace('\n', '<br />')
     return APIHelper.wrap_for_datatables(data, ['owner', 'modify_date',
                                                 'images'])
Beispiel #6
0
 def images(self, request, pk=None):
     collection = get_collection(pk, request, mode='api')
     queryset = Image.objects.filter(collection=collection)
     paginator = StandardResultPagination()
     page = paginator.paginate_queryset(queryset, request)
     serializer = ImageSerializer(page,
                                  context={'request': request},
                                  many=True)
     return paginator.get_paginated_response(serializer.data)
Beispiel #7
0
    def images(self, request, pk=None):
        if request.method == 'POST':
            return self.add_item(request, pk, EditableStatisticMapSerializer)

        collection = get_collection(pk, request, mode='api')
        queryset = Image.objects.filter(collection=collection)
        paginator = StandardResultPagination()
        page = paginator.paginate_queryset(queryset, request)
        serializer = ImageSerializer(
            page, context={'request': request}, many=True)
        return paginator.get_paginated_response(serializer.data)
Beispiel #8
0
    def images(self, request, pk=None):
        if request.method == 'POST':
            return self.add_item(request, pk, EditableStatisticMapSerializer)

        collection = get_collection(pk, request, mode='api')
        queryset = Image.objects.filter(collection=collection)
        paginator = StandardResultPagination()
        page = paginator.paginate_queryset(queryset, request)
        serializer = ImageSerializer(page,
                                     context={'request': request},
                                     many=True)
        return paginator.get_paginated_response(serializer.data)
Beispiel #9
0
    def add_item(self, request, pk, obj_serializer):
        collection = get_collection(pk, request, mode='api')

        if not owner_or_contrib(request, collection):
            self.permission_denied(request)

        obj = obj_serializer.Meta.model(collection=collection)
        serializer = obj_serializer(data=request.data,
                                    instance=obj,
                                    context={'request': request})

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #10
0
    def add_item(self, request, pk, obj_serializer):
        collection = get_collection(pk, request, mode='api')

        if not owner_or_contrib(request, collection):
            self.permission_denied(request)

        obj = obj_serializer.Meta.model(collection=collection)
        serializer = obj_serializer(data=request.data,
                                    instance=obj,
                                    context={'request': request})

        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data,
                            status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #11
0
 def retrieve(self, request, pk=None):
     collection = get_collection(pk,request,mode='api')
     data = CollectionSerializer(collection, context={'request': request}).data
     return Response(data)
Beispiel #12
0
 def retrieve(self, request, pk=None):
     collection = get_collection(pk, request, mode='api')
     data = CollectionSerializer(collection, context={
         'request': request
     }).data
     return Response(data)