Commit a50a8a01 authored by Robin Sonnabend's avatar Robin Sonnabend

Add (public) ical appointment calendar

parent 679538f4
......@@ -1809,17 +1809,9 @@ def feed_appointments_atom(protocoltype):
mimetype="application/atom+xml")
@app.route("/feed/appointments/ical/<int:protocoltype_id>")
@db_lookup(ProtocolType)
def feed_appointments_ical(protocoltype):
if not protocoltype.has_public_anonymous_view_right():
abort(403)
protocols = [
protocol for protocol in protocoltype.protocols
if not protocol.is_done()
]
def make_calendar_from_protocols(protocols, summary):
calendar = icalendar.Calendar()
calendar["summary"] = protocoltype.short_name
calendar["summary"] = summary
calendar["prodid"] = "Protokollsystem 3"
calendar["version"] = "2.0"
for protocol in protocols:
......@@ -1830,7 +1822,7 @@ def feed_appointments_ical(protocoltype):
event["dtstamp"] = to_datetime(start)
event["dtstart"] = to_datetime(start)
event["dtend"] = to_datetime(start + timedelta(hours=3))
event["summary"] = protocoltype.short_name
event["summary"] = protocol.protocoltype.short_name
event["description"] = "\n".join(
top.name for top in protocol.get_tops())
calendar.add_component(event)
......@@ -1842,6 +1834,34 @@ def feed_appointments_ical(protocoltype):
return Response(content.encode("utf-8"), mimetype="text/calendar")
@app.route("/feed/appointments/ical/<int:protocoltype_id>")
@db_lookup(ProtocolType)
def feed_appointments_ical(protocoltype):
if not protocoltype.has_public_anonymous_view_right():
abort(403)
protocols = [
protocol for protocol in protocoltype.protocols
if not protocol.is_done()
]
return make_calendar_from_protocols(protocols, protocoltype.short_name)
@app.route("/feed/appointments/ical/")
def feed_all_appointments_ical():
user = current_user()
types = [
protocoltype for protocoltype in ProtocolType.query.all()
if (protocoltype.has_private_view_right(user)
or protocoltype.has_public_view_right(user)
or protocoltype.is_public)]
protocols = [
protocol
for protocoltype in types
for protocol in protocoltype.protocols
]
return make_calendar_from_protocols(protocols, "Sitzungskalender")
@app.route("/like/new")
@login_required
@protect_csrf
......
......@@ -11,6 +11,9 @@
{% if check_login() %}
<a href="{{url_for("new_protocol")}}">Neu</a>
{% endif %}
<a href="{{url_for("feed_all_appointments_ical")}}">
<img src="{{url_for("static", filename="images/feed-icon.svg")}}" width="18px"></img>
</a>
</h3>
<ul>
{% if open_protocols|length > 0 %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment