From eace1f622aa05d24891679cfaa1361674e59e978 Mon Sep 17 00:00:00 2001 From: David Kane Date: Wed, 20 Dec 2023 13:39:02 +0000 Subject: [PATCH] first try at html reconcile page --- specs | 2 +- src/datasette_reconcile/__init__.py | 8 +++- .../templates/reconcile.html | 19 +++++++++ src/datasette_reconcile/views.py | 42 +++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/datasette_reconcile/templates/reconcile.html create mode 100644 src/datasette_reconcile/views.py diff --git a/specs b/specs index aaf439d..1812f84 160000 --- a/specs +++ b/specs @@ -1 +1 @@ -Subproject commit aaf439dd10cce35a13947a1d9f62347fbbc1f2ff +Subproject commit 1812f84d7f34a8342c0b7f2899ef032bcad6601a diff --git a/src/datasette_reconcile/__init__.py b/src/datasette_reconcile/__init__.py index b74d17c..a83e12c 100644 --- a/src/datasette_reconcile/__init__.py +++ b/src/datasette_reconcile/__init__.py @@ -2,6 +2,7 @@ from datasette_reconcile.reconcile import ReconcileAPI from datasette_reconcile.utils import check_config, check_permissions +from datasette_reconcile.views import ReconcileHTML async def reconcile(request, datasette): @@ -30,5 +31,8 @@ async def reconcile(request, datasette): @hookimpl -def register_routes(): - return [(r"/(?P[^/]+)/(?P[^/]+?)/-/reconcile$", reconcile)] +def register_routes(datasette): + return [ + (r"/(?P[^/]+)/(?P[^/]+?)/-/reconcile$", reconcile), + (r"/(?P[^/]+)/(?P[^/]+?)/-/reconcile.html$", ReconcileHTML.as_view(datasette)), + ] diff --git a/src/datasette_reconcile/templates/reconcile.html b/src/datasette_reconcile/templates/reconcile.html new file mode 100644 index 0000000..092efe4 --- /dev/null +++ b/src/datasette_reconcile/templates/reconcile.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block title %}{{ metadata.title or "Datasette" }}: Reconciliation{% endblock %} + +{%- block extra_head %} +{{- super() -}} + + +{% endblock -%} + +{% block content %} +

{{ metadata.title or "Datasette" }} Reconciliation {% if private %} 🔒{% endif %}

+ +{{ reconcile_config }} +{% endblock %} \ No newline at end of file diff --git a/src/datasette_reconcile/views.py b/src/datasette_reconcile/views.py new file mode 100644 index 0000000..b875866 --- /dev/null +++ b/src/datasette_reconcile/views.py @@ -0,0 +1,42 @@ +from datasette.version import __version__ +from datasette.views.base import BaseView + +from datasette_reconcile.utils import check_config, check_permissions + + +class ReconcileHTML(BaseView): + name = "reconcile_html" + + async def get(self, request): + database = request.url_vars["db_name"] + table = request.url_vars["db_table"] + db = self.ds.get_database(database) + + # get plugin configuration + config = self.ds.plugin_config("datasette-reconcile", database=database, table=table) + config = await check_config(config, db, table) + + # check user can at least view this table + await check_permissions( + request, + [ + ("view-table", (database, table)), + ("view-database", database), + "view-instance", + ], + self.ds, + ) + + return await self.render( + ["reconcile.html"], + request=request, + context={ + "database": database, + "table": table, + "reconcile_config": config, + "reconcile_url": self.ds.absolute_url(request, self.ds.urls.table(database, table) + "/-/reconcile"), + "metadata": self.ds.metadata(), + "datasette_version": __version__, + "private": not await self.ds.permission_allowed(None, "view-instance"), + }, + )