def edit_profile(request): if request.method == 'POST': form = EditProfileForm(request.POST, instance=request.user) if form.is_valid(): form.save() return redirect('/app/profile') else: form = EditProfileForm(instance=request.user) args = {'form': form} return render(request, 'app/edit_profile.html', args)
def post(self, request, *args, **kwargs): user = User.objects.filter(username=self.kwargs['username']).first() profile = Profile.objects.filter(user=user).first() user_form = EditUserForm(request.POST, instance=user) profile_form = EditProfileForm(request.POST, instance=profile) if user_form.is_valid() and profile_form.is_valid(): user_form = user_form.save() custom_form = profile_form.save(False) custom_form.user = user_form custom_form.save() return redirect('user', username=user.username) return render(request, self.template_name, args)
def test_edit_profile_email_missing(self): edit_profile_form = { 'first_name': 'testsdgsdg', 'last_name': 'sgfsdgdgdg', 'engage_anonymously': True, 'gender': 'female', 'alias': 'sdgsdgsdgdg', 'year_of_birth': 1989, 'avatar': None, 'mobile_number': '8767564444', 'email': '*****@*****.**', 'identity': '' } form = EditProfileForm(data=edit_profile_form) self.assertEqual(form.is_valid(), False)
def edit_profile(request): if request.method == 'POST': CurrUser = request.user form = EditProfileForm(request.POST) if form.is_valid(): CurrUser.refresh_from_db() CurrUser.userprofile.bio = form.cleaned_data.get('bio') raw_password = form.cleaned_data.get('password') CurrUser.set_password(raw_password) CurrUser.userprofile.favoritePark = form.cleaned_data.get( 'favoritePark') CurrUser.save() return redirect('index') else: form = EditProfileForm() return render(request, 'app/edit_profile.html', {'form': form})
def edit_profile(request): """ allows a user to edit their profile Arguments: request -- [standard Django request arg] Returns: Errors if there were errors with form completion Redirect to account Or renders the page """ logger.info("Edit profile page hit") form = EditProfileForm(request.POST, request.FILES) if request.method == 'POST': logger.info("%s is editing ptofile", request.user) form = EditProfileForm(request.POST, request.FILES) if form.is_valid(): obj = UserProfile.objects.get(user=request.user) obj.user_picture = form.cleaned_data['picture'] print(obj.user_picture) obj.address = form.cleaned_data['address'] obj.phone = form.cleaned_data['phone'] obj.save() return redirect('app:account') else: print(form.errors) avatar = None user = request.user if user: if user.is_active: profile = UserProfile.objects.get(user=request.user) avatar = profile.picture else: avatar = None context_dict = {'form': form, 'picture': avatar} return render(request, 'app/edit_profile.html', context_dict)
return render(request, 'profile_page.html', context) def edit_profile(request): context = {} try: user = CustomUser.objects.get(pk=request.user.pk) except Exception, e: raise Http404('404') form = EditProfileForm(request.POST or None, instance=user) context['form'] = form if form.is_valid(): form.save() return redirect('/profile/') else: print form.errors return render(request, 'edit_profile.html', context) @staff_member_required def delete_album(request, pk): album = Album.objects.get(pk=pk) album.delete() artist = album.artist
def test_edit_profile_email_already_exist(self): # This beloe email address has already been set to user in setup() call. edit_profile_form = { 'username': '******', # New edited email address 'first_name': 'testsdgsdg', 'last_name': 'sgfsdgdgdg', 'engage_anonymously': True, 'gender': 'female', 'alias': 'sdgsdgsdgdg', 'year_of_birth': 1989, 'avatar': None, 'mobile_number': '8767564444', 'email': '*****@*****.**', # Current user email address 'identity': '' } form = EditProfileForm(data=edit_profile_form) self.assertEqual(form.is_valid(), False)