Changeset - 81d8f0641a9c
[Not reviewed]
default
0 1 0
Dennis Fink - 3 years ago 2022-01-19 20:56:06
dennis.fink@c3l.lu
Reformat stuff
1 file changed with 26 insertions and 25 deletions:
0 comments (0 inline, 0 general)
c3l_membership/views.py
Show inline comments
 
@@ -42,81 +42,82 @@ def index():
 
        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"]
 
        elif form.starving.data:
 
            price = 1
 
        else:
 
            price = current_app.config["REGULAR_FEE"]
 

	
 
        if form.starving.data:
 
            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"])
 
        xml_data["voting"] = 1 if form.membership.data == "regular" else 0
 

	
 
        if form.payment.data in current_app.config["CRYPTOCURRENCIES"]:
 
            try:
 
                current_conversion_r = requests.get(
 
                    current_app.config["CONVERSION_URL"], timeout=30
 
                )
 
                current_conversion_r.raise_for_status()
 
            except:
 
                return render_template("index.html", form=form, crypto_error=True), 503
 
            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_data = {
 
            "status": status,
 
            "name": form.fullname.data,
 
            "birthday": form.birthday.data
 
            if form.birthday.data is not None
 
            else date(9999, 12, 12),
 
            "username": form.username.data,
 
            "email": form.email.data,
 
            "address": " ".join(
 
                (
 
                    form.street.data,
 
                    form.zip.data,
 
                    form.city.data,
 
                    form.state.data,
 
                    form.country.data,
 
                )
 
            ),
 
            "address": re.sub("\s+", " ", xml_data["address"]),
 
            "voting": 1 if form.membership.data == "regular" else 0,
 
            "date": now,
 
        }
 

	
 
        xml = xml_template.format(**xml_data)
 
        html = render_template(
 
            "member.html", form=form, price=price, year=year, xml=xml
 
            "member.html",
 
            form=form,
 
            price=price,
 
            year=now.year,
 
            xml=xml_template.format(**xml_data),
 
        )
 
        return render_pdf(HTML(string=html))
 

	
 
    return render_template("index.html", form=form, crypto_error=False)
0 comments (0 inline, 0 general)