add rental calendar

This commit is contained in:
2025-10-14 13:44:34 +02:00
parent 1a47dd2165
commit 484dce8305
4 changed files with 62 additions and 1 deletions

View File

@@ -1,11 +1,12 @@
from django.urls import path
from . import apps
from . import apps, views
from .views import RentalCreateDoneView, RentalCreateView, RentalItemDetailView, RentalListView
app_name = apps.RentalConfig.name
urlpatterns = [
path("rental_calendar.ics", views.rental_calendar, name="calendar"),
path("rental/", RentalListView.as_view(), name="index"),
path("request-rental/", RentalCreateView.as_view(), name="rental_create"),
path(

View File

@@ -2,6 +2,7 @@ import calendar
import datetime
from django.db.models import Q
from django.shortcuts import render
from django.urls import reverse
from django.views.generic import ListView, TemplateView
from django.views.generic.detail import DetailView
@@ -170,3 +171,21 @@ class RentalCreateDoneView(TemplateView):
class RentalItemDetailView(DetailView):
model = RentalItem
template_name = "rental/rentalitem_detail.html"
def rental_calendar(request):
"""
ICS-calendar for outlook, google calender, ...
"""
rentals = Rental.objects.all()
context = {
"rentals": rentals,
}
response = render(request, "rental/rental_calendar.ics", context, content_type="text/calendar")
# End of line (EOL) must be CRLF, to be compliant with RFC5545. Django/Python set the EOL to LF.
response.content = response.content.replace(b"\n", b"\r\n")
return response