8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-30 08:32:26 +00:00

Add preferences dormitory choice on displayed room states

This commit is contained in:
Gabriel Detraz 2020-09-04 20:44:55 +02:00
parent 9eca19e176
commit 2d4c94243b
2 changed files with 7 additions and 4 deletions

View file

@ -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,

View file

@ -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)