Skip to content
Snippets Groups Projects
Commit e05911bf authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Allow to filter types for slides with "and" instead of "or"

Solution only works in specific cases, revision needed after the current event
parent bced419b
No related branches found
No related tags found
1 merge request!283[Tmp] Allow to filter types for slides with "and" instead of "or"
Pipeline #290667 passed
......@@ -181,6 +181,12 @@ class SlideExportForm(AdminIntermediateForm):
widget=forms.CheckboxSelectMultiple,
choices=[],
required=False)
types_all_selected_only = forms.BooleanField(
initial=False,
label=_("Only show AKs with all selected types?"),
help_text=_("If checked, only AKs that have all selected types will be shown in the slides. "
"If unchecked, AKs with at least one of the selected types will be shown."),
required=False)
presentation_mode = forms.TypedChoiceField(
initial=False,
label=_("Presentation only?"),
......
......@@ -211,7 +211,8 @@ class Event(models.Model):
return event
def get_categories_with_aks(self, wishes_seperately=False,
filter_func=lambda ak: True, hide_empty_categories=False, types=None):
filter_func=lambda ak: True, hide_empty_categories=False,
types=None, types_all_selected_only=False):
"""
Get AKCategories as well as a list of AKs belonging to the category for this event
......@@ -223,6 +224,8 @@ class Event(models.Model):
:type hide_empty_categories: bool
:param types: Optional list of AK types to filter by, if None, all types are included
:type types: list[AKType] | None
:param types_all_selected_only: If True, only include AKs that have all of the selected types at the same time
:type types_all_selected_only: bool
:return: list of category-AK-list-tuples, optionally the additional list of AK wishes
:rtype: list[(AKCategory, list[AK])] [, list[AK]]
"""
......@@ -246,6 +249,9 @@ class Event(models.Model):
s = category.ak_set
if types is not None:
s = s.filter(types__in=types).distinct()
if types_all_selected_only:
# TODO fix - this only works in very specific cases
s = s.annotate(Count('types')).filter(types__count=len(types))
return s.select_related('event').prefetch_related('owners', 'akslot_set', 'types').all()
if wishes_seperately:
......
......@@ -46,6 +46,7 @@ class ExportSlidesView(EventSlugMixin, IntermediateAdminView):
]
else:
form.fields['types'].widget = form.fields['types'].hidden_widget()
form.fields['types_all_selected_only'].widget = form.fields['types_all_selected_only'].hidden_widget()
return form
def form_valid(self, form):
......@@ -82,12 +83,14 @@ class ExportSlidesView(EventSlugMixin, IntermediateAdminView):
types = AKType.objects.filter(id__in=form.cleaned_data['types'])
names_string = ', '.join(AKType.objects.get(pk=t).name for t in form.cleaned_data['types'])
types_filter_string = f"[{_('Type(s)')}: {names_string}]"
types_all_selected_only = form.cleaned_data['types_all_selected_only']
# Get all relevant AKs (wishes separately, and either all AKs or only those who should directly or indirectly
# be presented when restriction setting was chosen)
categories_with_aks, ak_wishes = self.event.get_categories_with_aks(wishes_seperately=True, filter_func=lambda
ak: not RESULT_PRESENTATION_MODE or (ak.present or (ak.present is None and ak.category.present_by_default)),
types=types)
types=types,
types_all_selected_only=types_all_selected_only)
# Create context for LaTeX rendering
context = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment