Пример #1
0
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())
    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)

    negotiate_renderer = NegotiatingRendererFactory()
    negotiate_renderer.add_accept_all_renderer(json_renderer)
    negotiate_renderer.add_renderer('application/json', json_renderer)
    negotiate_renderer.add_renderer('text/csv', csv_renderer)
    negotiate_renderer.add_renderer('image/png', image_renderer)
    negotiate_renderer.add_adapter(Car, lambda c, _: c.to_dict())
    config.add_renderer('negotiate', negotiate_renderer)