def configure_renderers(config): json_renderer = JSONRendererFactory(indent=4) json_renderer.add_adapter(Car, lambda c, _: c.to_dict()) config.add_renderer('json', json_renderer) csv_renderer = CSVRendererFactory() csv_renderer.add_adapter(Car, lambda c, _: c.to_dict()) config.add_renderer('csv', csv_renderer) # image_renderer = ImageRedirectRendererFactory() image_renderer = ImageDirectRendererFactory() image_renderer.add_adapter(Car, lambda c, _: c.to_dict()) config.add_renderer('png', image_renderer)
def configure_renderers(config): json_renderer = JSONRendererFactory(indent=4) json_renderer.add_adapter(Car, lambda c, _: c.to_dict()) json_renderer.add_adapter(datetime.datetime, lambda d, _: str(d.isoformat())) config.add_renderer('json', json_renderer) csv_renderer = CSVRendererFactory() csv_renderer.add_adapter(Car, lambda c, _: c.to_dict()) config.add_renderer('csv', csv_renderer) image_renderer = ImageDirectRendererFactory() image_renderer.add_adapter(Car, lambda c, _: c.to_dict()) config.add_renderer('png', image_renderer) negociate_renderer = NegotiatingRendererFactory() negociate_renderer.add_accept_all_renderer(json_renderer) negociate_renderer.add_renderer('application/json', json_renderer) negociate_renderer.add_renderer('text/csv', csv_renderer) negociate_renderer.add_renderer('image/png', image_renderer) config.add_renderer('negociate', negociate_renderer)