WIP export semaine - ne fonctionne pas

This commit is contained in:
SebF 2024-05-12 18:19:35 +02:00
parent fc3b0f8320
commit 1db30afc1a
4 changed files with 24 additions and 10 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

@ -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' day.year day %}" >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

@ -11,6 +11,7 @@ from .views import *
urlpatterns = [
path("", home, name="home"),
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("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"),

View File

@ -286,7 +286,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,14 +300,21 @@ 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)
if ical:
logger.warning("export ical semaine")
response = Event.export_to_ics("testsemaine", cweek.get_events())
return response
context = {"year": year, "week": week, "calendar": cweek, "filter": filter}
if home:
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, ical=False):
now = date.today()
if year is None:
@ -327,7 +338,7 @@ def day_view(request, year=None, month=None, day=None, ical=False):
categories = [(k, v) for k, v in categories.items()]
categories.sort(key=lambda k: -k[1])
if "ical" in str(request):
if ical:
response = Event.export_to_ics(str(day), cday.get_events())
return response