Converted views

This commit is contained in:
Ben Arc 2021-08-21 01:55:07 +01:00
parent d3d24abb17
commit bbdb96f4ac
21 changed files with 177 additions and 112 deletions

View file

@ -25,7 +25,10 @@ from ..crud import (
save_balance_notify,
)
from ..services import redeem_lnurl_withdraw, pay_invoice
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@core_app.get("/favicon.ico")
async def favicon():
@ -35,10 +38,8 @@ async def favicon():
@core_app.get("/")
async def home():
return await render_template(
"core/index.html", lnurl=request.args.get("lightning", None)
)
async def home(request: Request, lightning: str = None):
return templates.TemplateResponse("core/index.html", {"request": request, "lnurl": lightning})
@core_app.get("/extensions")
@ -61,8 +62,7 @@ async def extensions():
await update_user_extension(
user_id=g.user.id, extension=extension_to_disable, active=False
)
return await render_template("core/extensions.html", user=await get_user(g.user.id))
return await templates.TemplateResponse("core/extensions.html", {"request": request, "user": get_user(g.user.id)})
@core_app.get("/wallet")

View file

@ -6,17 +6,18 @@ from . import bleskomat_ext
from .exchange_rates import exchange_rate_providers_serializable, fiat_currencies
from .helpers import get_callback_url
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@bleskomat_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
async def index(request: Request):
bleskomat_vars = {
"callback_url": get_callback_url(),
"exchange_rate_providers": exchange_rate_providers_serializable,
"fiat_currencies": fiat_currencies,
}
return await render_template(
"bleskomat/index.html", user=g.user, bleskomat_vars=bleskomat_vars
)
return await templates.TemplateResponse("bleskomat/index.html", {"request": request, "user":g.user, "bleskomat_vars":bleskomat_vars})

View file

