Allow custom units to be registered with Pint

This commit is contained in:
Russ Garrett 2018-04-14 12:27:06 +01:00
commit 3c985ec271
No known key found for this signature in database
GPG key ID: 68880BB652AB0570
2 changed files with 15 additions and 1 deletions

View file

@ -1186,6 +1186,11 @@ class Datasette:
}
return self._inspect
def register_custom_units(self):
"Register any custom units defined in the metadata.json with Pint"
for unit in self.metadata.get('custom_units', []):
ureg.define(unit)
def app(self):
app = Sanic(__name__)
default_templates = str(app_root / 'datasette' / 'templates')
@ -1230,6 +1235,8 @@ class Datasette:
'/<db_name:[^/]+>/<table:[^/]+?>/<pk_path:[^/]+?><as_json:(\.jsono?)?$>'
)
self.register_custom_units()
@app.exception(Exception)
def on_exception(request, exception):
title = None