Merge pull request #310 from arcbtc/FastAPI

Converted views
This commit is contained in:
Arc 2021-08-21 02:08:30 +01:00 committed by GitHub
commit 266e220f94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View File

@ -12,4 +12,4 @@ templates = Jinja2Templates(directory="templates")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index(request: Request):
return await render_template("usermanager/index.html", {"request":request,"user":g.user})
return await templates.TemplateResponse("usermanager/index.html", {"request":request,"user":g.user})

View File

@ -13,5 +13,5 @@ templates = Jinja2Templates(directory="templates")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index(request: Request):
return await render_template("watchonly/index.html", {"request":request,"user":g.user})
return await templates.TemplateResponse("watchonly/index.html", {"request":request,"user":g.user})

View File

@ -6,25 +6,28 @@ from lnbits.decorators import check_user_exists, validate_uuids
from . import withdraw_ext
from .crud import get_withdraw_link, chunks
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@withdraw_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("withdraw/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("withdraw/index.html", {"request":request,"user":g.user})
@withdraw_ext.get("/<link_id>")
async def display(link_id):
async def display(request: Request, link_id):
link = await get_withdraw_link(link_id, 0) or abort(
HTTPStatus.NOT_FOUND, "Withdraw link does not exist."
)
return await render_template("withdraw/display.html", link=link, unique=True)
return await templates.TemplateResponse("withdraw/display.html", {"request":request,"link":link, "unique":True})
@withdraw_ext.get("/img/<link_id>")
async def img(link_id):
async def img(request: Request, link_id):
link = await get_withdraw_link(link_id, 0) or abort(
HTTPStatus.NOT_FOUND, "Withdraw link does not exist."
)
@ -44,12 +47,12 @@ async def img(link_id):
@withdraw_ext.get("/print/<link_id>")
async def print_qr(link_id):
async def print_qr(request: Request, link_id):
link = await get_withdraw_link(link_id) or abort(
HTTPStatus.NOT_FOUND, "Withdraw link does not exist."
)
if link.uses == 0:
return await render_template("withdraw/print_qr.html", link=link, unique=False)
return await templates.TemplateResponse("withdraw/print_qr.html", {"request":request,link:link, unique:False})
links = []
count = 0
for x in link.usescsv.split(","):
@ -60,4 +63,4 @@ async def print_qr(link_id):
count = count + 1
page_link = list(chunks(links, 2))
linked = list(chunks(page_link, 5))
return await render_template("withdraw/print_qr.html", link=linked, unique=True)
return await templates.TemplateResponse("withdraw/print_qr.html", {"request":request,"link":linked, "unique":True})