@ -10,23 +10,24 @@ from functools import wraps
import trio
import shortuuid
from . import copilot_ext
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@copilot_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("copilot/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("copilot/index.html", {"request": request, "user":g.user})
@copilot_ext.route("/cp/")
async def compose():
return await render_template("copilot/compose.html")
async def compose(request: Request):
return await templates.TemplateResponse("copilot/compose.html", {"request": request})
@copilot_ext.route("/pn/")
async def panel():
return await render_template("copilot/panel.html")
async def panel(request: Request):
return await templates.TemplateResponse("copilot/panel.html", {"request": request})
##################WEBSOCKET ROUTES########################

View file

@ -6,46 +6,51 @@ from lnbits.decorators import check_user_exists, validate_uuids
from . import events_ext
from .crud import get_ticket, get_event
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@events_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("events/index.html", user=g.user)
async def index(request: Request):
return templates.TemplateResponse("events/index.html", {"user":g.user})
@events_ext.route("/<event_id>")
async def display(event_id):
async def display(request: Request, event_id):
event = await get_event(event_id)
if not event:
abort(HTTPStatus.NOT_FOUND, "Event does not exist.")
if event.amount_tickets < 1:
return await render_template(
return await templates.TemplateResponse(
"events/error.html",
event_name=event.name,
event_error="Sorry, tickets are sold out :(",
{"request":request,
"event_name":event.name,
"event_error":"Sorry, tickets are sold out :("}
)
datetime_object = datetime.strptime(event.closing_date, "%Y-%m-%d").date()
if date.today() > datetime_object:
return await render_template(
return await templates.TemplateResponse(
"events/error.html",
event_name=event.name,
event_error="Sorry, ticket closing date has passed :(",
{"request":request,
"event_name":event.name,
"event_error":"Sorry, ticket closing date has passed :("}
)
return await render_template(
return await templates.TemplateResponse(
"events/display.html",
event_id=event_id,
event_name=event.name,
event_info=event.info,
event_price=event.price_per_ticket,
{"request":request,
"event_id":event_id,
"event_name":event.name,
"event_info":event.info,
"event_price":event.price_per_ticket}
)
@events_ext.route("/ticket/<ticket_id>")
async def ticket(ticket_id):
async def ticket(request: Request, ticket_id):
ticket = await get_ticket(ticket_id)
if not ticket:
abort(HTTPStatus.NOT_FOUND, "Ticket does not exist.")
@ -54,23 +59,25 @@ async def ticket(ticket_id):
if not event:
abort(HTTPStatus.NOT_FOUND, "Event does not exist.")
return await render_template(
return await templates.TemplateResponse(
"events/ticket.html",
ticket_id=ticket_id,
ticket_name=event.name,
ticket_info=event.info,
{"request":request,
"ticket_id":ticket_id,
"ticket_name":event.name,
"ticket_info":event.info}
)
@events_ext.route("/register/<event_id>")
async def register(event_id):
async def register(request: Request, event_id):
event = await get_event(event_id)
if not event:
abort(HTTPStatus.NOT_FOUND, "Event does not exist.")
return await render_template(
return await templates.TemplateResponse(
"events/register.html",
event_id=event_id,
event_name=event.name,
wallet_id=event.wallet,
{"request":request,
"event_id":event_id,
"event_name":event.name,
"wallet_id":event.wallet}
)

View file

@ -1,12 +1,16 @@
from quart import g, render_template
from lnbits.decorators import check_user_exists, validate_uuids
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
from . import example_ext
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@example_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("example/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("example/index.html", {"request": request, "user":g.user})

View file

@ -3,10 +3,13 @@ from quart import g, render_template
from lnbits.decorators import check_user_exists, validate_uuids
from . import hivemind_ext
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@hivemind_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("hivemind/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("hivemind/index.html", {"request": request, "user":g.user})

View file

@ -10,17 +10,20 @@ import json
from . import jukebox_ext
from .crud import get_jukebox
from .views_api import api_get_jukebox_device_check
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@jukebox_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("jukebox/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("jukebox/index.html", {"request": request,"user":g.user})
@jukebox_ext.get("/<juke_id>")
async def connect_to_jukebox(juke_id):
async def connect_to_jukebox(request: Request, juke_id):
jukebox = await get_jukebox(juke_id)
if not jukebox:
return "error"
@ -31,7 +34,7 @@ async def connect_to_jukebox(juke_id):
if device["id"] == jukebox.sp_device.split("-")[1]:
deviceConnected = True
if deviceConnected:
return await render_template(
return await templates.TemplateResponse(
"jukebox/jukebox.html",
playlists=jukebox.sp_playlists.split(","),
juke_id=juke_id,
@ -39,4 +42,4 @@ async def connect_to_jukebox(juke_id):
inkey=jukebox.inkey,
)
else:
return await render_template("jukebox/error.html")
return await templates.TemplateResponse("jukebox/error.html",{"request": request})

View file

@ -7,13 +7,16 @@ from lnbits.core.crud import get_wallet_payment
from . import livestream_ext
from .crud import get_track, get_livestream_by_track
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@livestream_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("livestream/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("livestream/index.html", {"request": request,"user":g.user})
@livestream_ext.route("/track/<track_id>")

View file

@ -2,10 +2,13 @@ from quart import render_template, g
from lnbits.decorators import check_user_exists, validate_uuids
from . import lndhub_ext
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@lndhub_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def lndhub_index():
return await render_template("lndhub/index.html", user=g.user)
async def lndhub_index(request: Request):
return await templates.TemplateResponse("lndhub/index.html", {"request": request,"user":g.user})

View file

@ -6,29 +6,33 @@ from http import HTTPStatus
from . import lnticket_ext
from .crud import get_form
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@lnticket_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("lnticket/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("lnticket/index.html", {"request": request,"user":g.user})
@lnticket_ext.route("/<form_id>")
async def display(form_id):
async def display(request: Request, form_id):
form = await get_form(form_id)
if not form:
abort(HTTPStatus.NOT_FOUND, "LNTicket does not exist.")
wallet = await get_wallet(form.wallet)
return await render_template(
return await templates.TemplateResponse(
"lnticket/display.html",
form_id=form.id,
form_name=form.name,
form_desc=form.description,
form_amount=form.amount,
form_flatrate=form.flatrate,
form_wallet=wallet.inkey,
{"request": request,
"form_id":form.id,
"form_name":form.name,
"form_desc":form.description,
"form_amount":form.amount,
"form_flatrate":form.flatrate,
"form_wallet":wallet.inkey}
)

View file

@ -5,28 +5,31 @@ from lnbits.decorators import check_user_exists, validate_uuids
from . import lnurlp_ext
from .crud import get_pay_link
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@lnurlp_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("lnurlp/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("lnurlp/index.html", {"request": request, "user":g.user})
@lnurlp_ext.route("/<link_id>")
async def display(link_id):
async def display(request: Request,link_id):
link = await get_pay_link(link_id)
if not link:
abort(HTTPStatus.NOT_FOUND, "Pay link does not exist.")
return await render_template("lnurlp/display.html", link=link)
return await templates.TemplateResponse("lnurlp/display.html", {"request": request, "link":link})
@lnurlp_ext.route("/print/<link_id>")
async def print_qr(link_id):
async def print_qr(request: Request,link_id):
link = await get_pay_link(link_id)
if not link:
abort(HTTPStatus.NOT_FOUND, "Pay link does not exist.")
return await render_template("lnurlp/print_qr.html", link=link)
return await templates.TemplateResponse("lnurlp/print_qr.html", {"request": request, "link":link})

View file

@ -5,7 +5,10 @@ from lnbits.decorators import check_user_exists, validate_uuids
from pyngrok import conf, ngrok
from . import ngrok_ext
from os import getenv
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
def log_event_callback(log):
string = str(log)
@ -26,5 +29,5 @@ ngrok_tunnel = ngrok.connect(port)
@ngrok_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("ngrok/index.html", ngrok=string5, user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("ngrok/index.html", {"request": request, "ngrok":string5, "user":g.user})

View file

@ -9,17 +9,20 @@ from lnbits.core.crud import get_standalone_payment
from . import offlineshop_ext
from .crud import get_item, get_shop
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@offlineshop_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("offlineshop/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("offlineshop/index.html", {"request": request,"user":g.user})
@offlineshop_ext.get("/print")
async def print_qr_codes():
async def print_qr_codes(request: Request):
items = []
for item_id in request.args.get("items").split(","):
item = await get_item(item_id)
@ -32,7 +35,7 @@ async def print_qr_codes():
}
)
return await render_template("offlineshop/print.html", items=items)
return await templates.TemplateResponse("offlineshop/print.html", {"request": request,"items":items})
@offlineshop_ext.get("/confirmation")

View file

@ -5,18 +5,21 @@ from lnbits.decorators import check_user_exists, validate_uuids
from . import paywall_ext
from .crud import get_paywall
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@paywall_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("paywall/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("paywall/index.html", {"request": request,"user":g.user})
@paywall_ext.route("/<paywall_id>")
async def display(paywall_id):
async def display(request: Request, paywall_id):
paywall = await get_paywall(paywall_id) or abort(
HTTPStatus.NOT_FOUND, "Paywall does not exist."
)
return await render_template("paywall/display.html", paywall=paywall)
return await templates.TemplateResponse("paywall/display.html", {"request": request,"paywall":paywall})

View file

@ -6,17 +6,21 @@ from lnbits.decorators import check_user_exists, validate_uuids
from . import satspay_ext
from .crud import get_charge
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@satspay_ext.route("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("satspay/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("satspay/index.html", {"request":request, "user":g.user})
@satspay_ext.route("/<charge_id>")
async def display(charge_id):
async def display(request: Request, charge_id):
charge = await get_charge(charge_id) or abort(
HTTPStatus.NOT_FOUND, "Charge link does not exist."
)
return await render_template("satspay/display.html", charge=charge)
return await templates.TemplateResponse("satspay/display.html", {"request":request, "charge":charge})

View file

@ -3,10 +3,13 @@ from quart import g, render_template
from lnbits.decorators import check_user_exists, validate_uuids
from . import splitpayments_ext
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@splitpayments_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("splitpayments/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("splitpayments/index.html", {"request":request, "user":g.user})

View file

@ -5,24 +5,28 @@ from http import HTTPStatus
from . import streamalerts_ext
from .crud import get_service
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@streamalerts_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
async def index(request: Request):
"""Return the extension's settings page"""
return await render_template("streamalerts/index.html", user=g.user)
return await templates.TemplateResponse("streamalerts/index.html", {"request":request, "user":g.user})
@streamalerts_ext.get("/<state>")
async def donation(state):
async def donation(request: Request, state):
"""Return the donation form for the Service corresponding to state"""
service = await get_service(0, by_state=state)
if not service:
abort(HTTPStatus.NOT_FOUND, "Service does not exist.")
return await render_template(
return await templates.TemplateResponse(
"streamalerts/display.html",
twitchuser=service.twitchuser,
service=service.id
{"request":request,
"twitchuser":service.twitchuser,
"service":service.id}
)

View file

@ -5,17 +5,20 @@ from http import HTTPStatus
from . import subdomains_ext
from .crud import get_domain
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@subdomains_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("subdomains/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("subdomains/index.html", {"request":request,"user":g.user})
@subdomains_ext.get("/<domain_id>")
async def display(domain_id):
async def display(request: Request, domain_id):
domain = await get_domain(domain_id)
if not domain:
abort(HTTPStatus.NOT_FOUND, "Domain does not exist.")
@ -23,11 +26,12 @@ async def display(domain_id):
domain.allowed_record_types.replace('"', "").replace(" ", "").split(",")
)
print(allowed_records)
return await render_template(
return await templates.TemplateResponse(
"subdomains/display.html",
domain_id=domain.id,
domain_domain=domain.domain,
domain_desc=domain.description,
domain_cost=domain.cost,
domain_allowed_record_types=allowed_records,
{"request":request,
"domain_id":domain.id,
"domain_domain":domain.domain,
"domain_desc":domain.description,
"domain_cost":domain.cost,
"domain_allowed_record_types":allowed_records}
)

View file

@ -5,19 +5,22 @@ from lnbits.decorators import check_user_exists, validate_uuids
from . import tpos_ext
from .crud import get_tpos
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@tpos_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("tpos/index.html", user=g.user)
async def index(request: Request):
return await templates.TemplateResponse("tpos/index.html", {"request":request,"user":g.user})
@tpos_ext.get("/{tpos_id}")
async def tpos(tpos_id):
async def tpos(request: Request, tpos_id):
tpos = await get_tpos(tpos_id)
if not tpos:
abort(HTTPStatus.NOT_FOUND, "TPoS does not exist.")
return await render_template("tpos/tpos.html", tpos=tpos)
return await templates.TemplateResponse("tpos/tpos.html", {"request":request,"tpos":tpos})

View file

@ -3,10 +3,13 @@ from quart import g, render_template
from lnbits.decorators import check_user_exists, validate_uuids
from . import usermanager_ext
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@usermanager_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("usermanager/index.html", user=g.user)
async def index(request: Request):
return await render_template("usermanager/index.html", {"request":request,"user":g.user})

View file

@ -4,11 +4,14 @@ from http import HTTPStatus
from lnbits.decorators import check_user_exists, validate_uuids
from . import watchonly_ext
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@watchonly_ext.get("/")
@validate_uuids(["usr"], required=True)
@check_user_exists()
async def index():
return await render_template("watchonly/index.html", user=g.user)
async def index(request: Request):
return await render_template("watchonly/index.html", {"request":request,"user":g.user})