mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Remove load_plugin hook - closes #1073
Refs #1042
This reverts commit 81dea4b07a.
This commit is contained in:
parent
a2a7090720
commit
f0a740ac21
8 changed files with 11 additions and 73 deletions
|
|
@ -21,7 +21,7 @@ from pathlib import Path
|
|||
from markupsafe import Markup
|
||||
from itsdangerous import URLSafeSerializer
|
||||
import jinja2
|
||||
from jinja2 import ChoiceLoader, Environment, FileSystemLoader, PrefixLoader
|
||||
from jinja2 import ChoiceLoader, Environment, FileSystemLoader, PrefixLoader, escape
|
||||
from jinja2.environment import Template
|
||||
from jinja2.exceptions import TemplateNotFound
|
||||
import uvicorn
|
||||
|
|
@ -713,41 +713,12 @@ class Datasette:
|
|||
self, templates, context=None, request=None, view_name=None
|
||||
):
|
||||
context = context or {}
|
||||
templates_considered = []
|
||||
if isinstance(templates, Template):
|
||||
template = templates
|
||||
else:
|
||||
if isinstance(templates, str):
|
||||
templates = [templates]
|
||||
|
||||
# Give plugins first chance at loading the template
|
||||
break_outer = False
|
||||
plugin_template_source = None
|
||||
plugin_template_name = None
|
||||
template_name = None
|
||||
for template_name in templates:
|
||||
if break_outer:
|
||||
break
|
||||
plugin_template_source = pm.hook.load_template(
|
||||
template=template_name,
|
||||
request=request,
|
||||
datasette=self,
|
||||
)
|
||||
plugin_template_source = await await_me_maybe(plugin_template_source)
|
||||
if plugin_template_source:
|
||||
break_outer = True
|
||||
plugin_template_name = template_name
|
||||
break
|
||||
if plugin_template_source is not None:
|
||||
template = self.jinja_env.from_string(plugin_template_source)
|
||||
else:
|
||||
template = self.jinja_env.select_template(templates)
|
||||
for template_name in templates:
|
||||
from_plugin = template_name == plugin_template_name
|
||||
used = from_plugin or template_name == template.name
|
||||
templates_considered.append(
|
||||
{"name": template_name, "used": used, "from_plugin": from_plugin}
|
||||
)
|
||||
template = self.jinja_env.select_template(templates)
|
||||
body_scripts = []
|
||||
# pylint: disable=no-member
|
||||
for extra_script in pm.hook.extra_body_script(
|
||||
|
|
@ -812,7 +783,6 @@ class Datasette:
|
|||
),
|
||||
"base_url": self.config("base_url"),
|
||||
"csrftoken": request.scope["csrftoken"] if request else lambda: "",
|
||||
"templates_considered": templates_considered,
|
||||
},
|
||||
**extra_template_vars,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,11 +49,6 @@ def extra_template_vars(
|
|||
"Extra template variables to be made available to the template - can return dict or callable or awaitable"
|
||||
|
||||
|
||||
@hookspec(firstresult=True)
|
||||
def load_template(template, request, datasette):
|
||||
"Load the specified template, returning the template code as a string"
|
||||
|
||||
|
||||
@hookspec
|
||||
def publish_subcommand(publish):
|
||||
"Subcommands for 'datasette publish'"
|
||||
|
|
|
|||
|
|
@ -79,10 +79,6 @@ document.body.addEventListener('click', (ev) => {
|
|||
<script>{{ body_script }}</script>
|
||||
{% endfor %}
|
||||
|
||||
{% if templates_considered %}
|
||||
<!-- Templates considered:
|
||||
{% for template in templates_considered %}- {{ template.name }}{% if template.used %} (used{% if template.from_plugin %}, from plugin{% endif %}){% endif %}
|
||||
{% endfor %}-->
|
||||
{% endif %}
|
||||
{% if select_templates %}<!-- Templates considered: {{ select_templates|join(", ") }} -->{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -119,15 +119,22 @@ class BaseView:
|
|||
|
||||
async def render(self, templates, request, context=None):
|
||||
context = context or {}
|
||||
template = self.ds.jinja_env.select_template(templates)
|
||||
template_context = {
|
||||
**context,
|
||||
**{
|
||||
"database_color": self.database_color,
|
||||
"select_templates": [
|
||||
"{}{}".format(
|
||||
"*" if template_name == template.name else "", template_name
|
||||
)
|
||||
for template_name in templates
|
||||
],
|
||||
},
|
||||
}
|
||||
return Response.html(
|
||||
await self.ds.render_template(
|
||||
templates, template_context, request=request, view_name=self.name
|
||||
template, template_context, request=request, view_name=self.name
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue