add stall page

This commit is contained in:
Tiago vasconcelos
2022-07-19 10:13:06 +01:00
parent b79fb373a8
commit f7f442c9d7
3 changed files with 152 additions and 14 deletions
+9 -9
View File
@@ -3,14 +3,13 @@ from http import HTTPStatus
from fastapi import Request
from fastapi.params import Depends
from fastapi.templating import Jinja2Templates
from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from lnbits.core.models import User
from lnbits.decorators import check_user_exists # type: ignore
from lnbits.extensions.diagonalley import diagonalley_ext, diagonalley_renderer
from starlette.exceptions import HTTPException
from starlette.responses import HTMLResponse
from .crud import get_diagonalley_products
from .crud import get_diagonalley_products, get_diagonalley_stall
templates = Jinja2Templates(directory="templates")
@@ -24,17 +23,18 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
@diagonalley_ext.get("/{stall_id}", response_class=HTMLResponse)
async def display(request: Request, stall_id):
product = await get_diagonalley_products(stall_id)
stall = await get_diagonalley_stall(stall_id)
products = await get_diagonalley_products(stall_id)
if not product:
if not stall:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Stall does not exist."
)
return diagonalley_renderer().TemplateResponse(
"diagonalley/stall.html",
{
"stall": [
product.dict() for product in await get_diagonalley_products(stall_id)
]
"request": request,
"stall": stall.dict(),
"products": [product.dict() for product in products]
},
)