Changeset - c4c5ab9a2bb8
[Not reviewed]
default
0 4 0
Dennis Fink - 3 years ago 2022-08-30 10:16:18
dennis.fink@c3l.lu
Rename zip to postal
4 files changed with 6 insertions and 6 deletions:
0 comments (0 inline, 0 general)
c3l_membership/forms.py
Show inline comments
 
from flask_babel import lazy_gettext
 
from flask_wtf import FlaskForm
 
from wtforms import (
 
    BooleanField,
 
    DateField,
 
    RadioField,
 
    StringField,
 
    SubmitField,
 
    ValidationError,
 
)
 
from wtforms.validators import Email, InputRequired, Length, Optional
 

	
 

	
 
class NotEqualTo:
 
    """
 
    Compares the values of two fields.
 
    :param fieldname:
 
        The name of the other field to compare to.
 
    :param message:
 
        Error message to raise in case of a validation error. Can be
 
        interpolated with `%(other_label)s` and `%(other_name)s` to provide a
 
        more helpful error.
 
    """
 

	
 
    def __init__(self, fieldname, message=None):
 
        self.fieldname = fieldname
 
        self.message = message
 

	
 
    def __call__(self, form, field):
 
        try:
 
            other = form[self.fieldname]
 
        except KeyError as exc:
 
            raise ValidationError(
 
                field.gettext("Invalid field name '%s'.") % self.fieldname
 
            ) from exc
 
        if field.data != other.data:
 
            return
 

	
 
        d = {
 
            "other_label": hasattr(other, "label")
 
            and other.label.text
 
            or self.fieldname,
 
            "other_name": self.fieldname,
 
        }
 
        message = self.message
 
        if message is None:
 
            message = field.gettext("Field must not be equal to %(other_name)s.")
 

	
 
        raise ValidationError(message % d)
 

	
 

	
 
