Changeset - 8605b0c3c489
[Not reviewed]
default
0 1 0
Dennis Fink - 3 years ago 2022-01-19 20:43:40
dennis.fink@c3l.lu
Set voting flag with ternary expression
1 file changed with 1 insertions and 5 deletions:
0 comments (0 inline, 0 general)
c3l_membership/views.py
Show inline comments
 
@@ -44,79 +44,75 @@ def index():
 
                (
 
                    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.membership.data == "supporting":
 
            xml_data["voting"] = 0
 
        elif form.membership.data == "regular":
 
            xml_data["voting"] = 1
 

	
 
        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"]:
 

	
 
            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)
0 comments (0 inline, 0 general)