fix: simplify plugin loading in plugin page
This also allows us to handle missing plugins, i.e: /plugin/missingplugin.
This commit is contained in:
parent
6e51ee2f3c
commit
6da10d199b
@ -125,24 +125,13 @@ async def plugin_installed_list() -> str:
|
|||||||
|
|
||||||
@app.get("/plugin/<name>")
|
@app.get("/plugin/<name>")
|
||||||
async def plugin(name: str) -> Response:
|
async def plugin(name: str) -> Response:
|
||||||
# TODO check that plugin exists
|
index_entry = tutorclient.Client.plugin_in_store(name)
|
||||||
|
if not index_entry:
|
||||||
|
return Response("Plugin not found", status=404)
|
||||||
|
|
||||||
seq_command_executed = request.args.get("seq_command_executed")
|
seq_command_executed = request.args.get("seq_command_executed")
|
||||||
author = next(
|
author = index_entry.author.split("<")[0].strip()
|
||||||
(
|
description = markdown(index_entry.description)
|
||||||
p.author.split("<")[0].strip()
|
|
||||||
for p in tutorclient.Client.plugins_in_store()
|
|
||||||
if p.name == name
|
|
||||||
),
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
description = next(
|
|
||||||
(
|
|
||||||
markdown(p.description)
|
|
||||||
for p in tutorclient.Client.plugins_in_store()
|
|
||||||
if p.name == name
|
|
||||||
),
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
rendered_template = await render_template(
|
rendered_template = await render_template(
|
||||||
"plugin.html",
|
"plugin.html",
|
||||||
plugin_name=name,
|
plugin_name=name,
|
||||||
|
|||||||
@ -302,6 +302,13 @@ class CliPool:
|
|||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
@classmethod
|
||||||
|
def plugin_in_store(cls, name: str) -> tutor.plugins.indexes.IndexEntry | None:
|
||||||
|
for plugin in cls.plugins_in_store():
|
||||||
|
if plugin.name == name:
|
||||||
|
return plugin
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def plugins_in_store(cls) -> list[tutor.plugins.indexes.IndexEntry]:
|
def plugins_in_store(cls) -> list[tutor.plugins.indexes.IndexEntry]:
|
||||||
if not os.path.exists(tutor.plugins.indexes.Indexes.CACHE_PATH):
|
if not os.path.exists(tutor.plugins.indexes.Indexes.CACHE_PATH):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user