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

Add more detailed properties to LessonEvent

parent b9f4bc21
No related branches found
No related tags found
1 merge request!301New data model based on calendar events
......@@ -2,6 +2,7 @@
from __future__ import annotations
import os
import itertools
from datetime import date, datetime, time, timedelta
from itertools import chain
from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union
......@@ -1367,7 +1368,7 @@ class ChronosGlobalPermissions(GlobalPermissionModel):
class LessonEvent(CalendarEvent):
name = "lesson"
verbose_name = _("Lesson")
verbose_name = _("Lessons")
title = models.CharField(verbose_name=_("Name"), max_length=255, blank=True)
......@@ -1402,8 +1403,24 @@ class LessonEvent(CalendarEvent):
null=True,
)
@property
def all_members(self: "LessonEvent") -> list[Person]:
return list(itertools.chain(*[list(g.members.all()) for g in self.groups.all()]))
@property
def group_names(self: "LessonEvent") -> str:
return ", ".join([g.name for g in self.groups.all()])
@property
def teacher_names(self: "LessonEvent") -> str:
return ", ".join([t.full_name for t in self.teachers.all()])
@property
def room_names(self: "LessonEvent") -> str:
return ", ".join([r.name for r in self.rooms.all()])
@classmethod
def value_title(cls, reference_object: "CalendarEvent") -> str:
def value_title(cls, reference_object: "LessonEvent") -> str:
"""Get the title of the event."""
if reference_object.title:
return reference_object.title
......@@ -1411,17 +1428,17 @@ class LessonEvent(CalendarEvent):
return (
reference_object.subject.name
+ " · "
+ ", ".join([g.name for g in reference_object.groups.all()])
+ reference_object.group_names
)
return _("Lesson")
@classmethod
def value_description(cls, reference_object: "CalendarEvent") -> str:
return ""
def value_description(cls, reference_object: "LessonEvent") -> str:
return render_to_string("chronos/lesson_event_description.txt", {"event": reference_object})
@classmethod
def value_color(cls, reference_object: "CalendarEvent") -> str:
def value_color(cls, reference_object: "LessonEvent") -> str:
"""Get the color of the event."""
return (
reference_object.subject.colour_bg
......@@ -1429,6 +1446,24 @@ class LessonEvent(CalendarEvent):
else super().value_color(reference_object)
)
@classmethod
def value_organizer(cls, reference_object: "LessonEvent") -> 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:
"""Get the attendees of the event."""
# FIXME: Permissions
attendees = [t.get_vcal_address(role="CHAIR") for t in reference_object.teachers.all()] + [g.get_vcal_address(role="REQ-PARTICIPANT") for g in reference_object.all_members]
return [a for a in attendees if a]
@classmethod
def value_location(cls, reference_object: "LessonEvent") -> str:
"""Get the location of the event."""
return ", ".join([r.name for r in reference_object.rooms.all()])
@classmethod
def get_objects(cls, request) -> Iterable:
"""Return all objects that should be included in the calendar."""
......
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