Compare commits
No commits in common. "59d93cf6862a6a39c413824cb315420e1ddca06f" and "4f80d0048512a9525a8475ad29718645298b9004" have entirely different histories.
59d93cf686
...
4f80d00485
@ -26,8 +26,6 @@ from django.utils import timezone
|
|||||||
from location_field.models.plain import PlainLocationField
|
from location_field.models.plain import PlainLocationField
|
||||||
|
|
||||||
from .calendar import CalendarList, CalendarDay
|
from .calendar import CalendarList, CalendarDay
|
||||||
from icalendar import Calendar as icalCal
|
|
||||||
from icalendar import Event as icalEvent
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -1092,46 +1090,6 @@ 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):
|
|
||||||
cal = icalCal()
|
|
||||||
# Some properties are required to be compliant
|
|
||||||
cal.add("prodid", "-//My calendar product//example.com//")
|
|
||||||
cal.add("version", "2.0")
|
|
||||||
|
|
||||||
for event in events:
|
|
||||||
eventIcal = icalEvent()
|
|
||||||
# mapping
|
|
||||||
eventIcal.add(
|
|
||||||
"dtstart",
|
|
||||||
datetime(
|
|
||||||
event.start_day.year,
|
|
||||||
event.start_day.month,
|
|
||||||
event.start_day.day,
|
|
||||||
event.start_time.hour,
|
|
||||||
event.start_time.minute,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
eventIcal.add(
|
|
||||||
"dtend",
|
|
||||||
datetime(
|
|
||||||
event.end_day.year,
|
|
||||||
event.end_day.month,
|
|
||||||
event.end_day.day,
|
|
||||||
event.end_time.hour,
|
|
||||||
event.end_time.minute,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
eventIcal.add("summary", event.title)
|
|
||||||
eventIcal.add("name", event.title)
|
|
||||||
eventIcal.add(
|
|
||||||
"description", event.description + "\r" + event.reference_urls[0]
|
|
||||||
)
|
|
||||||
eventIcal.add("location", event.exact_location or event.location)
|
|
||||||
|
|
||||||
cal.add_component(eventIcal)
|
|
||||||
|
|
||||||
return cal
|
|
||||||
|
|
||||||
|
|
||||||
class ContactMessage(models.Model):
|
class ContactMessage(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -70,12 +70,11 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
|
||||||
<a href="{% url 'export_event_ical' event.id %}" role="button">Exporter ical {% picto_from_name "calendar" %}</a>
|
|
||||||
{% if perms.agenda_culturel.change_event and not noedit %}
|
{% if perms.agenda_culturel.change_event and not noedit %}
|
||||||
|
<div class="buttons">
|
||||||
{% include "agenda_culturel/edit-buttons-inc.html" with event=event %}
|
{% include "agenda_culturel/edit-buttons-inc.html" with event=event %}
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
|
@ -158,7 +158,6 @@ urlpatterns = [
|
|||||||
UnknownPlaceAddView.as_view(),
|
UnknownPlaceAddView.as_view(),
|
||||||
name="add_place_to_event",
|
name="add_place_to_event",
|
||||||
),
|
),
|
||||||
path("event/<int:pk>", export_event_ical, name="export_event_ical"),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
@ -10,7 +10,7 @@ from django.http import QueryDict
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.postgres.search import SearchQuery, SearchHeadline
|
from django.contrib.postgres.search import SearchQuery, SearchHeadline
|
||||||
|
|
||||||
from django.http import HttpResponseRedirect, FileResponse
|
from django.http import HttpResponseRedirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
@ -598,22 +598,6 @@ def import_from_url(request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def export_event_ical(request, pk):
|
|
||||||
event = get_object_or_404(Event, pk=pk)
|
|
||||||
|
|
||||||
events = list()
|
|
||||||
events.append(event)
|
|
||||||
|
|
||||||
cal = Event.export_to_ics(events)
|
|
||||||
|
|
||||||
return FileResponse(
|
|
||||||
cal.to_ical().decode("utf-8").replace("\r\n", "\n"),
|
|
||||||
as_attachment=True,
|
|
||||||
filename=event.title + ".ics",
|
|
||||||
content_type="text/calendar",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
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