From 3439e8c22ed0353f548d20cf66c3fe396aa33664 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Wed, 10 Jul 2019 12:57:58 -0400 Subject: [PATCH] Voting on polls works for both single and multiple --- brutaldon/templates/polls/new_partial.html | 24 +++++++++++++--------- brutaldon/urls.py | 1 + brutaldon/views.py | 20 ++++++++++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/brutaldon/templates/polls/new_partial.html b/brutaldon/templates/polls/new_partial.html index 8687cb5..719d174 100644 --- a/brutaldon/templates/polls/new_partial.html +++ b/brutaldon/templates/polls/new_partial.html @@ -2,21 +2,25 @@ {% load taglinks %} {% load static %} -
+ + {% csrf_token %} {% for option in toot.poll.options %}
- {% if toot.poll.multiple %} - + {% else %} - + {% endif %} - -
{% endfor %} diff --git a/brutaldon/urls.py b/brutaldon/urls.py index dea6ac7..809085b 100644 --- a/brutaldon/urls.py +++ b/brutaldon/urls.py @@ -68,5 +68,6 @@ urlpatterns = [ path("requests/", views.follow_requests, name="follow_requests"), path("accounts/", views.accounts, name="accounts"), path("accounts/", views.accounts, name="accounts"), + path("vote/", views.vote, name="vote"), path("", views.home, name=""), ] diff --git a/brutaldon/views.py b/brutaldon/views.py index beb9b13..066cb35 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -1616,3 +1616,23 @@ def accounts(request, id=None): "preferences": active_account.preferences, }, ) + +@br_login_required +def vote(request, id): + if request.method == "GET": + return redirect("thread", id) + if request.method == "POST": + account, mastodon = get_usercontext(request) + toot = mastodon.status(id) + poll = toot.poll + if not poll: + return redirect("thread", id) + # radio buttons + if "poll-single" in request.POST.keys(): + mastodon.poll_vote(poll.id, request.POST['poll-single']) + # checkboxes + else: + values = [x for x in request.POST.getlist('poll-multiple')] + if values: + mastodon.poll_vote(poll.id, values) + return redirect("thread", id)