Undo follow request view

This commit is contained in:
Mouse Reeve 2021-03-13 14:55:09 -08:00
parent e9575cae6c
commit 4d7364d045
2 changed files with 17 additions and 5 deletions

View file

@ -18,7 +18,7 @@
<form action="{% url 'unfollow' %}" method="POST" class="interaction follow-{{ user.id }} {% if not request.user in user.followers.all and not request.user in user.follower_requests.all %}hidden{%endif %}" data-id="follow-{{ user.id }}">
{% csrf_token %}
<input type="hidden" name="user" value="{{ user.username }}">
{% if user.manually_approves_followers %}
{% if user.manually_approves_followers and request.user not in user.followers.all %}
<button class="button is-small is-danger is-light" type="submit">{% trans "Undo follow request" %}</button>
{% else %}
<button class="button is-small is-danger is-light" type="submit">{% trans "Unfollow" %}</button>

View file

@ -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