forms.py 1.56 KB
Newer Older
1
# core django imports
2
from django import forms
3
# third party imports
4
from crispy_forms.helper import FormHelper
Daniel W Bond's avatar
Daniel W Bond committed
5
6
from crispy_forms.layout import Submit, Layout
from crispy_forms.bootstrap import PrependedText, AppendedText
Daniel W Bond's avatar
Daniel W Bond committed
7
from multiselectfield import MultiSelectFormField
8
9
# imports from your apps
from .models import Student
10

Daniel W Bond's avatar
Daniel W Bond committed
11

12
# form to create student
Daniel W Bond's avatar
Daniel W Bond committed
13
class StudentForm(forms.ModelForm):
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

    def __init__(self, *args, **kwargs):

        self.helper = FormHelper()
        self.helper.layout = Layout(
            'user',
            PrependedText('room', 'Room'),
            'class',
            AppendedText('major', 'Major'),
        )
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', 'Submit'))

        super(StudentForm, self).__init__(*args, **kwargs)

    class Meta:
30
        model = Student
31

32

Daniel W Bond's avatar
Daniel W Bond committed
33
class UserSettingsForm(forms.ModelForm):
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

    def __init__(self, *args, **kwargs):

        self.helper = FormHelper()
        self.helper.layout = Layout(
            'user',
            PrependedText('room', 'Room'),
            'class',
            AppendedText('major', 'Major'),
        )
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', 'Submit'))

        super(StudentForm, self).__init__(*args, **kwargs)

    class Meta:
        model = Student
Daniel W Bond's avatar
Daniel W Bond committed
51
52
53
54
55
56
57
58

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