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

Merge branch 'master' into feature/show-week-on-desktop

parents 3c235a8a 6e35c3e5
No related branches found
No related tags found
1 merge request!117Show full timetable on my timetable on desktop
Pipeline #5104 passed
......@@ -468,6 +468,20 @@ class LessonPeriod(ExtensibleModel, WeekAnnotationMixin):
def __str__(self) -> str:
return f"{self.period}, {self.lesson}"
@property
def _equal_lessons(self):
"""Get all lesson periods with equal lessons in the whole school term."""
qs = LessonPeriod.objects.filter(
lesson__subject=self.lesson.subject,
lesson__validity__school_term=self.lesson.validity.school_term,
)
for group in self.lesson.groups.all():
qs = qs.filter(lesson__groups=group)
for teacher in self.lesson.teachers.all():
qs = qs.filter(lesson__teachers=teacher)
return qs
@property
def next(self) -> "LessonPeriod":
"""Get next lesson period of this lesson.
......@@ -475,7 +489,7 @@ class LessonPeriod(ExtensibleModel, WeekAnnotationMixin):
.. warning::
To use this property, the provided lesson period must be annotated with a week.
"""
return LessonPeriod.objects.filter(lesson=self.lesson).next_lesson(self)
return self._equal_lessons.next_lesson(self)
@property
def prev(self) -> "LessonPeriod":
......@@ -484,7 +498,7 @@ class LessonPeriod(ExtensibleModel, WeekAnnotationMixin):
.. warning::
To use this property, the provided lesson period must be annotated with a week.
"""
return LessonPeriod.objects.filter(lesson=self.lesson).next_lesson(self, -1)
return self._equal_lessons.next_lesson(self, -1)
class Meta:
ordering = [
......
......@@ -7,6 +7,7 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache
from django_tables2 import RequestConfig
from rules.contrib.views import permission_required
......@@ -226,6 +227,7 @@ def lessons_day(
return render(request, "chronos/lessons_day.html", context)
@never_cache
@permission_required("chronos.edit_substitution", fn=get_substitution_by_id)
def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse:
"""View a form to edit a substitution lessen."""
......
This diff is collapsed.
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