def post(self, request): postData = request.POST settingsForm = SettingsForm(postData) settingsForm.user = request.user if settingsForm.is_valid(): cleanedData = settingsForm.cleaned_data username = cleanedData['username'] email = cleanedData['email'] firstName = cleanedData['first_name'] lastName = cleanedData['last_name'] timezone = cleanedData['timezone'] gender = cleanedData['gender'] about = cleanedData['about'] password = cleanedData['password'] newPassword1 = cleanedData['new_password1'] newPassword2 = cleanedData['new_password2'] with transaction.atomic(): user = request.user if password or newPassword1 or newPassword2: user.set_password(newPassword1) user.save() user = authenticate( username=user.username, password=newPassword1, ) assert user is not None login(request, user) userProfile = user.userprofile user.username = username user.email = email user.first_name = firstName user.last_name = lastName userProfile.timezone = timezone userProfile.about = about userProfile.gender = gender user.save() userProfile.save() return redirect('users_profile', username=username) else: context = { 'settingsForm' : settingsForm, } return render(request, self.template_name, context)