forms.py 2.16 KB
Newer Older
1
2
# standard library imports
from __future__ import absolute_import, print_function
3
# core django imports
4
from django import forms
5
# third party imports
6
from crispy_forms.helper import FormHelper
Daniel W Bond's avatar
Daniel W Bond committed
7
8
from crispy_forms.layout import Submit, Layout
from crispy_forms.bootstrap import PrependedText, AppendedText
Daniel W Bond's avatar
Daniel W Bond committed
9
from multiselectfield import MultiSelectFormField
10
# imports from your apps
11
from .models import Student, Room, Major
12
from housing.models import Building
13

Daniel W Bond's avatar
Daniel W Bond committed
14

15
class StudentUpdateForm(forms.Form):
16

17
18
19
20
    first_name = forms.CharField(label='First Name')
    last_name = forms.CharField(label='Last Name')
    gender = MultiSelectFormField(choices=Student.GENDER_CHOICES,
                                  label='Gender Identity (please choose all that apply)')
21

22
23
24
25
    #neighborhood = forms.ChoiceField(choices=Building.NEIGHBOURHOOD_CHOICES)
    #building = forms.ModelChoiceField(queryset=Building.objects.filter(neighbourhood=neighborhood)
    #floor = forms.ModelChoiceField(queryset=Floor.objects.filter(building=building)
    #room = forms.ModelChoiceField(queryset=Room.objects.filter(floor=floor))
26

27
28
    privacy = forms.ChoiceField(choices=Student.PRIVACY_CHOICES)
    major = forms.ModelChoiceField(queryset=Major.objects.all())
29
    graduating_year = forms.IntegerField(label='Graduating Year')
30

Daniel W Bond's avatar
Daniel W Bond committed
31
32
33
34
35
36

class WelcomeNameForm(forms.Form):

    first_name = forms.CharField(label='First Name')
    last_name = forms.CharField(label='Last Name')
    gender = MultiSelectFormField(choices=Student.GENDER_CHOICES, label='Gender Identity (please choose all that apply)')
37
38
39
40


class WelcomePrivacyForm(forms.ModelForm):

Daniel W Bond's avatar
Daniel W Bond committed
41
42
43
44
45
    def __init__(self, *args, **kwargs):
        super(WelcomePrivacyForm, self).__init__(*args, **kwargs)
        if self.instance.recent_changes() >= 2:
            self.fields['room'].widget = forms.widgets.HiddenInput()

46
47
    class Meta:
        model = Student
Daniel W Bond's avatar
Daniel W Bond committed
48
        fields = ('room', 'privacy', )
49
50
51
52


class WelcomeSocialForm(forms.ModelForm):

Daniel W Bond's avatar
Daniel W Bond committed
53
54
55
56
    def __init__(self, *args, **kwargs):
        super(WelcomeSocialForm, self).__init__(*args, **kwargs)
        self.fields['completedSocial'].widget = forms.widgets.HiddenInput()

57
58
    class Meta:
        model = Student
Daniel W Bond's avatar
Daniel W Bond committed
59
        fields = ('completedSocial', )