Esempio n. 1
0
        queryset = Person.objects.all()
        serializer = PersonSerializer(queryset, many=True)
        return Response(serializer.data)

    def retrieve(self, request, pk=None):
        queryset = Person.objects.all()
        item = get_object_or_404(queryset, pk=pk)
        serializer = PersonSerializer(item)
        return Response(serializer.data)


class CategoryViewSet(ViewSet):
    def list(self, request):
        queryset = Category.objects.all()
        serializer = CategorySerializer(queryset, many=True)
        return Response(serializer.data)

    def retrieve(self, request, pk=None):
        queryset = Category.objects.all()
        item = get_object_or_404(queryset, pk=pk)
        serializer = CategorySerializer(item)
        return Response(serializer.data)


# Add environment specific endpoints
try:
    utils.apply_custom_methods(TopicViewSet, "views", "TopicViewSet",
                               "includeMethods")
except:
    pass
        if not latest:
            latest = item
        serializer = CredentialSerializer(latest)
        return Response(serializer.data)

    def get_object(self):
        pk = self.kwargs.get("pk")
        if not pk:
            raise Http404()
        filter = {"credential_id": pk}
        try:
            filter = {"pk": int(pk)}
        except (ValueError, TypeError):
            pass

        queryset = self.filter_queryset(self.get_queryset())
        obj = get_object_or_404(queryset, **filter)

        # May raise a permission denied
        self.check_object_permissions(self.request, obj)
        return obj


# Add environment specific endpoints
try:
    # utils.apply_custom_methods(TopicViewSet, "views", "TopicViewSet", "includeMethods")
    utils.apply_custom_methods(TopicRelationshipViewSet, "views",
                               "TopicRelationshipViewSet", "includeMethods")
except:
    pass