Changeset - 53bbd1295ee2
[Not reviewed]
default
0 2 0
Dennis Fink - 3 years ago 2022-01-19 20:50:54
dennis.fink@c3l.lu
Show an error message to the user, if we fail fetching conversion rates for the cryptocurrencies
2 files changed with 7 insertions and 5 deletions:
0 comments (0 inline, 0 general)
c3l_membership/templates/index.html
Show inline comments
 
@@ -38,24 +38,27 @@
 
      <div class="pure-u-1-1 pure-u-md-1-3">
 
        <img src="{{ url_for('static', filename='images/logo.png') }}" class="pure-img" />
 
        <h1>{% trans %}Membership Application{% endtrans %}</h1>
 
        <h2>{% trans %}How to use this form{% endtrans %}</h2>
 
        <p>{% trans %}Fill out this form and click on "Become a member". Afterwards you will be presented with a PDF, which you have to send to info@c3l.lu or bring it to one of our next events. Print it or save it to your local hardware, because we don't save a copy on our servers for data protection reasons!{% endtrans %}</p>
 
        {% if form.errors %}
 
          {% for fieldname, errors in form.errors.items() %}
 
            {% for error in errors %}
 
              <p class="form-error">{{ fieldname }} - {{ error }}</p>
 
            {% endfor %}
 
          {% endfor %}
 
        {% endif %}
 
        {% if crypto_error %}
 
          <p class="form-error">{% trans %}Couldn't fetch conversion rate for cryptocurrencies. Please try again later or use another payment option!{% endtrans %}</p>
 
        {% endif %}
 
        <form class="pure-form pure-form-stacked" method="POST" action="{{ url_for('root.index', lang_code=g.lang_code) }}">
 
          <fieldset>
 
            {{ form.hidden_tag() }}
 
            <legend>{% trans %}Required information{% endtrans %}</legend>
 
            <div class="pure-g">
 
              <div class="pure-u-1-1">
 
                <b>{{ form.username.label }}</b>
 
                {{ form.username(required=True, class="pure-u-1-1 field-error" if form.username.errors else "pure-u-1-1") }}
 
              </div>
 
            </div>
 
            <div class="pure-g">
 
              <div class="pure-u-1-1">
c3l_membership/views.py
Show inline comments
 
@@ -49,25 +49,24 @@ def index():
 

	
 
    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"
 
@@ -85,39 +84,39 @@ def index():
 
            (
 
                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
 
            )
 
            try:
 
                current_conversion_r.raise_for_status()
 
            except:
 
                return 500
 
                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 = 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)
 

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