diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py index f2172e9c78cf02662c121f73d12c3babc8e04a7e..c40c6010ac323bb7950e100216a9262b6deb9cf0 100644 --- a/aleksis/apps/chronos/models.py +++ b/aleksis/apps/chronos/models.py @@ -1431,36 +1431,43 @@ class LessonEvent(CalendarEvent): return ", ".join([r.name for r in self.rooms.all()]) @classmethod - def value_title(cls, reference_object: "LessonEvent") -> str: + def value_title(cls, reference_object: "LessonEvent", request) -> str: """Get the title of the event.""" if reference_object.title: return reference_object.title elif reference_object.subject: - return reference_object.subject.name + " · " + reference_object.group_names + title = reference_object.subject.name + if request.user.person in reference_object.teachers.all(): + title += " · " + reference_object.group_names + else: + title += " · " + reference_object.teacher_names + if reference_object.rooms.all().exists(): + title += " · " + reference_object.room_names + return title return _("Lesson") @classmethod - def value_description(cls, reference_object: "LessonEvent") -> str: + def value_description(cls, reference_object: "LessonEvent", request) -> str: return render_to_string("chronos/lesson_event_description.txt", {"event": reference_object}) @classmethod - def value_color(cls, reference_object: "LessonEvent") -> str: + def value_color(cls, reference_object: "LessonEvent", request) -> str: """Get the color of the event.""" return ( reference_object.subject.colour_bg if reference_object.subject - else super().value_color(reference_object) + else super().value_color(reference_object, request) ) @classmethod - def value_organizer(cls, reference_object: "LessonEvent") -> str: + def value_organizer(cls, reference_object: "LessonEvent", request) -> str: """Get the organizer of the event.""" # TODO: Do not use the teachers as organizer, because only one organizer is allowed return [t.get_vcal_address(role="CHAIR") for t in reference_object.teachers.all()] @classmethod - def value_attendee(cls, reference_object: "LessonEvent") -> str: + def value_attendee(cls, reference_object: "LessonEvent", request) -> str: """Get the attendees of the event.""" # FIXME: Permissions attendees = [t.get_vcal_address(role="CHAIR") for t in reference_object.teachers.all()] + [ @@ -1469,12 +1476,12 @@ class LessonEvent(CalendarEvent): return [a for a in attendees if a] @classmethod - def value_location(cls, reference_object: "LessonEvent") -> str: + def value_location(cls, reference_object: "LessonEvent", request) -> str: """Get the location of the event.""" return ", ".join([r.name for r in reference_object.rooms.all()]) @classmethod - def value_status(cls, reference_object: "LessonEvent") -> str: + def value_status(cls, reference_object: "LessonEvent", request) -> str: """Get the status of the event.""" if reference_object.cancelled: return "CANCELLED" @@ -1485,7 +1492,8 @@ class LessonEvent(CalendarEvent): """Return all objects that should be included in the calendar.""" objs = super().get_objects(request) amended = objs.filter( - Q(teachers=request.user.person) | Q(groups__members=request.user.person) + Q(amended_by__isnull=False) + & (Q(teachers=request.user.person) | Q(groups__members=request.user.person)) ).values_list("amended_by__pk", flat=True) return objs.filter( Q(teachers=request.user.person) @@ -1503,13 +1511,13 @@ class SupervisionEvent(LessonEvent): verbose_name = _("Supervisions") @classmethod - def value_title(cls, reference_object: "LessonEvent") -> str: + def value_title(cls, reference_object: "LessonEvent", request) -> str: """Get the title of the event.""" return _("Supervision: {}").format(reference_object.room_names) @classmethod - def value_description(cls, reference_object: "LessonEvent") -> str: + def value_description(cls, reference_object: "LessonEvent", request) -> str: return render_to_string( "chronos/supervision_event_description.txt", {"event": reference_object} )