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 @@ ...@@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import os import os
import itertools
from datetime import date, datetime, time, timedelta from datetime import date, datetime, time, timedelta
from itertools import chain from itertools import chain
from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union
...@@ -1367,7 +1368,7 @@ class ChronosGlobalPermissions(GlobalPermissionModel): ...@@ -1367,7 +1368,7 @@ class ChronosGlobalPermissions(GlobalPermissionModel):
class LessonEvent(CalendarEvent): class LessonEvent(CalendarEvent):
name = "lesson" name = "lesson"
verbose_name = _("Lesson") verbose_name = _("Lessons")
title = models.CharField(verbose_name=_("Name"), max_length=255, blank=True) title = models.CharField(verbose_name=_("Name"), max_length=255, blank=True)
...@@ -1402,8 +1403,24 @@ class LessonEvent(CalendarEvent): ...@@ -1402,8 +1403,24 @@ class LessonEvent(CalendarEvent):
null=True, 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 @classmethod
def value_title(cls, reference_object: "CalendarEvent") -> str: def value_title(cls, reference_object: "LessonEvent") -> str:
"""Get the title of the event.""" """Get the title of the event."""
if reference_object.title: if reference_object.title:
return reference_object.title return reference_object.title
...@@ -1411,17 +1428,17 @@ class LessonEvent(CalendarEvent): ...@@ -1411,17 +1428,17 @@ class LessonEvent(CalendarEvent):
return ( return (
reference_object.subject.name reference_object.subject.name
+ " · " + " · "
+ ", ".join([g.name for g in reference_object.groups.all()]) + reference_object.group_names
) )
return _("Lesson") return _("Lesson")
@classmethod @classmethod
def value_description(cls, reference_object: "CalendarEvent") -> str: def value_description(cls, reference_object: "LessonEvent") -> str:
return "" return render_to_string("chronos/lesson_event_description.txt", {"event": reference_object})
@classmethod @classmethod
def value_color(cls, reference_object: "CalendarEvent") -> str: def value_color(cls, reference_object: "LessonEvent") -> str:
"""Get the color of the event.""" """Get the color of the event."""
return ( return (
reference_object.subject.colour_bg reference_object.subject.colour_bg
...@@ -1429,6 +1446,24 @@ class LessonEvent(CalendarEvent): ...@@ -1429,6 +1446,24 @@ class LessonEvent(CalendarEvent):
else super().value_color(reference_object) 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 @classmethod
def get_objects(cls, request) -> Iterable: def get_objects(cls, request) -> Iterable:
"""Return all objects that should be included in the calendar.""" """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