Always pass follow/unfollow parameter using POST.

Fixes buttons in followers list.
This commit is contained in:
Adam Kelly 2020-02-22 18:00:43 +00:00
parent c889fab6d1
commit 730c49a2b6
3 changed files with 12 additions and 8 deletions

View file

@ -12,13 +12,15 @@
{% endif %} {% endif %}
{% if not is_self %} {% if not is_self %}
{% if not request.user in user.followers.all %} {% if not request.user in user.followers.all %}
<form action="/follow/{{ user.username }}" method="post"> <form action="/follow/" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ user.username }}"></input>
<input type="submit" value="Follow"></input> <input type="submit" value="Follow"></input>
</form> </form>
{% else %} {% else %}
<form action="/unfollow/{{ user.username }}" method="post"> <form action="/unfollow/" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ user.username }}"></input>
<input type="submit" value="Unfollow"></input> <input type="submit" value="Unfollow"></input>
</form> </form>
{% endif %} {% endif %}
@ -38,13 +40,13 @@
{% if not request.user in follower.followers.all %} {% if not request.user in follower.followers.all %}
<form action="/follow/" method="post"> <form action="/follow/" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ follower.id }}"></input> <input type="hidden" name="user" value="{{ follower.username }}"></input>
<input type="submit" value="Follow"></input> <input type="submit" value="Follow"></input>
</form> </form>
{% else %} {% else %}
<form action="/unfollow/" method="post"> <form action="/unfollow/" method="post">
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="user" value="{{ follower.id }}"></input> <input type="hidden" name="user" value="{{ follower.username }}"></input>
<input type="submit" value="Unfollow"></input> <input type="submit" value="Unfollow"></input>
</form> </form>
{% endif %} {% endif %}

View file

@ -57,8 +57,8 @@ urlpatterns = [
re_path(r'^comment/?$', views.comment), re_path(r'^comment/?$', views.comment),
re_path(r'^favorite/(?P<status_id>\d+)/?$', views.favorite), re_path(r'^favorite/(?P<status_id>\d+)/?$', views.favorite),
re_path(r'^shelve/?$', views.shelve), re_path(r'^shelve/?$', views.shelve),
re_path(r'^follow/(?P<username>[\w@\.-]+)/?$', views.follow), re_path(r'^follow/?$', views.follow),
re_path(r'^unfollow/(?P<username>[\w@\.-]+)/?$', views.unfollow), re_path(r'^unfollow/?$', views.unfollow),
re_path(r'^search/?$', views.search), re_path(r'^search/?$', views.search),
re_path(r'^edit_profile/?$', views.edit_profile), re_path(r'^edit_profile/?$', views.edit_profile),

View file

@ -362,8 +362,9 @@ def favorite(request, status_id):
@login_required @login_required
def follow(request, username): def follow(request):
''' follow another user, here or abroad ''' ''' follow another user, here or abroad '''
username = request.POST['user']
# should this be an actor rather than an id? idk # should this be an actor rather than an id? idk
to_follow = models.User.objects.get(username=username) to_follow = models.User.objects.get(username=username)
@ -374,8 +375,9 @@ def follow(request, username):
@login_required @login_required
def unfollow(request, username): def unfollow(request):
''' unfollow a user ''' ''' unfollow a user '''
username = request.POST['user']
to_unfollow = models.User.objects.get(username=username) to_unfollow = models.User.objects.get(username=username)
outgoing.handle_outgoing_unfollow(request.user, to_unfollow) outgoing.handle_outgoing_unfollow(request.user, to_unfollow)