forms.py 1.56 KB
Newer Older
1
"""The forms defined by the registrations package"""
2
from django import forms
3
from django.forms import TypedChoiceField
4
5
6
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

7
from utils.snippets import datetime_to_lectureyear
Thom Wiggers's avatar
Thom Wiggers committed
8
from .models import Registration, Renewal
9
10
11


class MemberRegistrationForm(forms.ModelForm):
12
    """Form for membership registrations"""
13
14
15
16
17
18
19
20
21
22
23
24
    birthday = forms.DateField(
        widget=forms.widgets.SelectDateWidget(years=[
            year for year in range(timezone.now().year - 50,
                                   timezone.now().year - 10)]),
        label=_('birthday')
    )

    privacy_policy = forms.BooleanField(
        required=True,
        label=_('I accept the privacy policy')
    )

25
26
    this_year = datetime_to_lectureyear(timezone.now())
    years = reversed([(x, "{} - {}".format(x, x + 1)) for x in
27
                      range(this_year - 20, this_year + 2)])
28
29
30
31
32
33
34

    starting_year = TypedChoiceField(
        choices=years,
        coerce=int,
        empty_value=this_year
    )

35
36
37
    class Meta:
        model = Registration
        fields = '__all__'
38
39
        exclude = ['created_at', 'updated_at', 'status', 'username', 'remarks',
                   'payment', 'membership']
40
41
42


class MemberRenewalForm(forms.ModelForm):
43
    """Form for membership renewals"""
44
45
46
47
48
49

    privacy_policy = forms.BooleanField(
        required=True,
        label=_('I accept the privacy policy')
    )

50
51
52
53
    class Meta:
        model = Renewal
        fields = '__all__'
        exclude = ['created_at', 'updated_at', 'status', 'remarks']