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

Build substitutions table with current changes that are no amends

parent 091797f8
No related branches found
No related tags found
1 merge request!394Show events with current changes in substitutions table
...@@ -212,6 +212,15 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet): ...@@ -212,6 +212,15 @@ class LessonEventQuerySet(RecurrencePolymorphicQuerySet):
"""Get all lesson events that are amending other events.""" """Get all lesson events that are amending other events."""
return self.filter(self.amending_q()) return self.filter(self.amending_q())
@staticmethod
def current_changes_q() -> Q:
"""Get all lesson events that are current changes."""
return Q(amends__isnull=False) | Q(current_change=True)
def current_changes(self) -> "LessonEventQuerySet":
"""Get all lesson events that are current changes."""
return self.filter(self.current_changes_q())
class SupervisionEventQuerySet(LessonEventQuerySet): class SupervisionEventQuerySet(LessonEventQuerySet):
pass pass
...@@ -215,6 +215,9 @@ class LessonEvent(CalendarEvent): ...@@ -215,6 +215,9 @@ class LessonEvent(CalendarEvent):
blank=True, blank=True,
) )
# current_change=True will show this event in substitutions table
current_change = models.BooleanField(default=False, verbose_name=_("Is this a current change?"))
@property @property
def actual_groups(self: LessonEvent) -> QuerySet[Group]: def actual_groups(self: LessonEvent) -> QuerySet[Group]:
"""Get list of the groups of this lesson event.""" """Get list of the groups of this lesson event."""
...@@ -431,6 +434,7 @@ class LessonEvent(CalendarEvent): ...@@ -431,6 +434,7 @@ class LessonEvent(CalendarEvent):
not_amended = params.get("not_amended", False) not_amended = params.get("not_amended", False)
not_amending = params.get("not_amending", False) not_amending = params.get("not_amending", False)
amending = params.get("amending", False) amending = params.get("amending", False)
current_changes = params.get("current_changes", False)
own = params.get("own", False) own = params.get("own", False)
if not_amended: if not_amended:
...@@ -442,6 +446,9 @@ class LessonEvent(CalendarEvent): ...@@ -442,6 +446,9 @@ class LessonEvent(CalendarEvent):
if amending: if amending:
q = q & LessonEventQuerySet.amending_q() q = q & LessonEventQuerySet.amending_q()
if current_changes:
q = q & LessonEventQuerySet.current_changes_q()
if request and "own" in params: if request and "own" in params:
if own: if own:
q = q & LessonEventQuerySet.for_person_q(request.user.person) q = q & LessonEventQuerySet.for_person_q(request.user.person)
......
...@@ -12,19 +12,21 @@ def build_substitutions_list(wanted_day: date) -> tuple[list[dict], set[Person], ...@@ -12,19 +12,21 @@ def build_substitutions_list(wanted_day: date) -> tuple[list[dict], set[Person],
lesson_events = LessonEvent.get_single_events( lesson_events = LessonEvent.get_single_events(
datetime.combine(wanted_day, time.min), datetime.combine(wanted_day, time.min),
datetime.combine(wanted_day, time.max), datetime.combine(wanted_day, time.max),
params={"amending": True}, params={"current_changes": True},
with_reference_object=True, with_reference_object=True,
) )
for lesson_event in lesson_events: for lesson_event in lesson_events:
ref_object = lesson_event["REFERENCE_OBJECT"]
affected_teachers.update(lesson_event["REFERENCE_OBJECT"].teachers.all()) affected_teachers.update(lesson_event["REFERENCE_OBJECT"].teachers.all())
affected_teachers.update(lesson_event["REFERENCE_OBJECT"].amends.teachers.all())
affected_groups.update(lesson_event["REFERENCE_OBJECT"].groups.all()) affected_groups.update(lesson_event["REFERENCE_OBJECT"].groups.all())
affected_groups.update(lesson_event["REFERENCE_OBJECT"].amends.groups.all()) if ref_object.amends:
affected_teachers.update(ref_object.amends.teachers.all())
affected_groups.update(ref_object.amends.groups.all())
row = { row = {
"type": "substitution", "type": "substitution",
"sort_a": lesson_event["REFERENCE_OBJECT"].group_names, "sort_a": ref_object.group_names,
"sort_b": str(lesson_event["DTSTART"]), "sort_b": str(lesson_event["DTSTART"]),
"el": lesson_event, "el": lesson_event,
} }
...@@ -34,13 +36,15 @@ def build_substitutions_list(wanted_day: date) -> tuple[list[dict], set[Person], ...@@ -34,13 +36,15 @@ def build_substitutions_list(wanted_day: date) -> tuple[list[dict], set[Person],
supervision_events = SupervisionEvent.get_single_events( supervision_events = SupervisionEvent.get_single_events(
datetime.combine(wanted_day, time.min), datetime.combine(wanted_day, time.min),
datetime.combine(wanted_day, time.max), datetime.combine(wanted_day, time.max),
params={"amending": True}, params={"current_changes": True},
with_reference_object=True, with_reference_object=True,
) )
for supervision_event in supervision_events: for supervision_event in supervision_events:
affected_teachers.update(supervision_event["REFERENCE_OBJECT"].teachers.all()) ref_object = supervision_event["REFERENCE_OBJECT"]
affected_teachers.update(supervision_event["REFERENCE_OBJECT"].amends.teachers.all()) affected_teachers.update(ref_object.teachers.all())
if ref_object.amends:
affected_teachers.update(ref_object.amends.teachers.all())
row = { row = {
"type": "supervision_substitution", "type": "supervision_substitution",
......
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