"...0d0cea2424ae97b27447dc64a7dbfae83c036c45b403392f0e8ba.png" did not exist on "master"
Newer
Older

Jonathan Weth
committed
from typing import Optional, Union
from django.utils.translation import gettext_lazy as _
from jsonstore import BooleanField
from aleksis.core.models import Announcement, Group, Person
from .models import Lesson, LessonPeriod, Subject
def is_teacher(self):
return self.lesson_periods_as_teacher.exists()
def timetable_type(self) -> Optional[TimetableType]:

Jonathan Weth
committed
if self.is_teacher:

Jonathan Weth
committed
elif self.primary_group:

Jonathan Weth
committed
else:
return None

Jonathan Weth
committed
def timetable_object(self) -> Optional[Union[Group, Person]]:
"""Return the object which has the user's timetable."""

Jonathan Weth
committed
type_ = self.timetable_type

Jonathan Weth
committed
return self

Jonathan Weth
committed
return self.primary_group
else:
return None
def lessons_as_participant(self):
"""Return a `QuerySet` containing all `Lesson`s this person participates in (as student).
.. note:: Only available when AlekSIS-App-Chronos is installed.
:Date: 2019-11-07
:Authors:
- Dominik George <dominik.george@teckids.org>
"""
def lesson_periods_as_participant(self):
"""Return a `QuerySet` containing all `LessonPeriod`s this person participates in (as student).
.. note:: Only available when AlekSIS-App-Chronos is installed.
:Date: 2019-11-07
:Authors:
- Dominik George <dominik.george@teckids.org>
"""
return LessonPeriod.objects.filter(lesson__groups__members=self)
def lesson_periods_as_teacher(self):
"""Return a `QuerySet` containing all `Lesson`s this person gives (as teacher).
.. note:: Only available when AlekSIS-App-Chronos is installed.
:Date: 2019-11-07
:Authors:
- Dominik George <dominik.george@teckids.org>
"""
return LessonPeriod.objects.filter(lesson__teachers=self)
def for_timetables(cls):
"""Return all announcements that should be shown in timetable views."""
return cls.objects.filter(show_in_timetables=True)
Announcement.class_method(for_timetables)
show_in_timetables=BooleanField(
verbose_name=_("Show announcement in timetable views?")
)
Group.foreign_key("subject", Subject, related_name="groups")