Newer
Older
from django.utils.translation import gettext_lazy as _

Jonathan Weth
committed
from calendarweek import CalendarWeek
from aleksis.apps.chronos.models import LessonPeriod

Jonathan Weth
committed
from aleksis.core.util.core_helpers import get_site_preferences
def isidentifier(value: str) -> bool:
return value.isidentifier()
class ExcuseType(ExtensibleModel):
"""An type of excuse.
Can be used to count different types of absences separately.
"""
short_name = models.CharField(
max_length=255, unique=True, verbose_name=_("Short name")
)
name = models.CharField(max_length=255, unique=True, verbose_name=_("Name"))
def __str__(self):
return f"{self.name} ({self.short_name})"
@property
def count_label(self):
return f"{self.short_name}_count"
class Meta:
ordering = ["name"]
verbose_name = _("Excuse type")
verbose_name_plural = _("Excuse types")
"""A personal note about a single person.
Used in the class register to note absences, excuses
and remarks about a student in a single lesson period.
person = models.ForeignKey(
"core.Person", models.CASCADE, related_name="personal_notes"
)
groups_of_person = models.ManyToManyField("core.Group", related_name="+")
week = models.IntegerField()
lesson_period = models.ForeignKey(
"chronos.LessonPeriod", models.CASCADE, related_name="personal_notes"
)
absent = models.BooleanField(default=False)
late = models.IntegerField(default=0)
excused = models.BooleanField(default=False)
excuse_type = models.ForeignKey(
ExcuseType,
on_delete=models.SET_NULL,
null=True,
blank=True,
verbose_name=_("Excuse type"),
)
remarks = models.CharField(max_length=200, blank=True)
extra_marks = models.ManyToManyField(
"ExtraMark", null=True, blank=True, verbose_name=_("Extra marks")
)
def save(self, *args, **kwargs):
if self.excuse_type:
self.excused = True
super().save(*args, **kwargs)
verbose_name = _("Personal note")
verbose_name_plural = _("Personal notes")
unique_together = [["lesson_period", "week", "person"]]
ordering = [
"lesson_period__lesson__validity__date_start",
"week",
"lesson_period__period__weekday",
"lesson_period__period__period",
"person__last_name",
"person__first_name",
]
"""A documentation on a single lesson period.
Non-personal, includes the topic and homework of the lesson.
week = models.IntegerField()
"chronos.LessonPeriod", models.CASCADE, related_name="documentations"
)
topic = models.CharField(verbose_name=_("Lesson topic"), max_length=200, blank=True)
homework = models.CharField(verbose_name=_("Homework"), max_length=200, blank=True)
group_note = models.CharField(
verbose_name=_("Group note"), max_length=200, blank=True
)

Jonathan Weth
committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def _take_over_data(self):
"""Take over data to the next lesson, if exists and data are not already set.
Can be deactivated using site preference ``alsijil__take_over_double``.
"""
if get_site_preferences()["alsijil__take_over_double"] and (
self.topic or self.homework or self.group_note
):
try:
second_lesson = LessonPeriod.objects.get(
lesson=self.lesson_period.lesson,
period__weekday=self.lesson_period.period.weekday,
period__period=self.lesson_period.period.period + 1,
)
lesson_documentation = second_lesson.get_or_create_lesson_documentation(
CalendarWeek(
week=self.week,
year=self.lesson_period.lesson.get_year(self.week),
)
)
changed = False
if not lesson_documentation.topic:
lesson_documentation.topic = self.topic
changed = True
if not lesson_documentation.homework:
lesson_documentation.homework = self.homework
changed = True
if not lesson_documentation.group_note:
lesson_documentation.group_note = self.group_note
changed = True
if changed:
lesson_documentation.save()
except LessonPeriod.DoesNotExist:
# Do nothing if it's a single lesson
pass
def save(self, *args, **kwargs):
self._take_over_data()
super().save(*args, **kwargs)
verbose_name = _("Lesson documentation")
verbose_name_plural = _("Lesson documentations")
unique_together = [["lesson_period", "week"]]
ordering = [
"lesson_period__lesson__validity__date_start",
"week",
"lesson_period__period__weekday",
"lesson_period__period__period",
]
class ExtraMark(ExtensibleModel):
"""A model for extra marks.
Can be used for lesson-based counting of things (like forgotten homework).
"""
short_name = models.CharField(
max_length=255, unique=True, verbose_name=_("Short name")
)
name = models.CharField(max_length=255, unique=True, verbose_name=_("Name"))
def __str__(self):
return f"{self.name}"