1
0
Fork 0
mirror of https://github.com/Kunsi/pretalx-plugin-broadcast-tools synced 2024-11-22 09:11:02 +00:00
pretalx-plugin-broadcast-tools/pretalx_broadcast_tools/views/schedule.py

123 lines
5.3 KiB
Python
Raw Normal View History

2021-11-20 08:05:08 +00:00
import datetime as dt
from django.conf import settings
2023-09-30 10:39:30 +00:00
from django.http import JsonResponse
from django.urls import reverse
from django.views import View
2021-11-20 08:05:08 +00:00
from pretalx.agenda.views.schedule import ScheduleMixin
2023-09-30 10:39:30 +00:00
from pretalx.common.mixins.views import EventPermissionRequired
2021-11-20 08:05:08 +00:00
from pretalx.schedule.exporters import ScheduleData
2023-09-30 10:39:30 +00:00
from ..utils.placeholders import placeholders
class BroadcastToolsScheduleView(EventPermissionRequired, ScheduleMixin, View):
2021-11-20 08:05:08 +00:00
permission_required = "agenda.view_schedule"
def get(self, request, *args, **kwargs):
schedule = ScheduleData(
event=self.request.event,
schedule=self.schedule,
)
2022-11-07 03:27:00 +00:00
infoline = str(
schedule.event.settings.broadcast_tools_lower_thirds_info_string or ""
)
try:
return JsonResponse(
{
"rooms": sorted(
{
room["name"].localize(schedule.event.locale)
for day in schedule.data
for room in day["rooms"]
}
),
"talks": [
{
"id": talk.submission.id,
2023-08-23 06:11:19 +00:00
"start": talk.start.astimezone(
schedule.event.tz
).isoformat(),
"start_ts": int(talk.start.timestamp()),
"end": (talk.start + dt.timedelta(minutes=talk.duration))
2023-06-03 20:07:13 +00:00
.astimezone(schedule.event.tz)
.isoformat(),
"end_ts": int(
(
talk.start + dt.timedelta(minutes=talk.duration)
).timestamp()
),
"slug": talk.frab_slug,
"title": talk.submission.title,
2023-02-28 07:30:58 +00:00
"persons": [
person.get_display_name()
for person in talk.submission.speakers.all()
],
2024-03-16 10:37:26 +00:00
"track": (
{
"color": talk.submission.track.color,
"name": str(talk.submission.track.name),
}
if talk.submission.track
else None
),
"room": room["name"].localize(schedule.event.locale),
"infoline": infoline.format(
**placeholders(
schedule, talk, supports_html_colour=True
)
),
"image_url": talk.submission.image_url,
"locale": talk.submission.content_locale,
"do_not_record": talk.submission.do_not_record,
"abstract": talk.submission.abstract,
"urls": {
"feedback": "{}{}".format(
schedule.event.custom_domain or settings.SITE_URL,
talk.submission.urls.feedback,
),
"feedback_qr": reverse(
"plugins:pretalx_broadcast_tools:feedback_qr_id",
kwargs={
2023-02-28 12:14:46 +00:00
"event": schedule.event.slug,
"talk": talk.submission.id,
},
),
"public": "{}{}".format(
schedule.event.custom_domain or settings.SITE_URL,
talk.submission.urls.public,
),
"public_qr": reverse(
"plugins:pretalx_broadcast_tools:public_qr_id",
kwargs={
"event": schedule.event.slug,
"talk": talk.submission.id,
},
),
},
2021-11-21 07:06:35 +00:00
}
for day in schedule.data
for room in day["rooms"]
for talk in room["talks"]
],
},
)
except KeyError as e:
key = str(e)[1:-1]
2022-11-08 19:04:28 +00:00
return JsonResponse(
{
"error": [
f"Could not find value for placeholder {{{key}}} in info line.",
f"If you want to use {{{key}}} without evaluating it, please use as follows: {{{{{key}}}}}",
],
}
)
except Exception as e:
2022-11-08 19:04:28 +00:00
return JsonResponse(
{
"error": [
repr(e),
],
}
)