-
Notifications
You must be signed in to change notification settings - Fork 4
/
views.py
37 lines (27 loc) · 1.11 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from http import HTTPStatus
from fastapi import APIRouter, Depends, Request
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
from lnbits.helpers import template_renderer
from starlette.exceptions import HTTPException
from .crud import get_tipjar
tipjar_generic_router = APIRouter()
def tipjar_renderer():
return template_renderer(["tipjar/templates"])
@tipjar_generic_router.get("/")
async def index(request: Request, user: User = Depends(check_user_exists)):
return tipjar_renderer().TemplateResponse(
"tipjar/index.html", {"request": request, "user": user.json()}
)
@tipjar_generic_router.get("/{tipjar_id}")
async def tip(request: Request, tipjar_id: str):
"""Return the donation form for the Tipjar corresponding to id"""
tipjar = await get_tipjar(tipjar_id)
if not tipjar:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TipJar does not exist."
)
return tipjar_renderer().TemplateResponse(
"tipjar/display.html",
{"request": request, "donatee": tipjar.name, "tipjar_id": tipjar.id},
)