|
| 1 | +from __future__ import annotations |
| 2 | + |
1 | 3 | from django.contrib.syndication.views import Feed |
2 | 4 |
|
| 5 | +from datetime import timedelta |
| 6 | +from typing import TYPE_CHECKING |
| 7 | + |
| 8 | +from icalendar import Calendar, Event |
| 9 | + |
| 10 | +if TYPE_CHECKING: |
| 11 | + from collections.abc import Iterable |
| 12 | + |
| 13 | + from .models import CommitFest |
| 14 | + |
3 | 15 |
|
4 | 16 | class ActivityFeed(Feed): |
5 | 17 | title = description = "Commitfest Activity Log" |
@@ -34,3 +46,31 @@ def item_link(self, item): |
34 | 46 |
|
35 | 47 | def item_pubdate(self, item): |
36 | 48 | return item["date"] |
| 49 | + |
| 50 | + |
| 51 | +def calendar(commitfests: Iterable[CommitFest]) -> Calendar: |
| 52 | + """ |
| 53 | + Build an RFC 5545 iCalendar document with one all-day VEVENT per |
| 54 | + commitfest, covering its start and end date. |
| 55 | + """ |
| 56 | + calendar = Calendar.new( |
| 57 | + prodid="-//PostgreSQL Commitfest//commitfest.postgresql.org//EN", |
| 58 | + name="PostgreSQL Commitfests", |
| 59 | + description="Start and end dates of PostgreSQL Commitfests", |
| 60 | + method="PUBLISH", |
| 61 | + ) |
| 62 | + |
| 63 | + for cf in commitfests: |
| 64 | + event = Event.new( |
| 65 | + uid=f"commitfest-{cf.name}@commitfest.postgresql.org", |
| 66 | + summary=cf.title, |
| 67 | + start=cf.startdate, |
| 68 | + # DTEND is exclusive for all-day events, so add a day to make the |
| 69 | + # last day of the commitfest show up as included on the calendar. |
| 70 | + end=cf.enddate + timedelta(days=1), |
| 71 | + description=f"Status: {cf.statusstring}", |
| 72 | + url=f"https://commitfest.postgresql.org/{cf.id}/", |
| 73 | + ) |
| 74 | + calendar.add_component(event) |
| 75 | + |
| 76 | + return calendar |
0 commit comments