Python rest_framework.generics.ListAPIView() Examples

The following are 7 code examples of rest_framework.generics.ListAPIView(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module rest_framework.generics , or try the search function .
Example #1
Source File: test_backend.py    From drf-mongo-filters with GNU General Public License v2.0 6 votes vote down vote up
def test_model_mismatch(self):
        """ cannot apply filters for one model to queryset from another """
        class FooDoc(Document):
            foo = fields.StringField()

        class BarDoc(Document):
            bar = fields.StringField()

        class FooFilter(ModelFilterset):
            class Meta:
                model = FooDoc

        class BarView(ListAPIView):
            filter_backends = (MongoFilterBackend,)
            filter_class = FooFilter
            serializer_class = mock.Mock()
            queryset = BarDoc.objects

        with self.assertRaises(TypeError):
            BarView.as_view()(APIRequestFactory().get("/?foo=Foo")) 
Example #2
Source File: test_backend.py    From drf-mongo-filters with GNU General Public License v2.0 6 votes vote down vote up
def test_model_subclassed(self):
        """ can apply filters for base model to queryset of derived """
        class FooDoc(Document):
            meta = { 'allow_inheritance': True}
            foo = fields.StringField()

        class BarDoc(FooDoc):
            bar = fields.StringField()

        class FooFilter(ModelFilterset):
            class Meta:
                model = FooDoc

        class BarView(ListAPIView):
            filter_backends = (MongoFilterBackend,)
            filter_class = FooFilter
            serializer_class = mock.Mock()
            queryset = BarDoc.objects

        BarView.as_view()(APIRequestFactory().get("/?foo=Foo")) 
Example #3
Source File: test_backend.py    From drf-mongo-filters with GNU General Public License v2.0 5 votes vote down vote up
def test_view(self):
        class TestFilter(Filterset):
            foo = filters.CharFilter()

        class TestView(ListAPIView):
            filter_backends = (MongoFilterBackend,)
            filter_class = TestFilter
            serializer_class = mock.Mock()
            queryset = mock.Mock()

        TestView.as_view()(APIRequestFactory().get("/?foo=Foo"))
        TestView.queryset.filter.assert_called_once_with(foo="Foo") 
Example #4
Source File: test_backend.py    From drf-mongo-filters with GNU General Public License v2.0 5 votes vote down vote up
def test_unknown_class(self):
        """ filter_class should be our Filterset """
        class Dumb():
            pass

        class TestView(ListAPIView):
            filter_backends = (MongoFilterBackend,)
            filter_class = Dumb
            serializer_class = mock.Mock()
            queryset = mock.Mock()

        with self.assertRaises(TypeError):
            TestView.as_view()(APIRequestFactory().get("/?foo=Foo")) 
Example #5
Source File: views.py    From REST-API with MIT License 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        return Response({"detail": "Not allowed here"}, status=400)
        

# class UserStatusAPIView(generics.ListAPIView):
#     serializer_class            = StatusInlineUserSerializer
#     search_fields               = ('user__username', 'content')
#     #pagination_class    = CFEAPIPagination

#     def get_queryset(self, *args, **kwargs):
#         username = self.kwargs.get("username", None)
#         if username is None:
#             return Status.objects.none()
#         return Status.objects.filter(user__username=username) 
Example #6
Source File: test_autofilter.py    From drf_tweaks with MIT License 5 votes vote down vote up
def test_excluding_fields(self):
        @autofilter(exclude_fields=("indexed_int", "indexed_char", ))
        class SampleApiV7(ListAPIView):
            permission_classes = (AllowAny,)
            serializer_class = SampleModelForAutofilterSerializerVer1
            queryset = SampleModelForAutofilter.objects.all()

        self.assertEqual(set(SampleApiV7.filter_fields.keys()), {"id", "fk", "indexed_text", "indexed_url",
                                                                 "indexed_email", "nullable_field", "unique_text"}) 
Example #7
Source File: views.py    From Django-Angular-Ionic with MIT License 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        return Response({"detail": "Not allowed here"}, status=400)
        

# class UserStatusAPIView(generics.ListAPIView):
#     serializer_class            = StatusInlineUserSerializer
#     search_fields               = ('user__username', 'content')
#     #pagination_class    = CFEAPIPagination

#     def get_queryset(self, *args, **kwargs):
#         username = self.kwargs.get("username", None)
#         if username is None:
#             return Status.objects.none()
#         return Status.objects.filter(user__username=username)