From 7c9db55d79fdfb1475c4637fa8b6a8060077ad94 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 4 Sep 2020 20:44:55 +0200 Subject: [PATCH] Add preferences dormitory choice on displayed room states --- multi_op/forms.py | 3 ++- multi_op/views.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/multi_op/forms.py b/multi_op/forms.py index 08bc9123..2de9eac1 100644 --- a/multi_op/forms.py +++ b/multi_op/forms.py @@ -34,12 +34,13 @@ from django.utils.translation import ugettext_lazy as _ from topologie.models import Dormitory +from .preferences.models import MultiopOption class DormitoryForm(FormRevMixin, Form): """Form used to select dormitories.""" dormitory = forms.ModelMultipleChoiceField( - queryset=Dormitory.objects.all(), + queryset=MultiopOption.get_cached_value("enabled_dorm").all(), label=_("Dormitory"), widget=forms.CheckboxSelectMultiple, required=False, diff --git a/multi_op/views.py b/multi_op/views.py index 0b040779..01e55aae 100644 --- a/multi_op/views.py +++ b/multi_op/views.py @@ -58,9 +58,9 @@ def display_rooms_connection(request, dormitory=None): dormitory: Dormitory, the dormitory used to filter rooms. If no dormitory is given, all rooms are displayed (default: None). """ - room_list = Room.objects.select_related("building__dormitory").order_by( - "building_dormitory", "port" - ) + room_list = Room.objects.select_related("building__dormitory").filter( + building__dormitory__in=MultiopOption.get_cached_value("enabled_dorm").all() + ).order_by("building_dormitory", "port") if dormitory: room_list = room_list.filter(building__dormitory=dormitory) room_list = SortTable.sort( @@ -113,6 +113,7 @@ def aff_pending_connection(request): Room.objects.select_related("building__dormitory") .filter(port__isnull=True) .filter(adherent__in=all_has_access()) + .filter(building__dormitory__in=MultiopOption.get_cached_value("enabled_dorm").all()) .order_by("building_dormitory", "port") ) dormitory_form = DormitoryForm(request.POST or None) @@ -150,6 +151,7 @@ def aff_pending_disconnection(request): Room.objects.select_related("building__dormitory") .filter(port__isnull=False) .exclude(Q(adherent__in=all_has_access()) | Q(adherent__in=all_adherent())) + .filter(building__dormitory__in=MultiopOption.get_cached_value("enabled_dorm").all()) .order_by("building_dormitory", "port") ) dormitory_form = DormitoryForm(request.POST or None)