class ProfileForm forms Form Base class for user profile first_name fo

 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
class ProfileForm(forms.Form):
"""Base class for user profile."""
first_name = forms.CharField(required = False, max_length = 30, label = u"Имя")
last_name = forms.CharField(required = False, max_length = 30, label = u"Фамилия")
sex = forms.ChoiceField(required = False, choices = [(0, u'Неизвестно'), (1, u'Мужчина'), (2, u'Женщина')], label=u'Пол')
location = forms.CharField(required = False, max_length = 60, label = u"Откуда")
avatar = forms.ImageField(required = False, label = u"Аватара")
#balance = forms.FloatField(required = False)
def save(self, user_profile):
usr = User.objects.get(username = user_profile['login'])
profile = usr.get_profile()
# Modify user
usr.first_name = user_profile['first_name']
usr.last_name = user_profile['last_name']
#usr.email = user_profile['email']
# Modify user`s profile
sex = int(user_profile['sex'])
if sex == 0:
profile.is_man = None
elif sex == 1:
profile.is_man = True
else:
profile.is_man = False
profile.location = user_profile['location']
profile.avatar = user_profile['avatar']
print self.cleaned_data
usr.save()
profile.save()