mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
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.
25 lines
751 B
Python
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)
|