diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index b92f9b6..d0c323f 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -12,6 +12,7 @@ import os from django.core.files import File from django.utils import timezone from django.contrib.postgres.search import TrigramSimilarity +from django.http import HttpResponse from django.db.models import Q, Count import recurrence.fields import recurrence @@ -1092,7 +1093,7 @@ class Event(models.Model): return (dtstart <= e_dtstart <= dtend) or (e_dtstart <= dtstart <= e_dtend) - def export_to_ics(events): + def export_to_ics(filename, events): cal = icalCal() # Some properties are required to be compliant cal.add("prodid", "-//My calendar product//example.com//") @@ -1130,7 +1131,13 @@ class Event(models.Model): cal.add_component(eventIcal) - return cal + response = HttpResponse(content_type="text/calendar") + response.content = cal.to_ical().decode("utf-8").replace("\r\n", "\n") + response["Content-Disposition"] = "attachment; filename={0}{1}".format( + filename, ".ics" + ) + + return response class ContactMessage(models.Model): diff --git a/src/agenda_culturel/templates/agenda_culturel/page-day.html b/src/agenda_culturel/templates/agenda_culturel/page-day.html index f830163..62bccad 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-day.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-day.html @@ -95,7 +95,7 @@

Voir aussi

- Exporter ical {% picto_from_name "calendar" %} + Exporter ical {% picto_from_name "calendar" %} Toute la semaine
diff --git a/src/agenda_culturel/urls.py b/src/agenda_culturel/urls.py index d8b7d81..401000b 100644 --- a/src/agenda_culturel/urls.py +++ b/src/agenda_culturel/urls.py @@ -13,6 +13,7 @@ urlpatterns = [ path("semaine///", week_view, name="week_view"), path("mois///", month_view, name="month_view"), path("jour////", day_view, name="day_view"), + path("jour///?feed=ical", day_view, name="day_view"), path("aujourdhui/", day_view, name="aujourdhui"), path("cette-semaine/", week_view, name="cette_semaine"), path("ce-mois-ci", month_view, name="ce_mois_ci"), diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 251ff70..d896414 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -325,6 +325,10 @@ def day_view(request, year=None, month=None, day=None): categories = [(k, v) for k, v in categories.items()] categories.sort(key=lambda k: -k[1]) + if "ical" in str(request): + response = Event.export_to_ics(str(day), cday.get_events()) + return response + context = { "day": day, "events": cday.get_events(), @@ -604,13 +608,7 @@ def export_event_ical(request, pk): events = list() events.append(event) - cal = Event.export_to_ics(events) - - response = HttpResponse(content_type="text/calendar") - response.content = cal.to_ical().decode("utf-8").replace("\r\n", "\n") - response["Content-Disposition"] = "attachment; filename={0}{1}".format( - event.title, ".ics" - ) + response = Event.export_to_ics(event.title, events) return response