Compare commits

...

3 commits

Author SHA1 Message Date
e74fd6b9ba Format code with black 2024-02-21 18:11:03 -05:00
5c6862180b Trigger reload on openapi schema change 2024-02-21 18:09:48 -05:00
7f9e19a74f Add autoreload option 2024-02-21 18:08:46 -05:00
2 changed files with 14 additions and 10 deletions

View file

@ -55,14 +55,16 @@ def main(ctx, database, log_level):
@click.option("--scheme", envvar="TUTOR_SCHEME")
@click.option("--static", envvar="TUTOR_STATIC", type=click.Path(file_okay=False))
@click.option("--debug", is_flag=True)
@click.option("--reload", is_flag=True)
@click.pass_context
def server(ctx, port, scheme, static, debug):
def server(ctx, port, scheme, static, debug, reload):
app = tutor.server.Application(
**{
**ctx.obj,
"scheme": scheme,
"static": static,
"debug": debug,
"autoreload": reload,
}
)
app.listen(port)
@ -70,8 +72,7 @@ def server(ctx, port, scheme, static, debug):
@main.group("import")
def import_group():
...
def import_group(): ...
@import_group.command("cards")

View file

@ -218,9 +218,9 @@ class SearchHandler(RequestHandler):
limit=limit + 1,
offset=limit * (page - 1),
sort_by=sort_by,
in_collection=in_collection in ("yes", "true")
if in_collection
else None,
in_collection=(
in_collection in ("yes", "true") if in_collection else None
),
)
has_more = copies and len(copies) > limit
self.set_header("Content-Type", "application/json")
@ -419,10 +419,13 @@ class StaticFileHandler(tornado.web.StaticFileHandler):
class Application(tornado.web.Application):
def __init__(self, **settings):
version = importlib.metadata.version(__package__)
settings.setdefault(
"template_path",
importlib.resources.files(__package__) / "templates",
)
template_path = importlib.resources.files(__package__) / "templates"
settings["template_path"] = str(template_path)
if settings.get("autoreload"):
import tornado.autoreload
tornado.autoreload.watch(str(template_path / "openapi.yaml"))
paths = [
(