Compare commits

...

10 Commits

Author SHA1 Message Date
de61752726 nettoyage 2024-05-19 17:17:15 +02:00
ce5ff2df63 make format 2024-05-19 17:11:00 +02:00
018b7a052f 13 amélioration des noms de fichiers 2024-05-19 17:09:25 +02:00
663c4cff71 réorganisation ordre des urls dates 2024-05-19 17:08:55 +02:00
8bd4fafb17 13 export mois 2024-05-19 16:59:13 +02:00
6795a221da 13 export semaine 2024-05-19 16:30:50 +02:00
1db30afc1a WIP export semaine - ne fonctionne pas 2024-05-12 18:19:35 +02:00
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
7b3aca21f4 poc vue jour 2024-05-06 17:05:54 +02:00
7 changed files with 83 additions and 29 deletions

View File

@ -175,6 +175,9 @@ class CalendarList:
def calendar_days_list(self):
return list(self.calendar_days.values())
def get_events(self):
return [event for jour in self.calendar_days_list() for event in jour.events]
class CalendarMonth(CalendarList):
def __init__(self, year, month, filter):

View File

@ -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):

View File

@ -94,7 +94,10 @@
<header>
<h2>Voir aussi</h2>
</header>
<div class="buttons">
<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>
</aside>

View File

@ -58,10 +58,13 @@
<footer>
{% if calendar.today_in_calendar %}
<a role="button" href="{% url 'aujourdhui' %}?{{ filter.get_url }}">Aujourd'hui</a>
<a role="button" href="{% url 'cette_semaine' %}?{{ filter.get_url }}">Cette semaine</a>
{% endif %}
<div class="buttons">
<a role="button" href="{% url 'month_view_ical' calendar.firstdate.year calendar.firstdate.month %}" >Exporter ical {% picto_from_name "calendar" %}</a>
{% if calendar.today_in_calendar %}
<a role="button" href="{% url 'aujourdhui' %}?{{ filter.get_url }}">Aujourd'hui</a>
<a role="button" href="{% url 'cette_semaine' %}?{{ filter.get_url }}">Cette semaine</a>
{% endif %}
</div>
</footer>
</article>

View File

@ -8,7 +8,6 @@
{% load event_extra %}
{% load utils_extra %}
{% load static %}
{% load i18n %}
{% block entete_header %}
{% css_categories %}
@ -20,11 +19,11 @@
Semaine du {{ calendar.calendar_days_list.0.date|date|frdate }}
{% endblock %}
{% block content %}
{% block content %}
{% if home %}
<article>{% include "agenda_culturel/static_content.html" with name="home" url_path="/" %}</article>
{% endif %}
{% if home %}
<article>{% include "agenda_culturel/static_content.html" with name="home" url_path="/" %}</article>
{% endif %}
{% include "agenda_culturel/filter-inc.html" with filter=filter %}
@ -57,15 +56,15 @@ Semaine du {{ calendar.calendar_days_list.0.date|date|frdate }}
<footer>
<a role="button" href="{% url 'week_view_ical' year week %}" >Exporter ical {% picto_from_name "calendar" %}</a>
{% if calendar.today_in_calendar %}
<a role="button" href="{% url 'aujourdhui' %}?{{ filter.get_url }}">Aujourd'hui</a>
{% endif %}
<a role="button" href="{% url 'month_view' calendar.firstdate.year calendar.firstdate.month %}?{{ filter.get_url }}">{{ calendar.firstdate | date:"F o" }}</a>
{% if calendar.firstdate.month != calendar.lastdate.month %}
<a role="button" href="{% url 'month_view' calendar.lastdate.year calendar.lastdate.month %}?{{ filter.get_url }}">{{ calendar.lastdate | date:"F o" }}</a>
{% endif %}
</footer>
{% endif %}
</footer>
</article>

View File

@ -10,12 +10,23 @@ from .views import *
urlpatterns = [
path("", home, name="home"),
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("aujourdhui/", day_view, name="aujourdhui"),
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("cette-semaine/", week_view, name="cette_semaine"),
path("semaine/<int:year>/<int:week>/", week_view, name="week_view"),
path(
"semaine/<int:year>/<int:week>?feed=ical", week_view_ical, name="week_view_ical"
),
path("ce-mois-ci", month_view, name="ce_mois_ci"),
path("mois/<int:year>/<int:month>/", month_view, name="month_view"),
path(
"mois/<int:year>/<int:month>?feed=ical", month_view_ical, name="month_view_ical"
),
path("tag/<t>/", view_tag, name="view_tag"),
path("tags/", tag_list, name="view_all_tags"),
path("moderation/", moderation, name="moderation"),

View File

@ -10,7 +10,7 @@ from django.http import QueryDict
from django import forms
from django.contrib.postgres.search import SearchQuery, SearchHeadline
from django.http import HttpResponseRedirect, HttpResponse
from django.http import HttpResponseRedirect
from django.urls import reverse
from collections import Counter
@ -267,7 +267,11 @@ def home(request):
return week_view(request, home=True)
def month_view(request, year=None, month=None):
def month_view_ical(request, year=None, month=None):
return month_view(request, year, month, True)
def month_view(request, year=None, month=None, ical=False):
now = date.today()
if year is None:
year = now.year
@ -277,6 +281,12 @@ def month_view(request, year=None, month=None):
filter = EventFilter(request.GET, queryset=get_event_qs(request), request=request)
cmonth = CalendarMonth(year, month, filter)
if ical:
response = Event.export_to_ics(
f"Événements {cmonth.get_month_name()} {year}", cmonth.get_events()
)
return response
context = {
"year": year,
"month": cmonth.get_month_name(),
@ -286,7 +296,11 @@ def month_view(request, year=None, month=None):
return render(request, "agenda_culturel/page-month.html", context)
def week_view(request, year=None, week=None, home=False):
def week_view_ical(request, year=None, week=None, home=False):
return week_view(request, year, week, home, True)
def week_view(request, year=None, week=None, home=False, ical=False):
now = date.today()
if year is None:
year = now.year
@ -296,13 +310,29 @@ def week_view(request, year=None, week=None, home=False):
filter = EventFilter(request.GET, queryset=get_event_qs(request), request=request)
cweek = CalendarWeek(year, week, filter)
context = {"year": year, "week": week, "calendar": cweek, "filter": filter}
if ical:
response = Event.export_to_ics(
f"Événements semaine {week} {year}", cweek.get_events()
)
return response
context = {
"year": year,
"week": week,
"calendar": cweek,
"filter": filter,
"ical": True,
}
if home:
context["home"] = 1
return render(request, "agenda_culturel/page-week.html", context)
def day_view(request, year=None, month=None, day=None):
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, ical=False):
now = date.today()
if year is None:
year = now.year
@ -325,6 +355,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:
response = Event.export_to_ics(str(day), cday.get_events())
return response
context = {
"day": day,
"events": cday.get_events(),
@ -604,13 +638,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