Changeset - 3e495ae230a2
[Not reviewed]
default
0 2 0
Dennis Fink - 3 years ago 2022-01-17 21:36:09
dennis.fink@c3l.lu
Mark fields that are not required as explicitly optional
2 files changed with 9 insertions and 7 deletions:
0 comments (0 inline, 0 general)
c3l_membership/forms.py
Show inline comments
 
@@ -18,87 +18,87 @@ class MembershipForm(FlaskForm):
 
    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."
 
        ),
 
    )
 

	
 
    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"))
 
    birthday = DateField(lazy_gettext("Birthday"), validators=[Optional()])
 

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

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

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

	
 
    country = StringField(
 
        lazy_gettext("Country"),
 
        validators=[Length(max=500)],
 
        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()],
 
    )
 

	
 
    minor_member = BooleanField(
 
        lazy_gettext(
 
            "I am under 18 years of age and have the approval of my legal representative."
 
        )
 
    )
 
    submit = SubmitField(lazy_gettext("Become a member"))
c3l_membership/views.py
Show inline comments
 
@@ -28,91 +28,93 @@ def pull_lang_code(endpoint, values):
 
@root_page.route("/", methods=("GET", "POST"))
 
def index():
 
    form = MembershipForm()
 

	
 
    choices = [
 
        ("cash", gettext("by cash")),
 
        ("wire transfer", gettext("by wire transfer")),
 
    ]
 

	
 
    for k, v in (
 
        ("DIGICASH_ENABLED", ("digicash", gettext("by DigiCash"))),
 
        ("BITCOIN_ENABLED", ("bitcoin", gettext("by bitcoin"))),
 
        ("ETHEREUM_ENABLED", ("ethereum", gettext("by ethereum"))),
 
        ("MONERO_ENABLED", ("monero", gettext("by monero"))),
 
        ("ZCASH_ENABLED", ("zcash", gettext("by zcash"))),
 
    ):
 
        if current_app.config[k]:
 
            choices.append(v)
 
    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"]
 
            xml_data["voting"] = 0
 
        elif form.membership.data == "regular":
 
            price = current_app.config["REGULAR_FEE"]
 
            xml_data["voting"] = 1
 

	
 
        if form.starving.data:
 
            price = 1
 

	
 
        if form.starving.data:
 
            xml_data["status"] = "Starving"
 
        elif form.minor_member.data or form.student.data:
 
            xml_data["status"] = "Student"
 
        elif form.membership.data == "supporting":
 
            xml_data["status"] = "Supporter"
 
        else:
 
            xml_data["status"] = "Regular"
 

	
 
        xml_data["name"] = form.fullname.data
 
        xml_data["birthday"] = form.birthday.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 == "bitcoin":
 
            price = subprocess.check_output(
 
                [current_app.config["BITCOIN_CONVERSION_SCRIPT"], str(price)]
 
            ).decode("utf-8")
 
        elif form.payment.data == "ethereum":
 
            price = subprocess.check_output(
 
                [current_app.config["ETHEREUM_CONVERSION_SCRIPT"], str(price)]
 
            ).decode("utf-8")
 
        elif form.payment.data == "monero":
 
            price = subprocess.check_output(
 
                [current_app.config["MONERO_CONVERSION_SCRIPT"], str(price)]
 
            ).decode("utf-8")
 
        elif form.payment.data == "zcash":
 
            price = subprocess.check_output(
 
                [current_app.config["ZCASH_CONVERSION_SCRIPT"], str(price)]
 
            ).decode("utf-8")
 
        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)
0 comments (0 inline, 0 general)