-
Notifications
You must be signed in to change notification settings - Fork 1
/
forms.py
127 lines (103 loc) · 4.07 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
from django import forms
from django.forms.widgets import PasswordInput
from django.core.validators import RegexValidator, MinLengthValidator
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User
from DBManagement.models import *
class RegistrationForm(forms.Form):
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
email = forms.EmailField(
max_length=75,
validators = [
RegexValidator(
regex='ntu\.edu\.sg$',
message='NTU Email is Required',
code='invalid_ntuemail'
),
]
)
password = forms.CharField(
widget=PasswordInput,
validators = [MinLengthValidator(8)]
)
cfm_password = forms.CharField(widget=PasswordInput)
def clean_email(self):
# Perform checking for existing email used by user
email = self.cleaned_data['email']
if User.objects.filter(email=email).exists():
raise ValidationError("Email already in use")
return email
def clean(self):
cleaned_data = super(RegistrationForm, self).clean()
# Perform checking for password confirmation
password = cleaned_data.get("password")
cfm_password = cleaned_data.get("cfm_password")
if password and cfm_password and password != cfm_password:
self._errors["cfm_password"] = self.error_class(["Confirm password does not match"])
del cleaned_data["password"]
del cleaned_data["cfm_password"]
return cleaned_data
class PasswordForgetForm(forms.Form):
email = forms.EmailField(
max_length=75,
validators = [
RegexValidator(
regex='ntu\.edu\.sg$',
message='NTU Email is Required',
code='invalid_ntuemail'
),
]
)
def clean_email(self):
# Perform checking for existing email used by user
email = self.cleaned_data['email']
if not User.objects.filter(email=email).exists():
raise ValidationError("No account has been registered with this email")
return email
class PasswordResetForm(forms.Form):
email = forms.EmailField(
max_length=75,
validators = [
RegexValidator(
regex='ntu\.edu\.sg$',
message='NTU Email is Required',
code='invalid_ntuemail'
),
]
)
password = forms.CharField(
widget=PasswordInput,
validators = [MinLengthValidator(8)]
)
cfm_password = forms.CharField(widget=PasswordInput)
def clean(self):
cleaned_data = super(PasswordResetForm, self).clean()
# Perform checking for password confirmation
password = cleaned_data.get("password")
cfm_password = cleaned_data.get("cfm_password")
if password and cfm_password and password != cfm_password:
self._errors["cfm_password"] = self.error_class(["Confirm password does not match"])
del cleaned_data["password"]
del cleaned_data["cfm_password"]
return cleaned_data
class ActivationForm(forms.Form):
username = forms.CharField()
password = forms.CharField()
class FeedbackForm(forms.Form):
feedback = forms.CharField()
"""
class InsertEditQuestionForm(forms.Form):
topics = Topic.objects.all()
tags = Tag.objects.all().values_list('name', 'name')
content = forms.CharField(max_length=2000)
difficulty = forms.IntegerField(min_value=1, max_value=5)
topic = forms.ModelChoiceField(queryset=topics)
time = forms.IntegerField(required=False, min_value=0)
marks = forms.DecimalField(required=False, max_digits=3, decimal_places=1, min_value=0.0)
answer = forms.CharField(max_length=1) # This shld be 100 but MCQ for now only
solution = forms.CharField(required=False, max_length=2000)
tags = forms.MultipleChoiceField(required=False, choices=tags)
class FlagQuestionForm(forms.Form):
issue = forms.CharField(max_length=2000)
"""