diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html index eddf61cb..3df85a1a 100644 --- a/bookwyrm/templates/snippets/follow_button.html +++ b/bookwyrm/templates/snippets/follow_button.html @@ -18,7 +18,7 @@
{% csrf_token %} - {% if user.manually_approves_followers %} + {% if user.manually_approves_followers and request.user not in user.followers.all %} {% else %} diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 515bf325..d9f455eb 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -40,10 +40,22 @@ def unfollow(request): except models.User.DoesNotExist: return HttpResponseBadRequest() - models.UserFollows.objects.get( - user_subject=request.user, user_object=to_unfollow - ).delete() - return redirect(to_unfollow.local_path) + try: + models.UserFollows.objects.get( + user_subject=request.user, user_object=to_unfollow + ).delete() + except models.UserFollows.DoesNotExist: + pass + + try: + models.UserFollowRequest.objects.get( + user_subject=request.user, user_object=to_unfollow + ).delete() + except models.UserFollowRequest.DoesNotExist: + pass + + # this is handled with ajax so it shouldn't really matter + return redirect(request.headers.get("Referer", "/")) @login_required