2020-04-16 17:07:53 +02:00
|
|
|
from flask import g, abort, render_template
|
2020-05-03 15:57:05 +02:00
|
|
|
from http import HTTPStatus
|
2020-01-31 21:07:05 +01:00
|
|
|
|
2020-04-16 17:07:53 +02:00
|
|
|
from lnbits.decorators import check_user_exists, validate_uuids
|
2020-01-31 21:07:05 +01:00
|
|
|
|
|
|
|
from lnbits.extensions.withdraw import withdraw_ext
|
2020-07-20 22:03:23 +02:00
|
|
|
from .crud import get_withdraw_link, chunks
|
2020-01-31 21:07:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
@withdraw_ext.route("/")
|
2020-04-16 17:07:53 +02:00
|
|
|
@validate_uuids(["usr"], required=True)
|
|
|
|
@check_user_exists()
|
2020-01-31 21:07:05 +01:00
|
|
|
def index():
|
2020-04-16 17:07:53 +02:00
|
|
|
return render_template("withdraw/index.html", user=g.user)
|
2020-01-31 21:07:05 +01:00
|
|
|
|
|
|
|
|
2020-04-16 17:07:53 +02:00
|
|
|
@withdraw_ext.route("/<link_id>")
|
|
|
|
def display(link_id):
|
2020-05-03 15:57:05 +02:00
|
|
|
link = get_withdraw_link(link_id) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
2020-07-20 22:03:23 +02:00
|
|
|
link = get_withdraw_link(link_id, len(link.usescsv.split(","))) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
2020-01-31 21:07:05 +01:00
|
|
|
|
2020-04-16 17:07:53 +02:00
|
|
|
return render_template("withdraw/display.html", link=link)
|
2020-01-31 21:07:05 +01:00
|
|
|
|
|
|
|
|
2020-04-16 17:07:53 +02:00
|
|
|
@withdraw_ext.route("/print/<link_id>")
|
|
|
|
def print_qr(link_id):
|
2020-05-03 15:57:05 +02:00
|
|
|
link = get_withdraw_link(link_id) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
2020-07-20 22:03:23 +02:00
|
|
|
if link.uses == 0:
|
|
|
|
return render_template("withdraw/print_qr.html", link=link, unique=False)
|
|
|
|
links = []
|
|
|
|
for x in link.usescsv.split(","):
|
|
|
|
linkk = get_withdraw_link(link_id, x) or abort(HTTPStatus.NOT_FOUND, "Withdraw link does not exist.")
|
|
|
|
links.append(linkk)
|
|
|
|
page_link = list(chunks(links, 4))
|
|
|
|
linked = list(chunks(page_link, 8))
|
|
|
|
return render_template("withdraw/print_qr.html", link=linked, unique=True)
|