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
25
    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')
    )

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

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

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


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

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

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