From bd663e753908fcfba8a7e1e4345e9cf06d65396f Mon Sep 17 00:00:00 2001 From: "Jason F. McBrayer" Date: Fri, 31 Aug 2018 15:55:05 -0400 Subject: [PATCH] AJAX the follow button --- brutaldon/templates/intercooler/follow.html | 22 ++++++++++++++++ brutaldon/templates/main/user.html | 29 ++++++++++++++++----- brutaldon/views.py | 9 +++++++ 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 brutaldon/templates/intercooler/follow.html diff --git a/brutaldon/templates/intercooler/follow.html b/brutaldon/templates/intercooler/follow.html new file mode 100644 index 0000000..611edc2 --- /dev/null +++ b/brutaldon/templates/intercooler/follow.html @@ -0,0 +1,22 @@ +{% if relationship.requested %} + + + +{% elif not relationship.following %} + + + +{% else %} + + + +{% endif %} diff --git a/brutaldon/templates/main/user.html b/brutaldon/templates/main/user.html index 91258d4..e09ebd2 100644 --- a/brutaldon/templates/main/user.html +++ b/brutaldon/templates/main/user.html @@ -38,17 +38,23 @@ Brutaldon ({{ own_acct.username }}) - {{ user.acct }} timelime
{% if relationship.requested %} + href="{% url 'follow' user.id %}" + ic-post-to="{% url 'follow' user.id %}" + ic-indicator="#user-spinner" ic-replace-target="true"> {% elif not relationship.following %} + href="{% url 'follow' user.id %}" + ic-post-to="{% url 'follow' user.id %}" + ic-indicator="#user-spinner" ic-replace-target="true"> {% else %} + href="{% url 'follow' user.id %}" + ic-post-to="{% url 'follow' user.id %}" + ic-indicator="#user-spinner" ic-replace-target="true"> {% endif %} @@ -60,27 +66,36 @@ Brutaldon ({{ own_acct.username }}) - {{ user.acct }} timelime href="{% url 'toot' user.acct %}" title="mention"> +
{% if not relationship.muting %} + href="{% url 'mute' user.id %}" + ic-post-to="{% url 'mute' user.id %}" + ic-indicator="#user-spinner" ic-replace-target="true"> {% else %} + href="{% url 'mute' user.id %}" + ic-post-to="{% url 'mute' user.id %}" + ic-indicator="#user-spinner" ic-replace-target="true"> {% endif %} {% if not relationship.blocking %} + href="{% url 'block' user.id %}" + ic-post-to="{% url 'block' user.id %}" + ic-indicator="#user-spinner" ic-replace-target="true"> {% else %} + href="{% url 'block' user.id %}" + ic-post-to="{% url 'block' user.id %}" + ic-indicator="#user-spinner" ic-replace-target="true"> {% endif %} diff --git a/brutaldon/views.py b/brutaldon/views.py index 1ce6787..ee4ccf1 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -11,6 +11,7 @@ from mastodon import Mastodon, AttribAccessDict, MastodonError from urllib import parse from pdb import set_trace from bs4 import BeautifulSoup +from time import sleep class NotLoggedInException(Exception): pass @@ -620,6 +621,14 @@ def follow(request, id): mastodon.account_unfollow(id) else: mastodon.account_follow(id) + if request.POST.get('ic-request'): + sleep(1) # This is annoying, but the next call will return Requested instead of Following in some cases + relationship = mastodon.account_relationships(user_dict.id)[0] + return render(request, 'intercooler/follow.html', + {"user": user_dict, "relationship": relationship, + 'own_acct': request.session['user'], + 'preferences': account.preferences}) + else: return redirect(user, user_dict.acct) else: return render(request, 'main/follow.html',