def follow_user(request, user_id): follower = get_profile(request.user, save=True) user_to_follow = get_object_or_404(User, pk=user_id) profile_to_follow = get_profile(user_to_follow, save=True) follower.followed.add(profile_to_follow) messages.add_message(request, messages.SUCCESS, "You have followed this user.") return redirect('show_user', user_to_follow.id)
def edit_profile(request): profile = get_profile(request.user) if request.method == "GET": profile_form = ProfileForm(instance=profile) elif request.method == "POST": profile_form = ProfileForm(instance=profile, data=request.POST) if profile_form.is_valid(): profile_form.save() messages.add_message(request, messages.SUCCESS, "Your profile has been updated.") return render(request, "users/edit_profile.html", {"form": profile_form})
def test_get_profile_makes_profile(self): user = User() self.assertEqual(Profile, type(get_profile(user)))
def test_get_profile_with_anon_user(self): user = AnonymousUser() self.assertEqual(None, get_profile(user))