Skip to content
Snippets Groups Projects
Verified Commit c8a299e3 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix imports and syntax

parent 78887b91
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,6 @@ from aleksis.apps.chronos.util.date import week_weekday_from_date ...@@ -12,7 +12,6 @@ from aleksis.apps.chronos.util.date import week_weekday_from_date
from aleksis.core.models import Group, Person from aleksis.core.models import Group, Person
from aleksis.core.util.core_helpers import get_site_preferences from aleksis.core.util.core_helpers import get_site_preferences
from .models import LessonPeriod
class TimetableType(Enum): class TimetableType(Enum):
......
...@@ -10,13 +10,13 @@ from .managers import TimetableType ...@@ -10,13 +10,13 @@ from .managers import TimetableType
from .models import Lesson, LessonPeriod from .models import Lesson, LessonPeriod
@Person.property @Person.property_
def is_teacher(self): def is_teacher(self):
"""Check if the user has lessons as a teacher.""" """Check if the user has lessons as a teacher."""
return self.lesson_periods_as_teacher.exists() return self.lesson_periods_as_teacher.exists()
@Person.property @Person.property_
def timetable_type(self) -> Optional[TimetableType]: def timetable_type(self) -> Optional[TimetableType]:
"""Return which type of timetable this user has.""" """Return which type of timetable this user has."""
if self.is_teacher: if self.is_teacher:
...@@ -27,7 +27,7 @@ def timetable_type(self) -> Optional[TimetableType]: ...@@ -27,7 +27,7 @@ def timetable_type(self) -> Optional[TimetableType]:
return None return None
@Person.property @Person.property_
def timetable_object(self) -> Optional[Union[Group, Person]]: def timetable_object(self) -> Optional[Union[Group, Person]]:
"""Return the object which has the user's timetable.""" """Return the object which has the user's timetable."""
type_ = self.timetable_type type_ = self.timetable_type
...@@ -40,7 +40,7 @@ def timetable_object(self) -> Optional[Union[Group, Person]]: ...@@ -40,7 +40,7 @@ def timetable_object(self) -> Optional[Union[Group, Person]]:
return None return None
@Person.property @Person.property_
def lessons_as_participant(self): def lessons_as_participant(self):
"""Return a `QuerySet` containing all `Lesson`s this person participates in (as student). """Return a `QuerySet` containing all `Lesson`s this person participates in (as student).
...@@ -53,7 +53,7 @@ def lessons_as_participant(self): ...@@ -53,7 +53,7 @@ def lessons_as_participant(self):
return Lesson.objects.filter(groups__members=self) return Lesson.objects.filter(groups__members=self)
@Person.property @Person.property_
def lesson_periods_as_participant(self): def lesson_periods_as_participant(self):
"""Return a `QuerySet` containing all `LessonPeriod`s this person participates in (as student). """Return a `QuerySet` containing all `LessonPeriod`s this person participates in (as student).
...@@ -66,7 +66,7 @@ def lesson_periods_as_participant(self): ...@@ -66,7 +66,7 @@ def lesson_periods_as_participant(self):
return LessonPeriod.objects.filter(lesson__groups__members=self) return LessonPeriod.objects.filter(lesson__groups__members=self)
@Person.property @Person.property_
def lesson_periods_as_teacher(self): def lesson_periods_as_teacher(self):
"""Return a `QuerySet` containing all `Lesson`s this person gives (as teacher). """Return a `QuerySet` containing all `Lesson`s this person gives (as teacher).
......
...@@ -114,27 +114,27 @@ class TimePeriod(ExtensibleModel): ...@@ -114,27 +114,27 @@ class TimePeriod(ExtensibleModel):
return url_prev, url_next return url_prev, url_next
@classproperty @classproperty
def period_min(self, cls) -> int: def period_min(cls) -> int:
return cls.objects.aggregate(period__min=Coalesce(Min("period"), 1)).get("period__min") return cls.objects.aggregate(period__min=Coalesce(Min("period"), 1)).get("period__min")
@classproperty @classproperty
def period_max(self, cls) -> int: def period_max(cls) -> int:
return cls.objects.aggregate(period__max=Coalesce(Max("period"), 7)).get("period__max") return cls.objects.aggregate(period__max=Coalesce(Max("period"), 7)).get("period__max")
@classproperty @classproperty
def time_min(self, cls) -> Optional[time]: def time_min(cls) -> Optional[time]:
return cls.objects.aggregate(Min("time_start")).get("time_start__min") return cls.objects.aggregate(Min("time_start")).get("time_start__min")
@classproperty @classproperty
def time_max(self, cls) -> Optional[time]: def time_max(cls) -> Optional[time]:
return cls.objects.aggregate(Max("time_end")).get("time_end__max") return cls.objects.aggregate(Max("time_end")).get("time_end__max")
@classproperty @classproperty
def weekday_min(self, cls) -> int: def weekday_min(cls) -> int:
return cls.objects.aggregate(weekday__min=Coalesce(Min("weekday"), 0)).get("weekday__min") return cls.objects.aggregate(weekday__min=Coalesce(Min("weekday"), 0)).get("weekday__min")
@classproperty @classproperty
def weekday_max(self, cls) -> int: def weekday_max(cls) -> int:
return cls.objects.aggregate(weekday__max=Coalesce(Max("weekday"), 6)).get("weekday__max") return cls.objects.aggregate(weekday__max=Coalesce(Max("weekday"), 6)).get("weekday__max")
class Meta: class Meta:
......
...@@ -2,8 +2,6 @@ from datetime import date ...@@ -2,8 +2,6 @@ from datetime import date
from django.utils.formats import date_format from django.utils.formats import date_format
from ..models import TimePeriod
def format_m2m(f, attr: str = "short_name") -> str: def format_m2m(f, attr: str = "short_name") -> str:
"""Join a attribute of all elements of a ManyToManyField.""" """Join a attribute of all elements of a ManyToManyField."""
......
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