Esempio n. 1
0
def edit_profile(request):
    user = request.user
    lp_user = user.LPUser
    avatar_form = AvatarForm(request.POST, request.FILES)
    email_form = UserEmailForm(request.POST or None, instance=user)
    password_form = UserPasswordNotRequiredForm(request.POST or None)
    if avatar_form.is_valid() and avatar_form.cleaned_data['avatar'] != 'avatars/default.png':
        lp_user.avatar = avatar_form.cleaned_data['avatar']
        lp_user.save()
    if email_form.is_valid():
        form_data = email_form.save()
        user.email = form_data.email
        user.save()
    if password_form.is_valid() and password_form.cleaned_data['password'] != '':
        user.set_password(password_form.cleaned_data['password'])
        user.save()
    return render(request, 'backoffice/edit_profile.html',
        {'avatar_form': avatar_form, 'email_form': email_form, 'password_form': password_form, 'lp_user': lp_user})
Esempio n. 2
0
 def test_missing_email(self):
     form = UserEmailForm(data=self.missing_email)
     self.assertTrue(form.is_valid())
Esempio n. 3
0
 def test_invalid_email(self):
     form = UserEmailForm(data=self.invalid_email)
     self.assertFalse(form.is_valid())
Esempio n. 4
0
 def test_valid_form(self):
     form = UserEmailForm(data=self.valid_form_data)
     self.assertTrue(form.is_valid())
Esempio n. 5
0
 def test_missing_email(self):
     form = UserEmailForm(data=self.missing_email)
     self.assertTrue(form.is_valid())
Esempio n. 6
0
 def test_invalid_email(self):
     form = UserEmailForm(data=self.invalid_email)
     self.assertFalse(form.is_valid())
Esempio n. 7
0
 def test_valid_form(self):
     form = UserEmailForm(data=self.valid_form_data)
     self.assertTrue(form.is_valid())