forms.py 1.6 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 payments.widgets import PaymentWidget
8
from utils.snippets import datetime_to_lectureyear
Thom Wiggers's avatar
Thom Wiggers committed
9
from .models import Registration, Renewal
10
11
12


class MemberRegistrationForm(forms.ModelForm):
13
    """Form for membership registrations"""
14

15
16
17
18
19
20
21
22
23
24
25
26
    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')
    )

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

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

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


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

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

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