Skip to content
Snippets Groups Projects
Commit d0355a61 authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Use optional type annotations

parent c4ccb64d
No related branches found
No related tags found
1 merge request!113Resolve "Review permissions"
from typing import Optional from typing import Optional
from django.contrib.auth.models import User
from django.db.models import Count, Q from django.db.models import Count, Q
from django.http import HttpRequest, HttpResponseNotFound from django.http import HttpRequest, HttpResponseNotFound
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from guardian.core import ObjectPermissionChecker from guardian.core import ObjectPermissionChecker
from typing import TYPE_CHECKING
from aleksis.core.models import Group, Person from aleksis.core.models import Group, Person
from aleksis.core.util.predicates import check_global_permission from aleksis.core.util.predicates import check_global_permission
...@@ -13,6 +13,11 @@ from aleksis.core.util.predicates import check_global_permission ...@@ -13,6 +13,11 @@ from aleksis.core.util.predicates import check_global_permission
from ..managers import TimetableType from ..managers import TimetableType
from ..models import LessonPeriod, LessonSubstitution, Room from ..models import LessonPeriod, LessonSubstitution, Room
if TYPE_CHECKING:
from django.contrib.auth import get_user_model
User = get_user_model() # noqa
def get_el_by_pk( def get_el_by_pk(
request: HttpRequest, request: HttpRequest,
...@@ -46,7 +51,7 @@ def get_substitution_by_id(request: HttpRequest, id_: int, week: int): ...@@ -46,7 +51,7 @@ def get_substitution_by_id(request: HttpRequest, id_: int, week: int):
).first() ).first()
def get_teachers(user: User): def get_teachers(user: "User"):
"""Get the teachers whose timetables are allowed to be seen by current user.""" """Get the teachers whose timetables are allowed to be seen by current user."""
checker = ObjectPermissionChecker(user) checker = ObjectPermissionChecker(user)
...@@ -70,7 +75,7 @@ def get_teachers(user: User): ...@@ -70,7 +75,7 @@ def get_teachers(user: User):
return teachers return teachers
def get_classes(user: User): def get_classes(user: "User"):
"""Get the classes whose timetables are allowed to be seen by current user.""" """Get the classes whose timetables are allowed to be seen by current user."""
checker = ObjectPermissionChecker(user) checker = ObjectPermissionChecker(user)
...@@ -104,7 +109,7 @@ def get_classes(user: User): ...@@ -104,7 +109,7 @@ def get_classes(user: User):
return classes return classes
def get_rooms(user: User): def get_rooms(user: "User"):
"""Get the rooms whose timetables are allowed to be seen by current user.""" """Get the rooms whose timetables are allowed to be seen by current user."""
checker = ObjectPermissionChecker(user) checker = ObjectPermissionChecker(user)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment