From ceaa4d1fa31b7190fbb115981360e243bb792dac Mon Sep 17 00:00:00 2001 From: Volker Mische Date: Sat, 30 Sep 2023 20:43:28 +0200 Subject: [PATCH] Add support for limiting to certain session types 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 #26. --- pretalx_public_voting/forms.py | 6 ++++++ ...licvotingsettings_limit_submission_types.py | 18 ++++++++++++++++++ pretalx_public_voting/models.py | 6 ++++++ pretalx_public_voting/views.py | 5 +++++ 4 files changed, 35 insertions(+) create mode 100644 pretalx_public_voting/migrations/0007_publicvotingsettings_limit_submission_types.py diff --git a/pretalx_public_voting/forms.py b/pretalx_public_voting/forms.py index ed754f3..cca60c1 100644 --- a/pretalx_public_voting/forms.py +++ b/pretalx_public_voting/forms.py @@ -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)): @@ -155,6 +158,7 @@ class Meta: "show_session_image", "show_session_description", "limit_tracks", + "limit_submission_types", "allowed_emails", "min_score", "max_score", @@ -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, } diff --git a/pretalx_public_voting/migrations/0007_publicvotingsettings_limit_submission_types.py b/pretalx_public_voting/migrations/0007_publicvotingsettings_limit_submission_types.py new file mode 100644 index 0000000..c35629c --- /dev/null +++ b/pretalx_public_voting/migrations/0007_publicvotingsettings_limit_submission_types.py @@ -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"), + ), + ] diff --git a/pretalx_public_voting/models.py b/pretalx_public_voting/models.py index ec562fa..801bfb9 100644 --- a/pretalx_public_voting/models.py +++ b/pretalx_public_voting/models.py @@ -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): diff --git a/pretalx_public_voting/views.py b/pretalx_public_voting/views.py index 2bad87d..3432d7a 100644 --- a/pretalx_public_voting/views.py +++ b/pretalx_public_voting/views.py @@ -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)