class MembershipForm(FlaskForm):
 

	
 
    username = StringField(
 
        lazy_gettext("Username"),
 
        validators=[
 
            InputRequired(lazy_gettext("This field is required!")),
 
            Length(max=255),
 
        ],
 
    )
 

	
 
    email = StringField(
 
        lazy_gettext("E-Mail"),
 
        validators=[InputRequired(lazy_gettext("This field is required!")), Email()],
 
    )
 

	
 
    fullname = StringField(
 
        lazy_gettext("Full Name"),
 
        validators=[
 
            InputRequired(lazy_gettext("This field is required!")),
 
            Length(max=65536),
 
        ],
 
    )
 

	
 
    membership = RadioField(
 
        lazy_gettext("Membership Plan"),
 
        validators=[InputRequired(lazy_gettext("Please select one of the options!"))],
 
        choices=[
 
            (
 
                "regular",
 
                lazy_gettext(
 
                    "Regular membership - Membership with voting rights on the general assembly."
 
                ),
 
            ),
 
            (
 
                "supporting",
 
                lazy_gettext(
 
                    "Supporting membership - Membership without voting rights on the general assembly."
 
                ),
 
            ),
 
        ],
 
    )
 

	
 
    student = BooleanField(
 
        lazy_gettext(
 
            "I am a student and would like to have the reduced membership fees."
 
        ),
 
        validators=[
 
            Optional(),
 
            NotEqualTo(
 
                "starving",
 
                lazy_gettext(
 
                    "Student and Starving Hacker are mutually exclusive! Please select only one of them."
 
                ),
 
            ),
 
        ],
 
    )
 

	
 
    starving = BooleanField(
 
        lazy_gettext(
 
            "I am a starving hacker and cannot afford the membership! (Please get in touch with us at info@c3l.lu before filling out this membership form)"
 
        )
 
    )
 

	
 
    payment = RadioField(
 
        lazy_gettext("Payment Options"),
 
        validators=[InputRequired(lazy_gettext("Please select one of the options!"))],
 
    )
 

	
 
    birthday = DateField(lazy_gettext("Birthday"), validators=[InputRequired()])
 

	
 
    street = StringField(
 
        lazy_gettext("Nr., Street"),
 
        validators=[Optional(), Length(max=4000)],
 
    )
 

	
 
    zip = StringField(
 
    postal = StringField(
 
        lazy_gettext("Postal Code"),
 
        validators=[Optional(), Length(max=30)],
 
    )
 

	
 
    city = StringField(
 
        lazy_gettext("City/Town"),
 
        validators=[Optional(), Length(max=500)],
 
    )
 

	
 
    state = StringField(
 
        lazy_gettext("State/County/Province"),
 
        validators=[Optional(), Length(max=500)],
 
    )
 

	
 
    country = StringField(
 
        lazy_gettext("Country"),
 
        validators=[Optional(), Length(max=500)],
 
    )
 

	
 
    terms = BooleanField(
 
        lazy_gettext(
 
            'By submitting this membership application, you agree to have read and understood the <a href="http://statutes.c3l.lu">statutes of the Chaos Computer Club Lëtzebuerg A.S.B.L.</a>.'
 
        ),
 
        validators=[InputRequired()],
 
    )
 

	
 
    submit = SubmitField(lazy_gettext("Become a member"))
c3l_membership/templates/index.html
Show inline comments
 
<!DOCTYPE html>
 
<html lang="en">
 
  <head>
 
    <meta charset="utf-8" />
 
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 
    <title>{% trans %}C3L Membership Application{% endtrans %}</title>
 

	
 
    <link rel="stylesheet" href="{{ url_for('static', filename='pure-min.css') }}" />
 
    <link rel="stylesheet" href="{{ url_for('static', filename='grids-responsive-min.css') }}" />
 
    <link rel="stylesheet" href="{{ url_for('static', filename='flag-icons.css') }}" />
 
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
 
  </head>
 
  <body>
 
    <div class="pure-g">
 
      <div class="pure-u-md-1-3"></div>
 
      <div class="pure-u-1-1 pure-u-md-1-3">
 
        <div class="menu">
 
          <div>
 
            <a href="{{ url_for("root.index", lang_code="en") }}" class="pure-menu-link"><span class="fi fi-gb"></span> English</a>
 
          </div>
 
          <div>
 
            <a href="{{ url_for("root.index", lang_code="lb") }}" class="pure-menu-link"><span class="fi fi-lu"></span> Lëtzebuergesch</a>
 
          </div>
 
          <div>
 
            <a href="{{ url_for("root.index", lang_code="de") }}" class="pure-menu-link"><span class="fi fi-de"></span> Deutsch</a>
 
          </div>
 
          <div>
 
            <a href="{{ url_for("root.index", lang_code="fr") }}" class="pure-menu-link"><span class="fi fi-fr"></span> Français</a>
 
          </div>
 
        </div>
 
      </div>
 
      <div class="pure-u-md-1-3"></div>
 
    </div>
 
    <div class="pure-g">
 
      <div class="pure-u-md-1-3"></div>
 
      <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 sign and 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-input-1 field-error" if form.username.errors else "pure-input-1") }}
 
              </div>
 
            </div>
 
            <div class="pure-g">
 
              <div class="pure-u-1-1">
 
                <b>{{ form.email.label }}</b>
 
                {{ form.email(required=True, class="pure-input-1 field-error" if form.email.errors else "pure-input-1") }}
 
              </div>
 
            </div>
 
            <div class="pure-g">
 
              <div class="pure-u-1-1">
 
                <b>{{ form.fullname.label }}</b>
 
                {{ form.fullname(required=True, class="pure-input-1 field-error" if form.fullname.errors else "pure-input-1") }}
 
              </div>
 
            </div>
 
            <div class="pure-g">
 
              <div class="pure-u-1-1">
 
                <h3>{{ form.membership.label }}</h3>
 
                {% for option in form.membership %}
 
                  <label for="{{ option.id }}" class="pure-radio pure-u-1-1">
 
                    {{ option() }} {{ option.label.text }}
 
                  </label>
 
                {% endfor %}
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <label for="{{ form.student.id }}" class="pure-checkbox">
 
                      {{ form.student }} {{ form.student.label.text|safe}}
 
                    </label>
 
                  </div>
 
                  <div class="pure-u-1-1">
 
                    <label for="{{ form.starving.id }}" class="pure-checkbox">
 
                      {{ form.starving }} {{ form.starving.label.text|safe}}
 
                    </label>
 
                  </div>
 
                </div>
 
                <h4>{% trans %}What's difference between the different membership options?{% endtrans %}</h4>
 
                <p>{% trans %}All the options include to following benefits:{% endtrans %}</p>
 
                <ul>
 
                  <li>{% trans %}Access to the <a href="https://wiki.c3l.lu/doku.php?id=organization:membership#benefits">services</a> run by us{% endtrans %}</li>
 
                  <li>{% trans %}Access to our <a href="https://wiki.c3l.lu/doku.php?id=chaosstuff:bootstrap">hackerspace: ChaosStuff</a>{% endtrans %}</li>
 
                </ul>
 
                <p>{% trans %}Becoming a regular member gives you these additional benefits:{% endtrans%}<p>
 
                  <ul>
 
                    <li>{% trans %}Voting rights on general assemblys{% endtrans %}</li>
 
                    <li>{% trans %}Access to our internal mailinglist{% endtrans %}</li>
 
                  </ul>
 
                  <p>{% trans %}You can read more on the membership <a href="https://wiki.c3l.lu/doku.php?id=organization:membership">here</a>.{% endtrans %}</p>
 
                  <h4>{% trans %}What are the membership fees?{% endtrans %}</h4>
 
                  <p>{% trans regular_fee=config["REGULAR_FEE"], supporting_fee=config["SUPPORTING_FEE"] %}The membership fee for the regular membership is {{ regular_fee }}€ per year. The membership fee for the supporting membership is {{ supporting_fee }}€ per year. If you are a student, all membership fees are {{ supporting_fee }}€ per year. For that please select the corresponding option.{% endtrans %}</p>
 
                  <h4>{% trans %}I cannot afford the membership?{% endtrans %}</h4>
 
                  <p>{% trans %}If you cannot afford the membership, please contact us via info@c3l.lu first, before filling out the membership form. We will try to find a solution together.{% endtrans %}</p>
 
                </div>
 
                </div>
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <h3>{{ form.payment.label }}</h3>
 
                    {% for option in form.payment %}
 
                      <label for="{{ option.id }}" class="pure-radio pure-u-1-1">
 
                        {{ option() }} {{ option.label.text }}
 
                      </label>
 
                    {% endfor %}
 
                  </div>
 
                </div>
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <b>{{ form.birthday.label }}</b>
 
                    {{ form.birthday(class="pure-input-1 field-error" if form.birthday.errors else "pure-input-1") }}
 
                  </div>
 
                  <div class="pure-u-1-1">
 
                    <h4>{% trans %}Why do you ask for the birthday?{% endtrans %}</h4>
 
                    <p>{% trans %}This information helps us with a few different things:{% endtrans %}</p>
 
                    <ul>
 
                      <li>{% trans %}We need to know if you are underage. If so your legal representatives needs to sign this membership application.{% endtrans %}</li>
 
                      <li>{% trans %}We ask the city of Luxembourg every year for a financial grant and they ask how many members we have over the age of 26 and how many under the age of 26.{% endtrans %}</li>
 
                    </ul>
 
                  </div>
 
                </div>
 
                <legend>{% trans %}Additional information (Optional){% endtrans %}</legend>
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <b>{{ form.street.label }}</b>
 
                    {{ form.street(class="pure-input-1 field-error" if form.street.errors else "pure-input-1") }}
 
                  </div>
 
                </div>
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <b>{{ form.zip.label }}</b>
 
                    {{ form.zip(class="pure-input-1 field-error" if form.zip.errors else "pure-input-1") }}
 
                    <b>{{ form.postal.label }}</b>
 
                    {{ form.postal(class="pure-input-1 field-error" if form.postal.errors else "pure-input-1") }}
 
                  </div>
 
                </div>
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <b>{{ form.city.label }}</b>
 
                    {{ form.city(class="pure-input-1 field-error" if form.city.errors else "pure-input-1") }}
 
                  </div>
 
                </div>
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <b>{{ form.state.label }}</b>
 
                    {{ form.state(class="pure-input-1 field-error" if form.state.errors else "pure-input-1") }}
 
                  </div>
 
                </div>
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <b>{{ form.country.label }}</b>
 
                    {{ form.country(class="pure-input-1 field-error" if form.country.errors else "pure-input-1") }}
 
                  </div>
 
                </div>
 
                <legend></legend>
 
                <div class="pure-g">
 
                  <div class="pure-u-1-1">
 
                    <label for="{{ form.terms.id }}" class="pure-checkbox text-justify">
 
                      {{ form.terms }} {{ form.terms.label.text|safe }}
 
                    </label>
 
                  </div>
 
                  <div class="pure-u-1-1">
 
                    {{ form.submit(class="text-xlarge pure-button pure-input-1 pure-button-primary") }}
 
                  </div>
 
                </div>
 
              </fieldset>
 
            </form>
 
          </div>
 
          <div class="pure-u-md-1-3"></div>
 
        </div>
 
      </body>
 
    </html>
c3l_membership/templates/member.html
Show inline comments
 
<!DOCTYPE html>
 
<html>
 
  <head>
 
    <title>{% trans username=form.username.data %}Membership Application - {{ username }}{% endtrans %}</title>
 
    <link rel="stylesheet" href="{{ url_for('static', filename='pdf.css') }}" />
 
  </head>
 
  <body>
 
    <div class="logos">
 
      <div>
 
        <img src="{{ url_for('static', filename='images/logo.png') }}" />
 
      </div>
 
      <div>
 
        <img src="{{ qrcode(xml|safe, border=1) }}" />
 
      </div>
 
    </div>
 
    <h1>{% trans %}Membership Application{% endtrans %}</h1>
 
    <div class="data">
 
      <div>
 
        <div>{% trans %}Username:{% endtrans %}</div>
 
        <div>{{ form.username.data }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}E-Mail:{% endtrans %}</div>
 
        <div>{{ form.email.data }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Full Name:{% endtrans %}</div>
 
        <div>{{ form.fullname.data }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Birthday:{% endtrans %}</div>
 
        <div>{{ form.birthday.data }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Street:{% endtrans %}</div>
 
        <div>{{ form.street.data if form.street.data else "".join(["<i>",_("Not specified"),"</i>"])|safe }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}ZIP-Code:{% endtrans %}</div>
 
        <div>{{ form.zip.data if form.zip.data else "".join(["<i>",_("Not specified"),"</i>"])|safe }}</div>
 
        <div>{% trans %}Postal Code:{% endtrans %}</div>
 
        <div>{{ form.postal.data if form.postal.data else "".join(["<i>",_("Not specified"),"</i>"])|safe }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}City:{% endtrans %}</div>
 
        <div>{{ form.city.data if form.city.data else "".join(["<i>",_("Not specified"),"</i>"])|safe }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}State/County/Province:{% endtrans %}</div>
 
        <div>{{ form.state.data if form.state.data else "".join(["<i>",_("Not specified"),"</i>"])|safe }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Country:{% endtrans %}</div>
 
        <div>{{ form.country.data if form.country.data else "".join(["<i>",_("Not specified"),"</i>"])|safe }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Membership Plan:{% endtrans%}</div>
 
        <div>{{ form.membership.data }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Voting rights:{% endtrans%}</div>
 
        <div>{{ _("Yes") if voting else _("No") }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Student:{% endtrans %}</div>
 
        <div>{{ _("Yes") if form.student.data else _("No") }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Starving:{% endtrans %}</div>
 
        <div>{{ _("Yes") if form.starving.data else _("No") }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Payment:{% endtrans %}</div>
 
        <div>{{ form.payment.data.lower() }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Agreed to Terms &amp; Conditions:{% endtrans %}</div>
 
        <div>{{ _("Yes") if form.terms.data else _("No") }}</div>
 
      </div>
 
      <div>
 
        <div>{% trans %}Minor Member:{% endtrans %}</div>
 
        <div>{{ _("Yes") if minor_member else _("No") }}</div>
 
      </div>
 
    </div>
 
    <p>{% trans %}Send this document to the Chaos Computer Club Lëtzebuerg!{% endtrans %}</p>
 
    {% if form.payment.data == 'wire transfer' %}
 
      <ul class="bank">
 
        <li>{% trans %}Account Holder:{% endtrans %} Chaos Computer Club Lëtzebuerg</li>
 
        <li>BIC/Swift: BCEELULLXXX</li>
 
        <li>IBAN: LU29 0019 2855 3890 4000</li>
 
        <li>{% trans %}Message:{% endtrans %} Membership fee {{ year }} {{ form.username.data }}</li>
 
        <li>{% trans %}Amount: {{ price }}€{% endtrans %}</li>
 
      </ul>
 
    {% elif form.payment.data == 'cash' %}
 
      <p>{% trans %}Please bring {{ price }}€ with you the next time you meet us!{% endtrans %}</p>
 
    {% elif form.payment.data in config["CRYPTOCURRENCIES"] %}
 
      <div class="cryptocontainer">
 
        <div>
 
          <ul class="cryptotext">
 
            <li><b>{% trans %}Address:{% endtrans %}</b> {{ config["CRYPTOCURRENCIES"][form.payment.data]["ADDRESS"] }}</li>
 
            <li><b>{% trans %}Label:{% endtrans %}</b> Membership Fee</li>
 
            <li><b>{% trans %}Message:{% endtrans %}</b> {{ year }} {{ form.username.data }}</li>
 
            <li><b>{% trans %}Amount:{% endtrans %}</b> {{ price }} {{ config["CRYPTOCURRENCIES"][form.payment.data]["COMMODITY"] }}</li>
 
          </ul>
 
        </div>
 
        {% set address = config["CRYPTOCURRENCIES"][form.payment.data]["ADDRESS"] %}
 
        {% set crypto_url=config["CRYPTOCURRENCIES"][form.payment.data]["URL"].format(address=address, amount=price, year=year, username=form.username.data) %}
 
        <div><img class="cryptoqrcode" src="{{ qrcode(crypto_url) }}" /></div>
 
      </div>
 
    {% elif form.payment.data == 'digicash' %}
 
      <div class="digicash">
 
        {% set payconiq_url='https://payconiq.com/t/1/62068d4d71445b0006dfbd5d?A={amount}&R=Membership&D={username}'.format(amount=price, username=form.username.data) %}
 
        <div><p>{% trans %}Pay with DigiCash/Payconiq!{% endtrans %}</p></div>
 
        <div><img src="{{ qrcode(payconiq_url) }}" /></div>
 
      </div>
 
    {% elif form.payment.data == 'satispay' %}
 
      <div class="digicash">
 
        {% set satispay_url='https://www.satispay.com/app/pay/shops/e5ca1df1-1f72-457e-88a2-7691ab630947?amount={amount}'.format(amount=price) %}
 
        <div><p>{% trans %}Pay with Satispay!{% endtrans %}</p></div>
 
        <div><img src="{{ qrcode(satispay_url) }}" /></div>
 
      </div>
 
    {% endif %}
 
    <div class="signature">
 
      <p class="membersignature">{% trans %}Luxembourg, the{% endtrans %}</p>
 
      <p class="adminsignature">
 
        {{ _("Signature of your legal representative") if minor_member else _("Your signature") }}
 
      </p>
 
    </div>
 
    <footer>
 
      <hr />
 
      <b>C</b>haos <b>C</b>omputer <b>C</b>lub <b>L</b>ëtzebuerg A.S.B.L.<br />
 
      Halle Victor Hugo - 60 Avenue Victor Hugo L-1750 Luxembourg<br />
 
      info@c3l.lu - <a href="https://c3l.lu">http://c3l.lu</a>
 
    </footer>
 
  </body>
 
</html>
c3l_membership/views.py
Show inline comments
 
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
 
from .utils import calculate_age
 

	
 
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/Payconiq")))
 

	
 
    if current_app.config["SATISPAY_ENABLED"]:
 
        choices.append(("satispay", gettext("by Satispay")))
 

	
 
    choices.extend(
 
        (cryptocurrency_label, " ".join((gettext("by"), cryptocurrency_label.title())))
 
        for cryptocurrency_label, options in current_app.config[
 
            "CRYPTOCURRENCIES"
 
        ].items()
 
        if options["ENABLED"]
 
    )
 

	
 
    form.payment.choices = choices
 

	
 
    if form.validate_on_submit():
 

	
 
        if form.birthday.data:
 
            if calculate_age(form.birthday.data) < 18:
 
                minor_member = True
 
                form.student.data = True
 
            else:
 
                minor_member = False
 

	
 
        if minor_member 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 minor_member or form.student.data:
 
            status = "Student"
 
        elif form.membership.data == "supporting":
 
            status = "Supporter"
 
        else:
 
            status = "Regular"
 

	
 
        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 in ("digicash", "satispay"):
 
            price = price * 100
 

	
 
        today = date.today()
 
        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": re.sub(
 
                "\s+",
 
                " ",
 
                " ".join(
 
                    (
 
                        form.street.data,
 
                        form.zip.data,
 
                        form.postal.data,
 
                        form.city.data,
 
                        form.state.data,
 
                        form.country.data,
 
                    )
 
                ),
 
            ),
 
            "voting": 1 if form.membership.data == "regular" else 0,
 
            "date": today,
 
        }
 

	
 
        html = render_template(
 
            "member.html",
 
            form=form,
 
            price=price,
 
            year=today.year,
 
            voting=True if form.membership.data == "regular" else False,
 
            xml=xml_template.format(**xml_data),
 
            minor_member=minor_member,
 
        )
 

	
 
        if current_app.debug:
 
            return render_pdf(HTML(string=html))
 
        else:
 
            return render_pdf(
 
                HTML(string=html),
 
                download_filename=f"C3L_Membership_{form.username.data}.pdf",
 
            )
 

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