-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
161 lines (136 loc) · 4.64 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from typing import Any
from django.contrib.auth.forms import UserCreationForm, UserChangeForm, UsernameField
from django.utils.translation import gettext_lazy as _
from django import forms
from croppie.fields import CroppieField
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Row, Column, Submit, Div
from .models import Doctor, AllUser, Teacher, Student
class AllUserUserCreationForm(UserCreationForm):
first_name = forms.CharField(required=True)
last_name = forms.CharField(required=True)
class Meta:
model = AllUser
fields = ("first_name", 'id_number', "gender", "age",
"user_type", "last_name", "username", "email")
field_classes = {'username': UsernameField}
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Row(Column('user_type'), Column('gender')),
Row(Column('id_number')), Column('age'),
Row(Column('first_name'), Column('last_name')),
Row(Column('username'), Column('email')),
Row(Column('password1'), Column('password2')),
Div(Submit('submit', 'Submit', css_class='btn col-4 btn-success'),
css_class="col-12 d-flex justify-content-center"),
)
class DateInput(forms.DateInput):
input_type = 'date'
class DoctorUserCreationForm(UserCreationForm):
first_name = forms.CharField(required=True)
photo = CroppieField(
options={
'viewport': {
'width': 150,
'height': 150,
},
'boundary': {
'width': 160,
'height': 160,
},
'showZoomer': True,
},
required=False,
)
password1 = forms.CharField(
label=_("Password"),
strip=False,
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
)
password2 = forms.CharField(
label=_("Password confirmation"),
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
strip=False,
help_text=_("Enter the same password as before, for verification."),
)
class Meta:
model = Doctor
fields = (
"first_name", "last_name",
"username", "email",
"gender", "phone", "emergency_contact_number",
"password1", "password2", "photo", "current_address", "permanent_address", "note"
)
field_classes = {
'username': UsernameField,
}
widgets = {
'gender': forms.Select(
attrs={'class': 'form-select select2'}
),
'current_address': forms.Textarea(
attrs={'rows': '2'}
),
'permanent_address': forms.Textarea(
attrs={'rows': '2'}
),
'note': forms.Textarea(
attrs={'rows': '2'}
),
}
class DoctorUserChangeForm(forms.ModelForm):
first_name = forms.CharField(required=True)
photo = CroppieField(
options={
'viewport': {
'width': 150,
'height': 150,
},
'boundary': {
'width': 160,
'height': 160,
},
'showZoomer': True,
},
required=False,
)
class Meta:
model = AllUser
fields = (
"first_name", "last_name",
"username", "email",
'gender', 'phone', 'emergency_contact_number',
'photo', 'current_address', 'permanent_address',
'note',
)
field_classes = {
'username': UsernameField,
}
widgets = {
'gender': forms.Select(
attrs={'class': 'form-select select2'}
),
'current_address': forms.Textarea(
attrs={'rows': '2'}
),
'permanent_address': forms.Textarea(
attrs={'rows': '2'}
),
'note': forms.Textarea(
attrs={'rows': '2'}
),
}
class TeacherUserCreationForm(DoctorUserCreationForm):
class Meta(DoctorUserCreationForm.Meta):
model = Teacher
class TeacherUserChangeForm(DoctorUserChangeForm):
class Meta(DoctorUserChangeForm.Meta):
model = Teacher
class StudentUserCreationForm(DoctorUserCreationForm):
class Meta(DoctorUserCreationForm.Meta):
model = Student
class StudentUserChangeForm(DoctorUserChangeForm):
class Meta(DoctorUserChangeForm.Meta):
model = Student