Skip to content

Commit 7e52559

Browse files
committed
added exec ics
1 parent e608e2b commit 7e52559

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

events/ui.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from flask import Blueprint, abort, flash, redirect, render_template, request, url_for
44
from flask import Response as FlaskResponse
5-
from icalendar import Calendar, Event
5+
from icalendar import Calendar
6+
from icalendar import Event as ICalEvent
67
from pytz import timezone
78
from werkzeug.datastructures import ImmutableMultiDict
89
from werkzeug.wrappers import Response
@@ -26,6 +27,7 @@
2627
prepare_event,
2728
validate_colour,
2829
)
30+
from schema import Event
2931

3032
events_ui_bp = Blueprint("events_ui", __name__)
3133

@@ -347,16 +349,14 @@ def view_tag(tag: str) -> str:
347349
return render_template("events/tag.html", events=events, tag=tag_obj)
348350

349351

350-
@events_ui_bp.route("/uwcs.ics")
351-
def get_ical() -> Response:
352-
events = get_upcoming_events()
353-
352+
def get_calendar(events: list[Event]) -> Calendar:
353+
"""Get an iCal calendar from a list of events"""
354354
calendar = Calendar()
355355
calendar.add("prodid", "-//UWCS Fulcrum//EN")
356356
calendar.add("version", "2.0")
357357

358358
for event in events:
359-
ical_event = Event()
359+
ical_event = ICalEvent()
360360
ical_event.add("summary", event.name)
361361
# descriptions can be long (and markdown formatted) so do not include
362362
# ical_event.add("description", event.description)
@@ -381,6 +381,15 @@ def get_ical() -> Response:
381381
)
382382
calendar.add_component(ical_event)
383383

384+
return calendar
385+
386+
387+
@events_ui_bp.route("/uwcs.ics")
388+
def get_ics() -> Response:
389+
events = get_upcoming_events()
390+
391+
calendar = get_calendar(events)
392+
384393
return FlaskResponse(
385394
calendar.to_ical(),
386395
mimetype="text/calendar",
@@ -389,3 +398,19 @@ def get_ical() -> Response:
389398
"Cache-Control": "no-cache",
390399
},
391400
)
401+
402+
403+
@events_ui_bp.route("exec.ics")
404+
def exec_ics() -> Response:
405+
events = get_upcoming_events(include_drafts=True)
406+
407+
calendar = get_calendar(events)
408+
409+
return FlaskResponse(
410+
calendar.to_ical(),
411+
mimetype="text/calendar",
412+
headers={
413+
"Content-Disposition": 'attachment; filename="exec.ics"',
414+
"Cache-Control": "no-cache",
415+
},
416+
)

templates/upcoming.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{% endwith %}
2222
<h1>Hello World!</h1>
2323
<p class="lead">We run some events! Here are the upcoming ones:</p>
24-
<p>We also host an <i class="ph-bold ph-calendar-dots"></i> <a href="{{ url_for('events_ui.get_ical') }}">iCal feed</a> of all our events</p>
24+
<p>We also host an <i class="ph-bold ph-calendar-dots"></i> <a href="{{ url_for('events_ui.get_ics') }}">iCal feed</a> of all our events</p>
2525
{% endif %}
2626
{{ list(events, True, True, False) }}
2727
{% endblock %}

0 commit comments

Comments
 (0)