Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view that renders the schedule as JSON #64

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading