Skip to content

Commit

Permalink
Add support for limiting to certain session types
Browse files Browse the repository at this point in the history
This is similar to limiting to by tracks.

Internally in the code it's not called "session", but "submission" type,
that naming is preserved throughout the code. The name "session" is used
for using facing parts like help messages.

Closes pretalx#26.
  • Loading branch information
vmx committed Sep 30, 2023
1 parent 76d5f30 commit ceaa4d1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pretalx_public_voting/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class PublicVotingSettingsForm(I18nModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["limit_tracks"].queryset = self.instance.event.tracks.all()
self.fields[
"limit_submission_types"
].queryset = self.instance.event.submission_types.all()
minimum = self.instance.min_score
maximum = self.instance.max_score
for number in range(abs(maximum - minimum + 1)):
Expand Down Expand Up @@ -155,6 +158,7 @@ class Meta:
"show_session_image",
"show_session_description",
"limit_tracks",
"limit_submission_types",
"allowed_emails",
"min_score",
"max_score",
Expand All @@ -163,7 +167,9 @@ class Meta:
"start": forms.DateTimeInput(attrs={"class": "datetimepickerfield"}),
"end": forms.DateTimeInput(attrs={"class": "datetimepickerfield"}),
"limit_tracks": forms.SelectMultiple(attrs={"class": "select2"}),
"limit_session_types": forms.SelectMultiple(attrs={"class": "select2"}),
}
field_classes = {
"limit_tracks": SafeModelMultipleChoiceField,
"limit_submission_types": SafeModelMultipleChoiceField,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2023-09-30 17:09

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("submission", "0073_track_position"),
("pretalx_public_voting", "0006_publicvotingsettings_limit_tracks"),
]

operations = [
migrations.AddField(
model_name="publicvotingsettings",
name="limit_submission_types",
field=models.ManyToManyField(to="submission.submissiontype"),
),
]
6 changes: 6 additions & 0 deletions pretalx_public_voting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class PublicVotingSettings(models.Model):
limit_tracks = models.ManyToManyField(
to="submission.Track", verbose_name=_("Limit to tracks"), blank=True
)
limit_submission_types = models.ManyToManyField(
to="submission.SubmissionType",
verbose_name=_("Limit to session types"),
blank=True,
help_text=_("If no session type is selected, then all submission are shown."),
)

@cached_property
def allowed_email_list(self):
Expand Down
5 changes: 5 additions & 0 deletions pretalx_public_voting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def get_queryset(self):
tracks = self.request.event.public_vote_settings.limit_tracks.all()
if tracks:
base_qs = base_qs.filter(track__in=tracks)
submission_types = (
self.request.event.public_vote_settings.limit_submission_types.all()
)
if submission_types:
base_qs = base_qs.filter(submission_type__in=submission_types)
submission_pks = list(base_qs.values_list("pk", flat=True))
random.seed(self.hashed_email)
random.shuffle(submission_pks)
Expand Down

0 comments on commit ceaa4d1

Please # to comment.