Skip to content

Commit 41be485

Browse files
committed
feat(polls): add randomization option
1 parent 3c0e29b commit 41be485

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

intranet/apps/polls/forms.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ def clean_description(self):
1313

1414
class Meta:
1515
model = Poll
16-
fields = ["title", "description", "start_time", "end_time", "visible", "is_secret", "is_election", "groups"]
16+
fields = ["title", "description", "start_time", "end_time", "visible", "is_secret", "is_election", "is_randomized", "groups"]
1717
widgets = {"description": forms.Textarea()}
18-
labels = {"is_secret": "Secret", "is_election": "Election"}
18+
labels = {"is_secret": "Secret", "is_election": "Election", "is_randomized": "Randomize"}
1919
help_texts = {
2020
"is_secret": "This will prevent Ion administrators from viewing individual users' votes.",
2121
"is_election": "Enable election formatting and results features.",
22+
"is_randomized": "Enable randomization of choices."
2223
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.17 on 2023-05-06 23:20
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('polls', '0012_poll_is_election'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='poll',
15+
name='is_randomized',
16+
field=models.BooleanField(default=False),
17+
),
18+
]

intranet/apps/polls/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Poll(models.Model):
7070
visible = models.BooleanField(default=False)
7171
is_secret = models.BooleanField(default=False)
7272
is_election = models.BooleanField(default=False)
73+
is_randomized = models.BooleanField(default=False)
7374
groups = models.ManyToManyField(DjangoGroup, blank=True)
7475

7576
# Access questions through .question_set

intranet/apps/polls/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def poll_vote_view(request, poll_id):
243243
for q in poll.question_set.all():
244244
current_votes = Answer.objects.filter(user=user, question=q)
245245

246-
if q.type == Question.ELECTION:
246+
if q.poll.is_randomized:
247247
choices = q.random_choice_set
248248
else:
249249
choices = q.choice_set.all()

0 commit comments

Comments
 (0)