From f16d9ed7250a97301bbabcf435ae58962ae19577 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sun, 8 Dec 2024 20:25:17 +0100 Subject: [PATCH] Reformat and fix lint --- .../absences/ManageStudentsDialog.vue | 5 +- .../statistics/StatisticsAbsencesCard.vue | 2 +- aleksis/apps/alsijil/frontend/index.js | 1 - aleksis/apps/alsijil/managers.py | 3 +- aleksis/apps/alsijil/models.py | 4 +- aleksis/apps/alsijil/schema/absences.py | 3 +- aleksis/apps/alsijil/tasks.py | 8 ++-- aleksis/apps/alsijil/util/predicates.py | 46 +++++++------------ aleksis/apps/alsijil/views.py | 6 +-- 9 files changed, 30 insertions(+), 48 deletions(-) diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/absences/ManageStudentsDialog.vue b/aleksis/apps/alsijil/frontend/components/coursebook/absences/ManageStudentsDialog.vue index 1fdbd333e..c165cec1f 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/absences/ManageStudentsDialog.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/absences/ManageStudentsDialog.vue @@ -8,10 +8,7 @@ import MobileFullscreenDialog from "aleksis.core/components/generic/dialogs/Mobi import updateParticipationMixin from "./updateParticipationMixin.js"; import deepSearchMixin from "aleksis.core/mixins/deepSearchMixin.js"; import LessonInformation from "../documentation/LessonInformation.vue"; -import { - extendParticipationStatuses, - updateParticipationStatuses, -} from "./participationStatus.graphql"; +import { extendParticipationStatuses } from "./participationStatus.graphql"; import SlideIterator from "aleksis.core/components/generic/SlideIterator.vue"; import PersonalNotes from "../personal_notes/PersonalNotes.vue"; import PersonalNoteChip from "../personal_notes/PersonalNoteChip.vue"; diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsAbsencesCard.vue b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsAbsencesCard.vue index fb8d90a6a..8be29a0a2 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsAbsencesCard.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsAbsencesCard.vue @@ -5,7 +5,7 @@ <absence-reason-chip v-for="absenceReason in absenceReasons" :key="absenceReason.id" - :absenceReason="absenceReason.absenceReason" + :absence-reason="absenceReason.absenceReason" :count="absenceReason.count" /> </v-card-text> diff --git a/aleksis/apps/alsijil/frontend/index.js b/aleksis/apps/alsijil/frontend/index.js index ac475483e..fe222f4fe 100644 --- a/aleksis/apps/alsijil/frontend/index.js +++ b/aleksis/apps/alsijil/frontend/index.js @@ -1,4 +1,3 @@ -import { hasPersonValidator } from "aleksis.core/routeValidators"; import { DateTime } from "luxon"; import { MODE } from "./components/coursebook/statistics/modes"; diff --git a/aleksis/apps/alsijil/managers.py b/aleksis/apps/alsijil/managers.py index b8d17a7aa..681e3e562 100644 --- a/aleksis/apps/alsijil/managers.py +++ b/aleksis/apps/alsijil/managers.py @@ -1,5 +1,6 @@ +from collections.abc import Sequence from datetime import date, datetime -from typing import TYPE_CHECKING, Optional, Sequence, Union +from typing import TYPE_CHECKING, Optional, Union from django.db.models import QuerySet from django.db.models.query import Prefetch diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index 7e10a80cb..2dd3deac4 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -1,5 +1,5 @@ from datetime import datetime -from typing import List, Optional +from typing import Optional from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied @@ -117,7 +117,7 @@ class Documentation(CalendarEvent): if self.course: return self.course.groups.all() - def get_teachers_short_names(self) -> List[str]: + def get_teachers_short_names(self) -> list[str]: return [teacher.short_name or teacher.name for teacher in self.teachers.all()] def __str__(self) -> str: diff --git a/aleksis/apps/alsijil/schema/absences.py b/aleksis/apps/alsijil/schema/absences.py index 28eca0172..eea8b075b 100644 --- a/aleksis/apps/alsijil/schema/absences.py +++ b/aleksis/apps/alsijil/schema/absences.py @@ -1,5 +1,4 @@ import datetime -from typing import List from django.core.exceptions import PermissionDenied @@ -28,7 +27,7 @@ class AbsencesForPersonsCreateMutation(graphene.Mutation): cls, root, info, - persons: List[str | int], + persons: list[str | int], start: datetime.datetime, end: datetime.datetime, comment: str, diff --git a/aleksis/apps/alsijil/tasks.py b/aleksis/apps/alsijil/tasks.py index 2502658de..5c0377d74 100644 --- a/aleksis/apps/alsijil/tasks.py +++ b/aleksis/apps/alsijil/tasks.py @@ -1,5 +1,5 @@ from datetime import date -from typing import List, Optional +from typing import Optional from django.db.models import Prefetch, Q from django.utils.translation import gettext as _ @@ -19,7 +19,7 @@ from .models import Documentation, ExtraMark, NewPersonalNote, ParticipationStat @recorded_task def generate_full_register_printout( - groups: List[int], + groups: list[int], file_object: int, recorder: ProgressRecorder, include_cover: Optional[bool] = True, @@ -142,9 +142,7 @@ def generate_full_register_printout( group.as_list = [group] if include_coursebook: - group.documentations = documentations.order_by( - "datetime_start" - ).prefetch_related( + group.documentations = documentations.order_by("datetime_start").prefetch_related( prefetch_notable_participations(select_related=["person"]), prefetch_personal_notes("personal_notes", select_related=["person"]), ) diff --git a/aleksis/apps/alsijil/util/predicates.py b/aleksis/apps/alsijil/util/predicates.py index 717703428..0afb92004 100644 --- a/aleksis/apps/alsijil/util/predicates.py +++ b/aleksis/apps/alsijil/util/predicates.py @@ -22,10 +22,7 @@ def is_group_owner(user: User, obj: Union[Group, Person]) -> bool: Checks whether the person linked to the user is the owner of the given group. If there isn't provided a group, it will return `False`. """ - if isinstance(obj, Group) and user.person in obj.owners.all(): - return True - - return False + return bool(isinstance(obj, Group) and user.person in obj.owners.all()) @predicate @@ -88,10 +85,7 @@ def is_group_member(user: User, obj: Union[Group, Person]) -> bool: Checks whether the person linked to the user is a member of the given group. If there isn't provided a group, it will return `False`. """ - if isinstance(obj, Group) and user.person in obj.members.all(): - return True - - return False + return bool(isinstance(obj, Group) and user.person in obj.members.all()) @predicate @@ -252,14 +246,13 @@ def can_view_any_documentation(user: User): if allowed_lesson_events.exists(): return True - if Documentation.objects.filter( - Q(teachers=user.person) - | Q(amends__in=allowed_lesson_events) - | Q(course__teachers=user.person) - ).exists(): - return True - - return False + return bool( + Documentation.objects.filter( + Q(teachers=user.person) + | Q(amends__in=allowed_lesson_events) + | Q(course__teachers=user.person) + ).exists() + ) @predicate @@ -316,27 +309,22 @@ def is_in_allowed_time_range(user: User, obj: Union[Documentation, NewPersonalNo """ if isinstance(obj, NewPersonalNote): obj = obj.documentation - if obj and ( - get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all" - or ( - get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_day" + return bool( + obj + and ( + get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all" + or get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_day" and obj.value_start_datetime(obj).date() <= localdate() - ) - or ( - get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_time" + or get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_time" and obj.value_start_datetime(obj) <= now() ) - ): - return True - return False + ) @predicate def is_in_allowed_time_range_for_participation_status(user: User, obj: Documentation): """Predicate which checks if the documentation is in the allowed time range for editing.""" - if obj and obj.value_start_datetime(obj) <= now(): - return True - return False + return bool(obj and obj.value_start_datetime(obj) <= now()) @predicate diff --git a/aleksis/apps/alsijil/views.py b/aleksis/apps/alsijil/views.py index c48c13eea..71b4cbdd6 100644 --- a/aleksis/apps/alsijil/views.py +++ b/aleksis/apps/alsijil/views.py @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any from django.core.exceptions import BadRequest, PermissionDenied from django.db.models import Q @@ -146,7 +146,7 @@ class AssignedGroupRolesView(PermissionRequiredMixin, DetailView): model = Group template_name = "alsijil/group_role/assigned_list.html" - def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: + def get_context_data(self, **kwargs: Any) -> dict[str, Any]: context = super().get_context_data() today = timezone.now().date() @@ -190,7 +190,7 @@ class AssignGroupRoleView(PermissionRequiredMixin, SuccessNextMixin, AdvancedCre kwargs["initial"] = {"role": self.role, "groups": [self.group]} return kwargs - def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: + def get_context_data(self, **kwargs: Any) -> dict[str, Any]: context = super().get_context_data(**kwargs) context["role"] = self.role context["group"] = self.group -- GitLab