Added polls module.
CI / Formatting (push) Successful in 6s
CI / Linting (push) Successful in 6s
CI / Tests (Python 3.12) (push) Successful in 12s
CI / Tests (Python 3.13) (push) Successful in 12s
CI / Tests (Python 3.14) (push) Successful in 10s
CI / Type Checking (push) Successful in 9s
CI / Spelling (push) Successful in 5s
CI / Formatting (push) Successful in 6s
CI / Linting (push) Successful in 6s
CI / Tests (Python 3.12) (push) Successful in 12s
CI / Tests (Python 3.13) (push) Successful in 12s
CI / Tests (Python 3.14) (push) Successful in 10s
CI / Type Checking (push) Successful in 9s
CI / Spelling (push) Successful in 5s
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Create Poll{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="mb-4">Create Poll</h1>
|
||||
{% if error %}
|
||||
<div class="alert alert-danger" role="alert">{{ error }}</div>
|
||||
{% endif %}
|
||||
<form method="POST" action="{{ submit_url }}" id="poll-form">
|
||||
<div class="mb-3">
|
||||
<label for="question" class="form-label">Question</label>
|
||||
<input type="text" class="form-control" id="question" name="question" required maxlength="{{ constraints.max_question_length }}" placeholder="What do you want to ask chat?" value="{{ form.question }}">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Options</label>
|
||||
<div id="options-container">
|
||||
{% for opt in form.options %}
|
||||
<div class="input-group mb-2 option-row">
|
||||
<span class="input-group-text option-number">{{ loop.index }}</span>
|
||||
<input type="text" class="form-control option-input" name="option_{{ loop.index }}" required maxlength="{{ constraints.max_option_length }}" placeholder="Option {{ loop.index }}" value="{{ opt }}">
|
||||
{% if loop.index > 2 %}
|
||||
<button type="button" class="btn btn-outline-danger remove-option">Remove</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<button type="button" class="btn btn-sm btn-outline-primary" id="add-option">Add Option</button>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="duration" class="form-label">Duration (seconds)</label>
|
||||
<input type="number" class="form-control" id="duration" name="duration" value="{{ form.duration }}" min="{{ constraints.min_duration }}" max="{{ constraints.max_duration }}">
|
||||
</div>
|
||||
|
||||
<div class="mb-3 form-check">
|
||||
<input type="checkbox" class="form-check-input" id="hidden" name="hidden" {% if form.hidden %}checked{% endif %}>
|
||||
<label class="form-check-label" for="hidden">Hidden until end</label>
|
||||
<div class="form-text">Vote counts stay hidden from voters until the poll ends.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 form-check">
|
||||
<input type="checkbox" class="form-check-input" id="requires_auth" name="requires_auth" {% if form.requires_auth %}checked{% endif %}>
|
||||
<label class="form-check-label" for="requires_auth">Require authentication</label>
|
||||
<div class="form-text">Only viewers with an authenticated Owncast account can vote.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 form-check">
|
||||
<input type="checkbox" class="form-check-input" id="allow_multiple" name="allow_multiple" {% if form.allow_multiple %}checked{% endif %}>
|
||||
<label class="form-check-label" for="allow_multiple">Allow multiple selections</label>
|
||||
<div class="form-text">Voters can select more than one option.</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3 ms-4 {{ '' if form.allow_multiple else 'd-none' }} d-flex align-items-center gap-2 flex-wrap" id="multi-select-options">
|
||||
<span>Voters must select between</span>
|
||||
<input type="number" class="form-control form-control-sm" style="width: 5rem" id="min_selections" name="min_selections" min="1" placeholder="1" value="{{ form.min_selections }}">
|
||||
<span>and</span>
|
||||
<input type="number" class="form-control form-control-sm" style="width: 5rem" id="max_selections" name="max_selections" min="1" value="{{ form.max_selections }}">
|
||||
<span>options.</span>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="options" id="options-hidden">
|
||||
<button type="submit" class="btn btn-primary">Create Poll</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script>window.CREATE_CONFIG = {
|
||||
maxOptions: {{ constraints.max_options | tojson }},
|
||||
maxOptionLength: {{ constraints.max_option_length | tojson }}
|
||||
};</script>
|
||||
<script src="{{ create_js_url }}?v={{ owlbot_version }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Error{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="mb-3">Error</h1>
|
||||
<div class="alert alert-danger" role="alert">{{ message }}</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,31 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Results: {{ question }}{% endblock %}
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="{{ polls_css_url }}?v={{ owlbot_version }}">
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="mb-3">{{ question }}</h1>
|
||||
|
||||
{% set total = results.counts | sum %}
|
||||
<div class="d-flex flex-column gap-2 mb-4">
|
||||
{% for option in options %}
|
||||
{% set count = results.counts[loop.index0] %}
|
||||
{% set pct = (count / total * 100) | round(0) | int if total > 0 else 0 %}
|
||||
{% set is_winner = option in results.winners and results.total_votes > 0 %}
|
||||
<div class="option-bar">
|
||||
<div class="bar-fill {{ 'winner' if is_winner else 'other' }}" style="width: {{ pct }}%"></div>
|
||||
<span class="option-label">
|
||||
{{ option }}
|
||||
{% if is_winner %}
|
||||
<span class="badge bg-success ms-1">{{ "Tie" if results.is_tie else "Winner" }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
<span class="vote-count">
|
||||
{{ count }} ({{ pct }}%)
|
||||
</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<p class="text-body-secondary">Total votes: {{ results.total_votes }}</p>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,83 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Vote: {{ poll.question }}{% endblock %}
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="{{ polls_css_url }}?v={{ owlbot_version }}">
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<h1 class="mb-3">{{ poll.question }}</h1>
|
||||
<div id="poll-status" class="mb-4">
|
||||
<p class="text-body-secondary mb-1">Time remaining: <strong id="timer">--:--</strong></p>
|
||||
{% if poll.hidden %}
|
||||
{% if token.is_moderator %}
|
||||
<p class="text-body-secondary mb-0">Results are hidden until this poll ends. As a moderator, you can still see the real-time results.</p>
|
||||
{% else %}
|
||||
<p class="text-body-secondary mb-0">Results are hidden until this poll ends.</p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p class="text-body-secondary mb-0">Results are updated in real time.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<form method="POST" action="{{ vote_url }}" id="vote-form">
|
||||
<div class="d-flex flex-column gap-2 mb-4">
|
||||
{% for option in poll.options %}
|
||||
<div class="option-bar" data-index="{{ loop.index0 }}">
|
||||
<div class="bar-fill" style="width: 0%"></div>
|
||||
<label>
|
||||
{% if poll.allow_multiple %}
|
||||
<input type="checkbox" name="option" value="{{ loop.index0 }}" class="form-check-input me-2"
|
||||
{% if loop.index0 in current_votes %}checked{% endif %}
|
||||
{% if has_voted or (not token.is_authenticated and poll.requires_auth) %}disabled{% endif %}>
|
||||
{% else %}
|
||||
<input type="radio" name="option" value="{{ loop.index0 }}" class="form-check-input me-2" required
|
||||
{% if loop.index0 in current_votes %}checked{% endif %}
|
||||
{% if has_voted or (not token.is_authenticated and poll.requires_auth) %}disabled{% endif %}>
|
||||
{% endif %}
|
||||
{{ option }}
|
||||
</label>
|
||||
<span class="vote-count d-none" data-index="{{ loop.index0 }}">
|
||||
<span class="count">-</span> (<span class="pct">-</span>%)
|
||||
</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if poll.requires_auth and not token.is_authenticated %}
|
||||
<div class="alert alert-warning mb-0" role="alert">This poll requires an authenticated account to vote. You are viewing results only.</div>
|
||||
{% elif not has_voted %}
|
||||
<button type="submit" class="btn btn-primary me-2">Vote</button>
|
||||
{% else %}
|
||||
<p class="text-body-secondary mb-0">You have already voted in this poll.</p>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
{% if token.is_moderator %}
|
||||
<hr class="my-4">
|
||||
<h5>Manage Poll</h5>
|
||||
<p class="text-body-secondary">As a moderator, you can perform the following actions on this poll:</p>
|
||||
<div class="d-flex gap-2">
|
||||
<form method="POST" action="{{ vote_url }}/end">
|
||||
<button type="submit" class="btn btn-success">End Poll</button>
|
||||
</form>
|
||||
<form method="POST" action="{{ vote_url }}/cancel">
|
||||
<button type="submit" class="btn btn-danger">Cancel Poll</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script>
|
||||
window.POLL_CONFIG = {
|
||||
hidden: {{ poll.hidden | tojson }},
|
||||
timeRemaining: {{ poll.time_remaining | tojson }},
|
||||
allowMultiple: {{ poll.allow_multiple | tojson }},
|
||||
minSelections: {{ poll.min_selections | tojson }},
|
||||
maxSelections: {{ poll.max_selections | tojson }}
|
||||
};
|
||||
window.TOKEN_INFO = {
|
||||
isModerator: {{ token.is_moderator | tojson }},
|
||||
eventsUrl: {{ (vote_url + "/events") | tojson }}
|
||||
};
|
||||
</script>
|
||||
<script src="{{ polls_js_url }}?v={{ owlbot_version }}"></script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user