Ajout d'un export ical
This commit is contained in:
parent
ab4bd28607
commit
4c431e515d
@ -175,6 +175,11 @@ class CalendarList:
|
|||||||
def calendar_days_list(self):
|
def calendar_days_list(self):
|
||||||
return list(self.calendar_days.values())
|
return list(self.calendar_days.values())
|
||||||
|
|
||||||
|
def export_to_ics(self):
|
||||||
|
from .models import Event
|
||||||
|
events = [event for day in self.calendar_days.values() for event in day.events]
|
||||||
|
return Event.export_to_ics(events)
|
||||||
|
|
||||||
|
|
||||||
class CalendarMonth(CalendarList):
|
class CalendarMonth(CalendarList):
|
||||||
def __init__(self, year, month, filter):
|
def __init__(self, year, month, filter):
|
||||||
|
@ -1099,8 +1099,19 @@ class Event(models.Model):
|
|||||||
cal.add("version", "2.0")
|
cal.add("version", "2.0")
|
||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
|
ed = event.get_consolidated_end_day()
|
||||||
eventIcal = icalEvent()
|
eventIcal = icalEvent()
|
||||||
# mapping
|
# mapping
|
||||||
|
if event.start_time is None:
|
||||||
|
eventIcal.add(
|
||||||
|
"dtstart",
|
||||||
|
date(
|
||||||
|
event.start_day.year,
|
||||||
|
event.start_day.month,
|
||||||
|
event.start_day.day,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
eventIcal.add(
|
eventIcal.add(
|
||||||
"dtstart",
|
"dtstart",
|
||||||
datetime(
|
datetime(
|
||||||
@ -1111,6 +1122,17 @@ class Event(models.Model):
|
|||||||
event.start_time.minute,
|
event.start_time.minute,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
if not event.end_day is None:
|
||||||
|
if event.end_time is None:
|
||||||
|
eventIcal.add(
|
||||||
|
"dtend",
|
||||||
|
date(
|
||||||
|
event.end_day.year,
|
||||||
|
event.end_day.month,
|
||||||
|
event.end_day.day,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
eventIcal.add(
|
eventIcal.add(
|
||||||
"dtend",
|
"dtend",
|
||||||
datetime(
|
datetime(
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
{% if calendar.today_in_calendar %}
|
{% if calendar.today_in_calendar %}
|
||||||
<a role="button" href="{% url 'aujourdhui' %}?{{ filter.get_url }}">Aujourd'hui</a>
|
<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>
|
<a role="button" href="{% url 'cette_semaine' %}?{{ filter.get_url }}">Cette semaine</a>
|
||||||
|
<a role="button" data-tooltip="Copiez ce lien et importez-le dans votre agenda" href="{% url 'export_ical' %}?{{ filter.get_url }}">Export ical {% picto_from_name "calendar" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
@ -65,6 +65,7 @@ Semaine du {{ calendar.calendar_days_list.0.date|date|frdate }}
|
|||||||
{% if calendar.firstdate.month != calendar.lastdate.month %}
|
{% 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>
|
<a role="button" href="{% url 'month_view' calendar.lastdate.year calendar.lastdate.month %}?{{ filter.get_url }}">{{ calendar.lastdate | date:"F o" }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<a role="button" data-tooltip="Copiez ce lien et importez-le dans votre agenda" href="{% url 'export_ical' %}?{{ filter.get_url }}">Export ical {% picto_from_name "calendar" %}</a>
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
@ -162,6 +162,10 @@ urlpatterns = [
|
|||||||
"event/<int:year>/<int:month>/<int:day>/<int:pk>/ical",
|
"event/<int:year>/<int:month>/<int:day>/<int:pk>/ical",
|
||||||
export_event_ical,
|
export_event_ical,
|
||||||
name="export_event_ical"),
|
name="export_event_ical"),
|
||||||
|
path(
|
||||||
|
"ical",
|
||||||
|
export_ical,
|
||||||
|
name="export_ical"),
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
@ -58,7 +58,7 @@ from django.contrib.auth.decorators import login_required, permission_required
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
|
|
||||||
from .calendar import CalendarMonth, CalendarWeek, CalendarDay
|
from .calendar import CalendarMonth, CalendarWeek, CalendarDay, CalendarList
|
||||||
|
|
||||||
from .import_tasks.importer import URL2Events
|
from .import_tasks.importer import URL2Events
|
||||||
from .import_tasks.extractor import Extractor
|
from .import_tasks.extractor import Extractor
|
||||||
@ -203,6 +203,12 @@ class EventFilter(django_filters.FilterSet):
|
|||||||
def get_cities(self):
|
def get_cities(self):
|
||||||
return self.form.cleaned_data["city"]
|
return self.form.cleaned_data["city"]
|
||||||
|
|
||||||
|
def to_str(self, prefix=''):
|
||||||
|
result = ' '.join([c.name for c in self.get_categories()] + [t for t in self.get_tags()] + [c for c in self.get_cities()])
|
||||||
|
if len(result) > 0:
|
||||||
|
result = prefix + result
|
||||||
|
return result
|
||||||
|
|
||||||
def get_status_names(self):
|
def get_status_names(self):
|
||||||
if "status" in self.form.cleaned_data:
|
if "status" in self.form.cleaned_data:
|
||||||
return [
|
return [
|
||||||
@ -616,6 +622,21 @@ def export_event_ical(request, year, month, day, pk):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def export_ical(request):
|
||||||
|
now = date.today()
|
||||||
|
|
||||||
|
filter = EventFilter(request.GET, queryset=get_event_qs(request), request=request)
|
||||||
|
calendar = CalendarList(now + timedelta(days=-7), now + timedelta(days=+60), filter)
|
||||||
|
ical = calendar.export_to_ics()
|
||||||
|
|
||||||
|
response = HttpResponse(content_type="text/calendar")
|
||||||
|
response.content = ical.to_ical().decode("utf-8").replace("\r\n", "\n")
|
||||||
|
response["Content-Disposition"] = "attachment; filename={0}{1}{2}".format(
|
||||||
|
'Pommes de lune', filter.to_str(' '), ".ics"
|
||||||
|
)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
class EventFilterAdmin(django_filters.FilterSet):
|
class EventFilterAdmin(django_filters.FilterSet):
|
||||||
status = django_filters.MultipleChoiceFilter(
|
status = django_filters.MultipleChoiceFilter(
|
||||||
choices=Event.STATUS.choices, widget=forms.CheckboxSelectMultiple
|
choices=Event.STATUS.choices, widget=forms.CheckboxSelectMultiple
|
||||||
|
Loading…
Reference in New Issue
Block a user