Compare commits

...

2 Commits

Author SHA1 Message Date
fc3b0f8320 correction urls 2024-05-08 11:41:43 +02:00
bd310c7b44 ajout de l’export ical vue jour 2024-05-07 11:58:13 +02:00
4 changed files with 19 additions and 11 deletions

View File

@ -12,6 +12,7 @@ import os
from django.core.files import File from django.core.files import File
from django.utils import timezone from django.utils import timezone
from django.contrib.postgres.search import TrigramSimilarity from django.contrib.postgres.search import TrigramSimilarity
from django.http import HttpResponse
from django.db.models import Q, Count from django.db.models import Q, Count
import recurrence.fields import recurrence.fields
import recurrence import recurrence
@ -1092,7 +1093,7 @@ class Event(models.Model):
return (dtstart <= e_dtstart <= dtend) or (e_dtstart <= dtstart <= e_dtend) return (dtstart <= e_dtstart <= dtend) or (e_dtstart <= dtstart <= e_dtend)
def export_to_ics(events): def export_to_ics(filename, events):
cal = icalCal() cal = icalCal()
# Some properties are required to be compliant # Some properties are required to be compliant
cal.add("prodid", "-//My calendar product//example.com//") cal.add("prodid", "-//My calendar product//example.com//")
@ -1130,7 +1131,13 @@ class Event(models.Model):
cal.add_component(eventIcal) 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): class ContactMessage(models.Model):

View File

@ -95,7 +95,7 @@
<h2>Voir aussi</h2> <h2>Voir aussi</h2>
</header> </header>
<div class="buttons"> <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> <a role="button" href="{% url 'week_view' day.year day|week %}?{{ filter.get_url }}">Toute la semaine</a>
</div> </div>
</article> </article>

View File

@ -13,6 +13,7 @@ urlpatterns = [
path("semaine/<int:year>/<int:week>/", week_view, name="week_view"), path("semaine/<int:year>/<int:week>/", week_view, name="week_view"),
path("mois/<int:year>/<int:month>/", month_view, name="month_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>/", 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("aujourdhui/", day_view, name="aujourdhui"),
path("cette-semaine/", week_view, name="cette_semaine"), path("cette-semaine/", week_view, name="cette_semaine"),
path("ce-mois-ci", month_view, name="ce_mois_ci"), path("ce-mois-ci", month_view, name="ce_mois_ci"),

View File

@ -301,8 +301,10 @@ def week_view(request, year=None, week=None, home=False):
context["home"] = 1 context["home"] = 1
return render(request, "agenda_culturel/page-week.html", context) 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() now = date.today()
if year is None: if year is None:
year = now.year 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 = [(k, v) for k, v in categories.items()]
categories.sort(key=lambda k: -k[1]) 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 = { context = {
"day": day, "day": day,
"events": cday.get_events(), "events": cday.get_events(),
@ -604,13 +610,7 @@ def export_event_ical(request, pk):
events = list() events = list()
events.append(event) events.append(event)
cal = Event.export_to_ics(events) response = Event.export_to_ics(event.title, 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"
)
return response return response