Skip to content

Commit

Permalink
feat(polls): add randomization option
Browse files Browse the repository at this point in the history
  • Loading branch information
disco-io committed May 7, 2023
1 parent 3c0e29b commit 604a48e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions Ion.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ intranet/apps/polls/migrations/0009_auto_20170425_1730.py
intranet/apps/polls/migrations/0010_poll_is_secret.py
intranet/apps/polls/migrations/0011_auto_20220502_2202.py
intranet/apps/polls/migrations/0012_poll_is_election.py
intranet/apps/polls/migrations/0013_poll_is_randomized.py
intranet/apps/polls/migrations/__init__.py
intranet/apps/preferences/__init__.py
intranet/apps/preferences/fields.py
Expand Down
5 changes: 3 additions & 2 deletions intranet/apps/polls/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ def clean_description(self):

class Meta:
model = Poll
fields = ["title", "description", "start_time", "end_time", "visible", "is_secret", "is_election", "groups"]
fields = ["title", "description", "start_time", "end_time", "visible", "is_secret", "is_election", "is_randomized", "groups"]
widgets = {"description": forms.Textarea()}
labels = {"is_secret": "Secret", "is_election": "Election"}
labels = {"is_secret": "Secret", "is_election": "Election", "is_randomized": "Randomize"}
help_texts = {
"is_secret": "This will prevent Ion administrators from viewing individual users' votes.",
"is_election": "Enable election formatting and results features.",
"is_randomized": "Enable randomization of choices.",
}
18 changes: 18 additions & 0 deletions intranet/apps/polls/migrations/0013_poll_is_randomized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.17 on 2023-05-06 23:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('polls', '0012_poll_is_election'),
]

operations = [
migrations.AddField(
model_name='poll',
name='is_randomized',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions intranet/apps/polls/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Poll(models.Model):
visible = models.BooleanField(default=False)
is_secret = models.BooleanField(default=False)
is_election = models.BooleanField(default=False)
is_randomized = models.BooleanField(default=False)
groups = models.ManyToManyField(DjangoGroup, blank=True)

# Access questions through .question_set
Expand Down
2 changes: 1 addition & 1 deletion intranet/apps/polls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def poll_vote_view(request, poll_id):
for q in poll.question_set.all():
current_votes = Answer.objects.filter(user=user, question=q)

if q.type == Question.ELECTION:
if q.poll.is_randomized:
choices = q.random_choice_set
else:
choices = q.choice_set.all()
Expand Down

0 comments on commit 604a48e

Please sign in to comment.