Skip to content

Commit

Permalink
add option to disallow voting after a specific date
Browse files Browse the repository at this point in the history
implements #3
  • Loading branch information
fkusei committed Sep 4, 2023
1 parent b9b484b commit 95d3fec
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 29 deletions.
15 changes: 15 additions & 0 deletions pretalx_halfnarp/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.forms import DateField
from django.utils.translation import gettext_lazy as _
from hierarkey.forms import HierarkeyForm
from i18nfield.forms import I18nFormMixin


class HalfnarpSettingsForm(I18nFormMixin, HierarkeyForm):
halfnarp_allow_voting_until = DateField(
help_text=_(
"Voting closes at midnight at the selected day. If unset, "
"voting is allowed until a schedule is released."
),
label=_("Allow votes until"),
required=False,
)
8 changes: 8 additions & 0 deletions pretalx_halfnarp/templates/pretalx_halfnarp/frontend.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h1>{% translate "Presentation Preference" %}</h1>
Thank you for helping us plan a better program for the upcoming conference.
{% endblocktranslate %}
</p>
{% if voting_is_enabled %}
<p>
{% blocktranslate trimmed %}
In the list below you will find all the talks we have accepted for the conference.
Expand Down Expand Up @@ -59,4 +60,11 @@ <h2 class="title">{{submission.title}}</h2>

{% endfor %}
</div>
{% else %}
<p>
{% blocktranslate trimmed %}
The voting period has ended.
{% endblocktranslate %}
</p>
{% endif %}
{% endblock %}
81 changes: 54 additions & 27 deletions pretalx_halfnarp/templates/pretalx_halfnarp/organiser.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,61 @@
{% endcompress %}
{% endblock %}

{% block scripts %}
{% compress js %}
<script defer src="{% static "vendored/moment-with-locales.js" %}"></script>
<script defer src="{% static "vendored/moment-timezone-with-data-10-year-range.js" %}"></script>
<script defer src="{% static "vendored/datetimepicker/bootstrap-datetimepicker.js" %}"></script>
<script defer src="{% static "orga/js/datetimepicker.js" %}"></script>
{% endcompress %}
{% endblock %}

{% block content %}
<div class="title">
<h2>{% translate "Most Preferred Submissions" %}</h2>
<a class="btn btn-info" href="{% url "plugins:pretalx_halfnarp:frontend" event %}" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
{% translate "Link to Vote-Page" %}
</a>
</div>
<p>
{% blocktranslate trimmed %}
The following Submissions have been voted the most (in descending order).
{% endblocktranslate %}
</p>
<div class="submissions">
{% for info in most_preferred_submissions %}
<div class="submission card mb-3">
<div class="card-body">
<div class="card-title headline">
<h2 class="title">{{info.submission.title}}</h2>
<span class="counter">Votes: {{info.count}}/{{num_preferences}}</span>
</div>
<p class="speakers">{{info.submission.display_speaker_names}}</p>
<div class="footer">
<div class="track">Track: <span class="track">{{info.submission.track}}</span></div>
<a href="{{info.submission.orga_urls.base}}" target="_blank">{% translate "More info" %}</a>
<div class="title">
<h2>{% translate "Most Preferred Submissions" %}</h2>
<a class="btn btn-info" href="{% url "plugins:pretalx_halfnarp:frontend" request.event %}" target="_blank">
<i class="fa fa-external-link" aria-hidden="true"></i>
{% translate "Link to Vote-Page" %}
</a>
</div>
<form method="post">
{% csrf_token %}
<fieldset>
<legend>{% translate "Settings" %}</legend>

{% bootstrap_form_errors form %}

{% bootstrap_field form.halfnarp_allow_voting_until layout='event' %}
</fieldset>
<div class="submit-group panel">
<span>
<button type="submit" class="btn btn-success btn-lg">
<i class="fa fa-check"></i>
{% translate "Save" %}
</button>
</span>
</div>
</form>
<p>
{% blocktranslate trimmed %}
The following Submissions have been voted the most (in descending order).
{% endblocktranslate %}
</p>
<div class="submissions">
{% for info in most_preferred_submissions %}
<div class="submission card mb-3">
<div class="card-body">
<div class="card-title headline">
<h2 class="title">{{info.submission.title}}</h2>
<span class="counter">Votes: {{info.count}}/{{num_preferences}}</span>
</div>
<p class="speakers">{{info.submission.display_speaker_names}}</p>
<div class="footer">
<div class="track">Track: <span class="track">{{info.submission.track}}</span></div>
<a href="{{info.submission.orga_urls.base}}" target="_blank">{% translate "More info" %}</a>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endblock %}
24 changes: 24 additions & 0 deletions pretalx_halfnarp/views/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import secrets
from datetime import timedelta

import pytz
from django.utils import timezone
from django.views.generic import TemplateView
from django_context_decorator import context
from pretalx.cfp.views.event import EventPageMixin
Expand Down Expand Up @@ -50,3 +52,25 @@ def preferred_talks(self):
return list(preference.preferred_submission_ids)
except Preference.DoesNotExist:
return []

@context
def voting_is_enabled(self):
until = None
try:
until = self.request.event.settings.halfnarp_allow_voting_until
except AttributeError:
pass
if until is None:
if not self.request.event.current_schedule:
return True
else:
until = timezone.datetime.strptime(until, "%Y-%m-%d").astimezone(
pytz.timezone(self.request.event.timezone)
)

tz = timezone.activate(pytz.timezone(self.request.event.timezone))
now = timezone.localtime()

if now < until:
return True
return False
25 changes: 23 additions & 2 deletions pretalx_halfnarp/views/organiser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from collections import Counter

from django.views.generic import TemplateView
from django.views.generic import FormView
from django_context_decorator import context
from pretalx.common.mixins.views import EventPermissionRequired
from pretalx.submission.models import Submission

from pretalx_halfnarp.forms import HalfnarpSettingsForm
from pretalx_halfnarp.models import Preference


class OrganiserView(EventPermissionRequired, TemplateView):
class OrganiserView(EventPermissionRequired, FormView):
form_class = HalfnarpSettingsForm
permission_required = "orga.view_submissions"
template_name = "pretalx_halfnarp/organiser.html"

Expand All @@ -35,3 +37,22 @@ def most_preferred_submissions(self):
@context
def most_correlated_submissions(self):
return []

def form_valid(self, form):
form.save()
return super().form_valid(form)

def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
return {
"obj": self.request.event,
"attribute_name": "settings",
"locales": self.request.event.locales,
**kwargs,
}

def get_object(self):
return self.request.event

def get_success_url(self):
return self.request.path

0 comments on commit 95d3fec

Please sign in to comment.