forms.py 1.86 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

Daniel W Bond's avatar
Daniel W Bond committed
13

14
class StudentUpdateForm(forms.Form):
15

16
17
18
19
20
21
22
    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)')
    room = forms.ModelChoiceField(queryset=Room.objects.all())
    privacy = forms.ChoiceField(choices=Student.PRIVACY_CHOICES)
    major = forms.ModelChoiceField(queryset=Major.objects.all())
23
    graduating_year = forms.IntegerField(label='Graduating Year')
24

Daniel W Bond's avatar
Daniel W Bond committed
25
26
27
28
29
30

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)')
31
32
33
34


class WelcomePrivacyForm(forms.ModelForm):

Daniel W Bond's avatar
Daniel W Bond committed
35
36
37
38
39
    def __init__(self, *args, **kwargs):
        super(WelcomePrivacyForm, self).__init__(*args, **kwargs)
        if self.instance.recent_changes() >= 2:
            self.fields['room'].widget = forms.widgets.HiddenInput()

40
41
    class Meta:
        model = Student
Daniel W Bond's avatar
Daniel W Bond committed
42
        fields = ('room', 'privacy', )
43
44
45
46


class WelcomeSocialForm(forms.ModelForm):

Daniel W Bond's avatar
Daniel W Bond committed
47
48
49
50
    def __init__(self, *args, **kwargs):
        super(WelcomeSocialForm, self).__init__(*args, **kwargs)
        self.fields['completedSocial'].widget = forms.widgets.HiddenInput()

51
52
    class Meta:
        model = Student
Daniel W Bond's avatar
Daniel W Bond committed
53
        fields = ('completedSocial', )