Compare commits
2 Commits
7b3aca21f4
...
fc3b0f8320
Author | SHA1 | Date | |
---|---|---|---|
fc3b0f8320 | |||
bd310c7b44 |
@ -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):
|
||||
|
@ -95,7 +95,7 @@
|
||||
<h2>Voir aussi</h2>
|
||||
</header>
|
||||
<div class="buttons">
|
||||
<a role="button" href="{% url 'export_events_ical' day.year day.month day.day%}" >Exporter ical {% picto_from_name "calendar" %}</a>
|
||||
<a role="button" href="{% url 'day_view_ical' day.year day.month day.day%}" >Exporter ical {% picto_from_name "calendar" %}</a>
|
||||
<a role="button" href="{% url 'week_view' day.year day|week %}?{{ filter.get_url }}">Toute la semaine</a>
|
||||
</div>
|
||||
</article>
|
||||
|
@ -13,6 +13,7 @@ urlpatterns = [
|
||||
path("semaine/<int:year>/<int:week>/", week_view, name="week_view"),
|
||||
path("mois/<int:year>/<int:month>/", month_view, name="month_view"),
|
||||
path("jour/<int:year>/<int:month>/<int:day>/", day_view, name="day_view"),
|
||||
path("jour/<int:year>/<int:month>/<int:day>?feed=ical", day_view_ical, name="day_view_ical"),
|
||||
path("aujourdhui/", day_view, name="aujourdhui"),
|
||||
path("cette-semaine/", week_view, name="cette_semaine"),
|
||||
path("ce-mois-ci", month_view, name="ce_mois_ci"),
|
||||
|
@ -301,8 +301,10 @@ def week_view(request, year=None, week=None, home=False):
|
||||
context["home"] = 1
|
||||
return render(request, "agenda_culturel/page-week.html", context)
|
||||
|
||||
def day_view_ical(request, year=None, month=None, day=None):
|
||||
return day_view(request, year, month, day, ical=True)
|
||||
|
||||
def day_view(request, year=None, month=None, day=None):
|
||||
def day_view(request, year=None, month=None, day=None, ical=False):
|
||||
now = date.today()
|
||||
if year is None:
|
||||
year = now.year
|
||||
@ -325,6 +327,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 +610,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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user