Skip to content
Snippets Groups Projects
Commit 7afa58a9 authored by Jonathan Weth's avatar Jonathan Weth :keyboard: Committed by Hangzhi Yu
Browse files

Document Holiday model and update changelog

parent cb9dc200
No related branches found
No related tags found
1 merge request!1148Calendar events and iCal feeds
......@@ -29,6 +29,7 @@ Added
* GraphQL queries and mutations for core data management
* [Dev] Introduce new mechanism to register classes over all apps.
* Data template for `room` model used for haystack search indexing moved to core.
* Introduce Holiday model to track information about holidays.
Changed
~~~~~~~
......
......@@ -1590,15 +1590,17 @@ class BirthdayEvent(CalendarEventMixin):
class Holiday(CalendarEvent):
"""Holiday model for keeping track of school holidays."""
name = "holidays"
verbose_name = _("Holidays")
@classmethod
def value_title(cls, reference_object):
def value_title(cls, reference_object: "Holiday") -> str:
return reference_object.holiday_name
@classmethod
def value_description(cls, reference_object):
def value_description(cls, reference_object: "Holiday") -> str:
return ""
objects = PolymorphicCurrentSiteManager.from_queryset(HolidayQuerySet)()
......@@ -1606,12 +1608,14 @@ class Holiday(CalendarEvent):
holiday_name = models.CharField(verbose_name=_("Name"), max_length=255)
def get_days(self) -> Iterator[date]:
"""Get all days included in the holiday."""
delta = self.date_end - self.date_start
for i in range(delta.days + 1):
yield self.date_start + timedelta(days=i)
@classmethod
def on_day(cls, day: date) -> Optional["Holiday"]:
"""Get the holiday that is active on a given day."""
holidays = cls.objects.on_day(day)
if holidays.exists():
return holidays[0]
......@@ -1620,6 +1624,7 @@ class Holiday(CalendarEvent):
@classmethod
def in_week(cls, week: CalendarWeek) -> dict[int, Optional["Holiday"]]:
"""Get the holidays that are active in a given week."""
per_weekday = {}
holidays = Holiday.objects.in_week(week)
......
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