Skip to content

Commit a27f9cc

Browse files
committed
Type ExamFacilityMiddleWare
1 parent fbcc5c4 commit a27f9cc

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

course/exam.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
THE SOFTWARE.
2424
"""
2525

26+
2627
from collections.abc import Collection
2728
from dataclasses import dataclass
2829
from typing import TYPE_CHECKING, cast
@@ -40,6 +41,7 @@
4041
)
4142
from django.db import transaction
4243
from django.db.models import Q
44+
from django.http.request import HttpRequest
4345
from django.shortcuts import get_object_or_404, redirect, render # noqa
4446
from django.urls import reverse
4547
from django.utils.html import escape
@@ -695,15 +697,19 @@ def check_in_for_exam(request: http.HttpRequest) -> http.HttpResponse:
695697
# }}}
696698

697699

698-
def is_from_exams_only_facility(request):
700+
def is_from_exams_only_facility(request: HttpRequest) -> bool:
701+
request = cast(RelateHttpRequest, request)
702+
699703
from course.utils import get_facilities_config
700-
for name, props in get_facilities_config(request).items():
701-
if not props.get("exams_only", False):
702-
continue
704+
facilities_config = get_facilities_config(request)
705+
if facilities_config:
706+
for name, props in facilities_config.items():
707+
if not props.get("exams_only", False):
708+
continue
703709

704-
# By now we know that this facility is exams-only
705-
if name in request.relate_facilities:
706-
return True
710+
# By now we know that this facility is exams-only
711+
if name in request.relate_facilities:
712+
return True
707713

708714
return False
709715

@@ -723,7 +729,7 @@ class ExamFacilityMiddleware:
723729
def __init__(self, get_response):
724730
self.get_response = get_response
725731

726-
def __call__(self, request):
732+
def __call__(self, request: http.HttpRequest) -> http.HttpResponse:
727733
exams_only = is_from_exams_only_facility(request)
728734

729735
if not exams_only:

0 commit comments

Comments
 (0)