include time restriction
All checks were successful
release-tag / release-image (push) Successful in 42s
All checks were successful
release-tag / release-image (push) Successful in 42s
This commit is contained in:
37
app/main.py
37
app/main.py
@@ -1,7 +1,10 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from app.api.main import api_router
|
||||
from app.core.config import settings
|
||||
|
||||
@@ -9,6 +12,8 @@ from app.core.db import init_db, engine
|
||||
|
||||
from sqlmodel import Session
|
||||
|
||||
from app.core.utils import is_registration_open
|
||||
|
||||
with Session(engine) as session:
|
||||
init_db(session)
|
||||
|
||||
@@ -16,10 +21,34 @@ app = FastAPI(
|
||||
title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json"
|
||||
)
|
||||
|
||||
@api_router.get("/")
|
||||
def index():
|
||||
return FileResponse("app/index.html")
|
||||
templates = Jinja2Templates(directory="app/templates")
|
||||
|
||||
@api_router.get("/")
|
||||
def index(request: Request):
|
||||
reg_open, not_before, not_after = is_registration_open()
|
||||
if reg_open:
|
||||
return templates.TemplateResponse(
|
||||
request=request, name="registration-open.html", context={}
|
||||
)
|
||||
else:
|
||||
return templates.TemplateResponse(
|
||||
request=request, name="registration-closed.html", context={
|
||||
"not_before": settings.NOT_BEFORE,
|
||||
"not_after": settings.NOT_AFTER,
|
||||
}
|
||||
)
|
||||
|
||||
@api_router.get("/success.html")
|
||||
def success(request: Request):
|
||||
return templates.TemplateResponse(
|
||||
request=request, name="registration-success.html", context={
|
||||
"not_before": settings.NOT_BEFORE,
|
||||
"not_after": settings.NOT_AFTER,
|
||||
}
|
||||
)
|
||||
|
||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||
|
||||
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user