Skip to content

Commit

Permalink
Add example ics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinRiese committed Feb 18, 2025
1 parent 80e368e commit 076a37d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions corehq/apps/prototype/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
name='prototype_example_knockout_pagination'),
url(r'^example/data/$', example.example_paginated_data,
name='prototype_example_paginated_data'),
url(r'^example/today.ics/$', example.generate_ics,
name='prototype_example_ics')
]
29 changes: 28 additions & 1 deletion corehq/apps/prototype/views/example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime

from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.http import JsonResponse, HttpResponse
from django.shortcuts import render
from django.views.decorators.http import require_POST

Expand Down Expand Up @@ -49,3 +51,28 @@ def example_paginated_data(request):
"total": len(data),
"rows": rows,
})


def generate_ics(request):
now = datetime.datetime.now()
dtstart = now.strftime('%Y%m%dT%H%M%S')
dtend = (now + datetime.timedelta(hours=1)).strftime('%Y%m%dT%H%M%S')

ics_content = f"""
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Your Organisation//Example Project//EN
BEGIN:VEVENT
UID:1
DTSTART:{dtstart}
DTEND:{dtend}
SUMMARY: Event for Today
LOCATION:
END:VEVENT
END:VCALENDAR
"""

response = HttpResponse(ics_content, content_type='text/calendar')
response['Content-Disposition'] = 'attachment; filename=event.ics'

return response

0 comments on commit 076a37d

Please sign in to comment.