From 31f74c1a8c4771c44817d72b814c856940574d5e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 29 Mar 2020 16:18:04 -0700 Subject: [PATCH] Hide follow request buttons after responding Fixes #106 --- .../templates/snippets/follow_request_buttons.html | 3 +++ fedireads/templatetags/fr_display.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/fedireads/templates/snippets/follow_request_buttons.html b/fedireads/templates/snippets/follow_request_buttons.html index 856fac51..fb25a194 100644 --- a/fedireads/templates/snippets/follow_request_buttons.html +++ b/fedireads/templates/snippets/follow_request_buttons.html @@ -1,3 +1,5 @@ +{% load fr_display %} +{% if request.user|follow_request_exists:user %}
{% csrf_token %} @@ -8,3 +10,4 @@
+{% endif %} diff --git a/fedireads/templatetags/fr_display.py b/fedireads/templatetags/fr_display.py index 33336d91..43a84b02 100644 --- a/fedireads/templatetags/fr_display.py +++ b/fedireads/templatetags/fr_display.py @@ -88,6 +88,20 @@ def get_user_liked(user, status): return False +@register.filter(name='follow_request_exists') +def follow_request_exists(user, requester): + ''' see if there is a pending follow request for a user ''' + try: + models.UserFollowRequest.objects.filter( + user_subject=requester, + user_object=user, + ).get() + return True + except models.UserFollowRequest.DoesNotExist: + return False + + + @register.simple_tag(takes_context=True) def shelve_button_identifier(context, book): ''' check what shelf a user has a book on, if any '''