Files
@ 98707c4bed4b
Branch filter:
Location: C3L/C3L-Membership-Online-Form/c3l_membership/views.py - annotation
98707c4bed4b
2.7 KiB
text/x-python
Update dependecies
587a9a50643f 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 587a9a50643f 587a9a50643f 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 587a9a50643f 587a9a50643f 52127f437376 52127f437376 52127f437376 52127f437376 52127f437376 52127f437376 587a9a50643f 52127f437376 52127f437376 587a9a50643f 6f06fc328a13 52127f437376 6f06fc328a13 6f06fc328a13 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 6f06fc328a13 6f06fc328a13 6f06fc328a13 587a9a50643f 587a9a50643f 587a9a50643f 6f06fc328a13 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 6f06fc328a13 6f06fc328a13 | import re
import subprocess
from datetime import date
from flask import Blueprint, current_app, render_template, request
from flask_weasyprint import HTML, render_pdf
from .forms import MembershipForm
root_page = Blueprint("root", __name__)
xml_template = "<member><numm>{name}</numm><gebuertsdag>{birthday:%d.%m.%Y}</gebuertsdag><address>{address}</address><nick>{username}</nick><email>{email}</email><status>{status}</status><stemmrecht>{voting}</stemmrecht></member>"
@root_page.route("/", methods=("GET", "POST"))
def index():
form = MembershipForm()
if form.validate_on_submit():
xml_data = {}
if (
form.minor_member.data
or form.student.data
or form.membership.data == "supporting"
):
price = 40
xml_data["voting"] = 0
elif form.membership.data == "regular":
price = 120
xml_data["voting"] = 1
if form.starving.data:
price = 1
if form.starving.data:
xml_data["status"] = "Starving"
elif form.minor_member.data or form.student.data:
xml_data["status"] = "Student"
elif form.membership.data == "supporting":
xml_data["status"] = "Supporter"
else:
xml_data["status"] = "Regular"
xml_data["name"] = form.fullname.data
xml_data["birthday"] = form.birthday.data
xml_data["username"] = form.username.data
xml_data["email"] = form.email.data
xml_data["address"] = " ".join(
(
form.street.data,
form.zip.data,
form.city.data,
form.state.data,
form.country.data,
)
)
xml_data["address"] = re.sub("\s+", " ", xml_data["address"])
if form.payment.data == "bitcoin":
price = subprocess.check_output(
["/usr/local/share/btc/BTC_Membership.pl", str(price)]
).decode("utf-8")
elif form.payment.data == "ethereum":
price = subprocess.check_output(
["/usr/local/share/eth/ETH_Membership.pl", str(price)]
).decode("utf-8")
elif form.payment.data == "monero":
price = subprocess.check_output(
["/usr/local/share/xmr/XMR_Membership.pl", str(price)]
).decode("utf-8")
elif form.payment.data == "digicash":
price = price * 100
now = date.today()
year = now.year
xml_data["date"] = now
xml = xml_template.format(**xml_data)
html = render_template(
"member.html", form=form, price=price, year=year, xml=xml
)
return render_pdf(HTML(string=html))
return render_template("index.html", form=form)
|