Changeset - 0b4955bdc703
[Not reviewed]
default
0 1 0
Dennis Fink - 3 years ago 2022-03-05 18:13:17
dennis.fink@c3l.lu
Automatically calculate age and set minor_member and student accordingly
1 file changed with 21 insertions and 3 deletions:
0 comments (0 inline, 0 general)
c3l_membership/views.py
Show inline comments
 
@@ -53,6 +53,25 @@ def index():
 

	
 
    if form.validate_on_submit():
 

	
 
        today = date.today()
 
        if form.birthday.data:
 
            born = form.birthday.data
 
            try:
 
                birthday = born.replace(year=today.year)
 
            except ValueError:
 
                birthday = born.replace(year=today.year, month=born.month + 1, day=1)
 

	
 
            age = today.year - born.year
 

	
 
            if birthday > today:
 
                age -= 1
 

	
 
            if age < 18:
 
                form.minor_member.data = True
 
                form.student.data = True
 
            else:
 
                form.minor_member.data = False
 

	
 
        if (
 
            form.minor_member.data
 
            or form.student.data
 
@@ -90,7 +109,6 @@ def index():
 
        elif form.payment.data in ("digicash", "satispay"):
 
            price = price * 100
 

	
 
        now = date.today()
 
        xml_data = {
 
            "status": status,
 
            "name": form.fullname.data,
 
@@ -113,14 +131,14 @@ def index():
 
                ),
 
            ),
 
            "voting": 1 if form.membership.data == "regular" else 0,
 
            "date": now,
 
            "date": today,
 
        }
 

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