-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathforms.py
39 lines (31 loc) · 1.24 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
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.forms import ModelForm
from .models import Course, Submission, Assignment
class SignUpForm(UserCreationForm):
def clean_email(self):
email = self.cleaned_data.get('email')
username = self.cleaned_data.get('username')
if email and User.objects.filter(email=email).exclude(username=username).exists():
raise forms.ValidationError(u'Email addresses must be unique.')
return email
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email' , 'password1', 'password2', )
class EnrollForm(forms.Form):
secret_key = forms.CharField(
widget=forms.TextInput(attrs={'placeholder': 'ABCXYZ12'}),
label='Secret Key',
required=False)
class Meta:
fields = ('secret_key')
class ChangeEmailForm(forms.Form):
email = forms.EmailField()
def clean_email(self):
email = self.cleaned_data.get('email')
if email and User.objects.filter(email=email).exists():
raise forms.ValidationError(u'That email is already used.')
return email
class Meta:
fields = ('email')