datasette/datasette/views/special.py
Simon Willison 35d6ee2790
Apply black to everything, enforce via unit tests (#449)
I've run the black code formatting tool against everything:

    black tests datasette setup.py

I also added a new unit test, in tests/test_black.py, which will fail if the code does not
conform to black's exacting standards.

This unit test only runs on Python 3.6 or higher, because black itself doesn't run on 3.5.
2019-05-03 22:15:14 -04:00

25 lines
751 B
Python

import json
from sanic import response
from .base import RenderMixin
class JsonDataView(RenderMixin):
name = "json_data"
def __init__(self, datasette, filename, data_callback):
self.ds = datasette
self.filename = filename
self.data_callback = data_callback
async def get(self, request, as_format):
data = self.data_callback()
if as_format:
headers = {}
if self.ds.cors:
headers["Access-Control-Allow-Origin"] = "*"
return response.HTTPResponse(
json.dumps(data), content_type="application/json", headers=headers
)
else:
return self.render(["show_json.html"], filename=self.filename, data=data)