Files
@ b314c40f5920
Branch filter:
Location: C3L/C3L-Membership-Online-Form/c3l_membership/views.py - annotation
b314c40f5920
3.9 KiB
text/x-python
Fix xml_data voting flag
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | 587a9a50643f 6f06fc328a13 6f06fc328a13 6f06fc328a13 ade19bdcb84a 4005eddcc559 805cb46ada9a 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 4005eddcc559 6f06fc328a13 587a9a50643f 587a9a50643f 6f06fc328a13 4005eddcc559 4005eddcc559 4005eddcc559 4005eddcc559 4005eddcc559 4005eddcc559 4005eddcc559 8e2c954d832f 8e2c954d832f 8e2c954d832f 4005eddcc559 4005eddcc559 6f06fc328a13 6f06fc328a13 6f06fc328a13 7cf7d1e162a4 805cb46ada9a 805cb46ada9a 805cb46ada9a 805cb46ada9a 7cf7d1e162a4 10cfc4437178 10cfc4437178 10cfc4437178 10cfc4437178 10cfc4437178 10cfc4437178 10cfc4437178 10cfc4437178 ade19bdcb84a 10cfc4437178 10cfc4437178 10cfc4437178 7cf7d1e162a4 7cf7d1e162a4 6f06fc328a13 6f06fc328a13 587a9a50643f 587a9a50643f 52127f437376 52127f437376 52127f437376 52127f437376 52127f437376 b314c40f5920 7cf7d1e162a4 b314c40f5920 b314c40f5920 b314c40f5920 b314c40f5920 587a9a50643f 52127f437376 587a9a50643f 6f06fc328a13 52127f437376 6f06fc328a13 ade19bdcb84a 587a9a50643f ade19bdcb84a 587a9a50643f ade19bdcb84a 587a9a50643f ade19bdcb84a 587a9a50643f ade19bdcb84a 587a9a50643f 3e495ae230a2 3e495ae230a2 3e495ae230a2 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 10cfc4437178 ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a ade19bdcb84a 6f06fc328a13 6f06fc328a13 6f06fc328a13 587a9a50643f 587a9a50643f 587a9a50643f 6f06fc328a13 587a9a50643f 587a9a50643f 587a9a50643f 587a9a50643f 6f06fc328a13 6f06fc328a13 | import re
import subprocess
from datetime import date
import requests
from flask import Blueprint, current_app, g, render_template, request
from flask_babel import gettext
from flask_weasyprint import HTML, render_pdf
from .forms import MembershipForm
root_page = Blueprint("root", __name__, url_prefix="/<lang_code>")
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.url_defaults
def add_lang_code(endpoint, values):
values.setdefault("lang_code", g.lang_code)
@root_page.url_value_preprocessor
def pull_lang_code(endpoint, values):
lang_code = values.pop("lang_code")
if lang_code != "favicon.ico":
g.lang_code = lang_code
@root_page.route("/", methods=("GET", "POST"))
def index():
form = MembershipForm()
choices = [
("cash", gettext("by cash")),
("wire transfer", gettext("by wire transfer")),
]
if current_app.config["DIGICASH_ENABLED"]:
choices.append(("digicash", gettext("by DigiCash")))
for cryptocurrency_label, options in current_app.config["CRYPTOCURRENCIES"].items():
if options["ENABLED"]:
choices.append(
(
cryptocurrency_label,
" ".join((gettext("by"), cryptocurrency_label.title())),
),
)
form.payment.choices = choices
if form.validate_on_submit():
xml_data = {}
if (
form.minor_member.data
or form.student.data
or form.membership.data == "supporting"
):
price = current_app.config["SUPPORTING_FEE"]
else:
price = current_app.config["REGULAR_FEE"]
if form.membership.data == "supporting":
xml_data["voting"] = 0
elif form.membership.data == "regular":
xml_data["voting"] = 1
if form.starving.data:
price = 1
status = "Starving"
elif form.minor_member.data or form.student.data:
status = "Student"
elif form.membership.data == "supporting":
status = "Supporter"
else:
status = "Regular"
xml_data["status"] = status
xml_data["name"] = form.fullname.data
xml_data["birthday"] = (
form.birthday.data if form.birthday.data is not None else date(9999, 12, 12)
)
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 in current_app.config["CRYPTOCURRENCIES"]:
current_conversion_r = requests.get(
current_app.config["CONVERSION_URL"], timeout=30
)
try:
current_conversion_r.raise_for_status()
except:
return 500
else:
current_conversion = current_conversion_r.json()
commodity = current_app.config["CRYPTOCURRENCIES"][form.payment.data][
"COMMODITY"
]
price = current_conversion[commodity][status.upper()]
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)
|