-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
62 lines (49 loc) · 1.93 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
from django import forms
from users.models import UserProfile
from django.contrib.auth.models import User
class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
class Meta:
model = User
fields = ('username', 'email', 'password')
class UserProfileForm(forms.ModelForm):
class Meta:
model =UserProfile
fields = ('firstName', 'lastName', 'school', 'picture', 'isTeacher')
class EditProfileForm(forms.ModelForm):
def __init__(self,*args,**kwargs):
profile = kwargs.pop('profile')
super(EditProfileForm,self).__init__(*args,**kwargs)
self.fields['first_name'].initial=profile.firstName
self.fields['last_name'].initial=profile.lastName
self.fields['picture'].initial=profile.picture
self.fields['school'].initial=profile.school
first_name = forms.CharField(required=True)
last_name = forms.CharField(required=True)
picture = forms.CharField(required=True)
school = forms.CharField(required=True)
class Meta:
model = UserProfile
fields = ('school', 'picture',)
def clean_pic(self):
picture = self.cleaned_data.get('picture')
return picture
def clean_firstname(self):
first_name = self.cleaned_data.get('first_name')
return first_name
def clean_lastname(self):
last_name = self.cleaned_data.get('last_name')
return last_name
def clean_school(self):
school = self.cleaned_data.get('school')
return school
def save(self, commit=True):
user = super(EditProfileForm, self).save(commit=False)
user.userprofile.picture = self.cleaned_data['picture']
user.userprofile.firstName = self.cleaned_data['first_name']
user.userprofile.lastName = self.cleaned_data['last_name']
user.userprofile.school = self.cleaned_data['school']
if commit:
user.save()
user.userprofile.save()
return user