Skip to content

Commit

Permalink
Merge pull request #64 from pyvec/schedule-json
Browse files Browse the repository at this point in the history
Add view that renders the schedule as JSON
  • Loading branch information
jsmitka authored Sep 16, 2023
2 parents 47dd3d6 + 78bdcd8 commit 1b1c1d1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions program/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
session_detail,
schedule_redirect,
schedule_day,
schedule_json,
debug_og_image_for_talk,
debug_og_image_for_workshop,
)
Expand All @@ -23,6 +24,7 @@
# Schedule
path("schedule/", schedule_redirect, name="schedule_redirect"),
path("schedule/<str:conference_day>/", schedule_day, name="schedule_day"),
path("schedule.json", schedule_json, name="schedule_json"),
]

# Routes for previewing OG images template.
Expand Down
68 changes: 67 additions & 1 deletion program/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re

from django.db.models import Prefetch
from django.http import HttpRequest, Http404
from django.http import HttpRequest, Http404, JsonResponse
from django.template.loader import render_to_string
from django.template.response import TemplateResponse, HttpResponse
from django.shortcuts import get_object_or_404, redirect
Expand Down Expand Up @@ -187,6 +187,72 @@ def schedule_day(request: HttpRequest, conference_day: str) -> HttpResponse:
)


def schedule_json(request):
all_slots = Slot.objects.select_related(
"room"
).prefetch_related(
"talk",
Prefetch(
"talk__talk_speakers",
queryset=Speaker.objects.filter(is_public=True),
to_attr="public_speakers",
),
"workshop",
Prefetch(
"workshop__workshop_speakers",
queryset=Speaker.objects.filter(is_public=True),
to_attr="public_speakers",
),
"utility",
).order_by(
"start",
"room__order",
)

schedule_grid = ScheduleGrid.create_from_slots(all_slots)
result = []
for row in schedule_grid.rows:
for item in row.items:
session = item.slot.event
session_json = {
'title': session.title,
}
if isinstance(session, (Talk, Workshop)):
session_json.update({
'type': session.type,
'abstract': session.abstract,
'track': session.track,
'language': session.language,
'minimum_python_knowledge': session.minimum_python_knowledge,
'minimum_topic_knowledge': session.minimum_topic_knowledge,
'speakers': [
{
'name': speaker.full_name,
'twitter': speaker.twitter if speaker.twitter else None,
'github': speaker.github if speaker.github else None,
'linkedin': speaker.linkedin if speaker.linkedin else None,
'personal_website': speaker.personal_website if speaker.personal_website else None,
}
for speaker in session.speakers
],
})
else:
session_json['type'] = 'other'

slot_json = {
'start': item.slot.start.isoformat(),
'end': item.slot.end.isoformat(),
'room': item.slot.room.label,
'is_streamed': item.is_streamed,
'session': session_json,
}
result.append(slot_json)

return JsonResponse({
'schedule': result,
})


def debug_og_image_for_talk(request, session_id: int) -> HttpResponse:
"""
DEBUG view: preview OG image template for a talk.
Expand Down

0 comments on commit 1b1c1d1

Please sign in to comment.