mirror of
https://gitlab.com/brutaldon/brutaldon.git
synced 2024-12-04 14:46:24 -05:00
Voting on polls works for both single and multiple
This commit is contained in:
parent
a5a67ccb54
commit
3439e8c22e
@ -2,21 +2,25 @@
|
|||||||
{% load taglinks %}
|
{% load taglinks %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
<form method="POST" action="/vote/{{ toot.poll.id }}">
|
<form method="POST" action="{% url "vote" toot.id %}">
|
||||||
|
{% csrf_token %}
|
||||||
{% for option in toot.poll.options %}
|
{% for option in toot.poll.options %}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
||||||
{% if toot.poll.multiple %}
|
{% if toot.poll.multiple %}
|
||||||
<input type="checkbox" id="poll-{{ toot.poll.id }}-{{ forloop.counter0 }}"
|
<label class="checkbox">
|
||||||
class="checkbox" >
|
<input type="checkbox"
|
||||||
|
name="poll-multiple"
|
||||||
|
value="{{ forloop.counter0 }}">
|
||||||
|
{{ option.title }}
|
||||||
|
</label>
|
||||||
{% else %}
|
{% else %}
|
||||||
<input type="radio" id="poll-{{ toot.poll.id }}-{{ forloop.counter0 }}"
|
<label class="radio">
|
||||||
name="poll-{{ toot.poll.id }}">
|
<input type="radio"
|
||||||
|
name="poll-single"
|
||||||
|
value="{{ forloop.counter0 }}">
|
||||||
|
{{ option.title }}
|
||||||
|
</label>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<label for="poll-{{ toot.poll.id }}-{{ forloop.counter0 }}">
|
|
||||||
{{ option.title }}
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<input type="submit" class="button is-primary" name="Vote" value="Vote">
|
<input type="submit" class="button is-primary" name="Vote" value="Vote">
|
||||||
|
@ -68,5 +68,6 @@ urlpatterns = [
|
|||||||
path("requests/<id>", views.follow_requests, name="follow_requests"),
|
path("requests/<id>", views.follow_requests, name="follow_requests"),
|
||||||
path("accounts/", views.accounts, name="accounts"),
|
path("accounts/", views.accounts, name="accounts"),
|
||||||
path("accounts/<id>", views.accounts, name="accounts"),
|
path("accounts/<id>", views.accounts, name="accounts"),
|
||||||
|
path("vote/<id>", views.vote, name="vote"),
|
||||||
path("", views.home, name=""),
|
path("", views.home, name=""),
|
||||||
]
|
]
|
||||||
|
@ -1616,3 +1616,23 @@ def accounts(request, id=None):
|
|||||||
"preferences": active_account.preferences,
|
"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)
|
||||||
|
Loading…
Reference in New Issue
Block a user