def get_renderers(self): my_renderers = super().get_renderers() if self.action == 'list': my_renderers.append(renderers.BrowsableAPIRenderer()) elif self.action == 'retrieve': my_renderers.append(EntityTripMapRenderer()) return my_renderers
def get_renderers(self): # When displaying a list the browsable API is used for HTML but for # details a map is displayed with the individual cluster results. my_renderers = super().get_renderers() if self.action == 'list': my_renderers.append(renderers.BrowsableAPIRenderer()) elif self.action == 'retrieve': my_renderers.append(ClusterMapRenderer()) return my_renderers
def test_browsable_renderer_put_render(self): """ Test, that PUT method works with BrowsableAPIRenderer This was not working in the past, because of `_get_serializer` didn't allow `instance parameter. """ data = {'blah': 'blah'} method = 'PUT' request = rest_request.Request(APIRequestFactory().get('blah')) input_view = (api_view([method]))(self._dummy_view) output_view = self.decorator(input_view) wrapper_cls = output_view.cls test_view_instance = wrapper_cls() renderer = renderers.BrowsableAPIRenderer() renderer.accepted_media_type = None renderer.renderer_context = {} response = renderer.get_raw_data_form( data, test_view_instance, method, request, ) self.assertEqual(response.data, {})
def test_browsable_renderer_put_render(input_put_view, decorator): """ Test, that PUT method works with BrowsableAPIRenderer This was not working in the past, because of `_get_serializer` didn't allow `instance parameter. """ data = {'blah': 'blah'} method = 'PUT' request = rest_request.Request(APIRequestFactory().get('blah')) output_view = decorator(input_put_view) wrapper_cls = _get_view_class(output_view) test_view_instance = wrapper_cls() renderer = renderers.BrowsableAPIRenderer() renderer.accepted_media_type = None renderer.renderer_context = {} response = renderer.get_raw_data_form( data, test_view_instance, method, request, ) assert response.data == {}
def get_renderers(self): if self.html: renderers_classes = [renderers.TemplateHTMLRenderer()] else: renderers_classes = [renderers.BrowsableAPIRenderer()] return renderers_classes