2021-11-20 08:05:08 +00:00
|
|
|
import datetime as dt
|
2023-02-28 07:27:01 +00:00
|
|
|
from xml.etree import ElementTree as ET
|
2021-11-20 08:05:08 +00:00
|
|
|
|
2021-11-21 07:06:35 +00:00
|
|
|
import pytz
|
2023-02-28 07:27:01 +00:00
|
|
|
import qrcode
|
|
|
|
import qrcode.image.svg
|
|
|
|
from django.conf import settings
|
|
|
|
from django.http import HttpResponse, JsonResponse
|
2023-02-28 08:51:07 +00:00
|
|
|
from django.urls import reverse
|
2023-02-28 07:27:01 +00:00
|
|
|
from django.utils.safestring import mark_safe
|
2022-11-22 18:19:33 +00:00
|
|
|
from django.views import View
|
2021-11-20 16:46:05 +00:00
|
|
|
from django.views.generic import FormView
|
2021-11-20 08:05:08 +00:00
|
|
|
from django.views.generic.base import TemplateView
|
|
|
|
from pretalx.agenda.views.schedule import ScheduleMixin
|
2021-11-21 12:30:31 +00:00
|
|
|
from pretalx.common.mixins.views import EventPermissionRequired, PermissionRequired
|
2021-11-20 08:05:08 +00:00
|
|
|
from pretalx.schedule.exporters import ScheduleData
|
|
|
|
|
2021-11-22 11:09:01 +00:00
|
|
|
from .forms import BroadcastToolsSettingsForm
|
2022-11-15 12:43:17 +00:00
|
|
|
from .utils.placeholders import placeholders
|
2021-11-20 16:46:05 +00:00
|
|
|
|
2021-11-20 08:05:08 +00:00
|
|
|
|
2021-11-22 11:09:01 +00:00
|
|
|
class BroadcastToolsLowerThirdsView(TemplateView):
|
|
|
|
template_name = "pretalx_broadcast_tools/lower_thirds.html"
|
2021-11-20 08:05:08 +00:00
|
|
|
|
|
|
|
|
2023-02-28 08:51:07 +00:00
|
|
|
class BroadcastToolsRoomInfoView(TemplateView):
|
|
|
|
template_name = "pretalx_broadcast_tools/room_info.html"
|
|
|
|
|
|
|
|
|
|
|
|
class BroadcastToolsFeedbackQrCode(TemplateView):
|
|
|
|
template_name = "pretalx_broadcast_tools/feedback_qr.html"
|
|
|
|
|
|
|
|
|
2021-11-22 11:09:01 +00:00
|
|
|
class BroadcastToolsOrgaView(PermissionRequired, FormView):
|
|
|
|
form_class = BroadcastToolsSettingsForm
|
2021-11-21 07:06:35 +00:00
|
|
|
permission_required = "orga.change_settings"
|
2021-11-22 11:09:01 +00:00
|
|
|
template_name = "pretalx_broadcast_tools/orga.html"
|
2021-11-20 16:46:05 +00:00
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return self.request.path
|
|
|
|
|
2022-11-22 18:19:11 +00:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
2022-11-22 18:21:52 +00:00
|
|
|
context["localized_rooms"] = [
|
2022-11-22 18:19:11 +00:00
|
|
|
room.name.localize(self.request.event.locale)
|
|
|
|
for room in self.request.event.rooms.all()
|
|
|
|
]
|
|
|
|
return context
|
|
|
|
|
2021-11-20 16:46:05 +00:00
|
|
|
def form_valid(self, form):
|
|
|
|
form.save()
|
|
|
|
return super().form_valid(form)
|
|
|
|
|
|
|
|
def get_object(self):
|
|
|
|
return self.request.event
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super().get_form_kwargs()
|
2021-11-21 07:06:35 +00:00
|
|
|
return {
|
|
|
|
"obj": self.request.event,
|
|
|
|
"attribute_name": "settings",
|
2021-11-21 12:07:19 +00:00
|
|
|
"locales": self.request.event.locales,
|
2021-11-21 07:06:35 +00:00
|
|
|
**kwargs,
|
|
|
|
}
|
2021-11-20 16:46:05 +00:00
|
|
|
|
|
|
|
|
2022-11-22 18:19:33 +00:00
|
|
|
class BroadcastToolsEventInfoView(View):
|
2021-11-22 09:14:25 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
2021-11-22 09:26:49 +00:00
|
|
|
color = self.request.event.primary_color or "#3aa57c"
|
2021-11-22 09:14:25 +00:00
|
|
|
return JsonResponse(
|
|
|
|
{
|
2023-02-28 18:10:18 +00:00
|
|
|
"color": color,
|
2021-11-22 09:14:25 +00:00
|
|
|
"name": str(self.request.event.name),
|
2022-11-07 03:27:00 +00:00
|
|
|
"no_talk": str(
|
|
|
|
self.request.event.settings.broadcast_tools_lower_thirds_no_talk_info
|
|
|
|
),
|
2023-02-28 18:10:18 +00:00
|
|
|
"room-info": {
|
2023-03-01 10:29:56 +00:00
|
|
|
"lower_info": self.request.event.settings.broadcast_tools_room_info_lower_content or '',
|
2023-02-28 18:10:18 +00:00
|
|
|
},
|
|
|
|
"slug": self.request.event.slug,
|
2021-11-22 09:14:25 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-02-28 08:51:07 +00:00
|
|
|
class BroadcastToolsFeedbackQrCodeSvg(View):
|
2023-02-28 07:27:01 +00:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
talk = self.request.event.submissions.filter(id=kwargs["talk"]).first()
|
|
|
|
domain = request.event.custom_domain or settings.SITE_URL
|
|
|
|
image = qrcode.make(
|
|
|
|
f"{domain}{talk.urls.feedback}", image_factory=qrcode.image.svg.SvgImage
|
|
|
|
)
|
|
|
|
svg_data = mark_safe(ET.tostring(image.get_image()).decode())
|
|
|
|
return HttpResponse(svg_data, content_type="image/svg+xml")
|
|
|
|
|
|
|
|
|
2023-02-28 17:49:29 +00:00
|
|
|
class BroadcastToolsPublicQrCodeSvg(View):
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
talk = self.request.event.submissions.filter(id=kwargs["talk"]).first()
|
|
|
|
domain = request.event.custom_domain or settings.SITE_URL
|
|
|
|
image = qrcode.make(
|
|
|
|
f"{domain}{talk.urls.public}", image_factory=qrcode.image.svg.SvgImage
|
|
|
|
)
|
|
|
|
svg_data = mark_safe(ET.tostring(image.get_image()).decode())
|
|
|
|
return HttpResponse(svg_data, content_type="image/svg+xml")
|
|
|
|
|
|
|
|
|
2022-11-22 18:19:33 +00:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
tz = pytz.timezone(schedule.event.timezone)
|
2022-11-07 03:27:00 +00:00
|
|
|
infoline = str(
|
|
|
|
schedule.event.settings.broadcast_tools_lower_thirds_info_string or ""
|
|
|
|
)
|
2022-11-08 18:43:17 +00:00
|
|
|
try:
|
|
|
|
return JsonResponse(
|
|
|
|
{
|
|
|
|
"rooms": sorted(
|
|
|
|
{
|
2022-11-22 18:19:11 +00:00
|
|
|
room["name"].localize(schedule.event.locale)
|
2022-11-08 18:43:17 +00:00
|
|
|
for day in schedule.data
|
|
|
|
for room in day["rooms"]
|
|
|
|
}
|
|
|
|
),
|
|
|
|
"talks": [
|
|
|
|
{
|
|
|
|
"id": talk.submission.id,
|
|
|
|
"start": talk.start.astimezone(tz).isoformat(),
|
|
|
|
"end": (talk.start + dt.timedelta(minutes=talk.duration))
|
|
|
|
.astimezone(tz)
|
|
|
|
.isoformat(),
|
|
|
|
"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()
|
|
|
|
],
|
2022-11-08 18:43:17 +00:00
|
|
|
"track": {
|
|
|
|
"color": talk.submission.track.color,
|
|
|
|
"name": str(talk.submission.track.name),
|
2021-11-21 07:06:35 +00:00
|
|
|
}
|
2022-11-08 18:43:17 +00:00
|
|
|
if talk.submission.track
|
|
|
|
else None,
|
2022-11-22 18:19:11 +00:00
|
|
|
"room": room["name"].localize(schedule.event.locale),
|
2022-11-15 12:43:17 +00:00
|
|
|
"infoline": infoline.format(**placeholders(schedule, talk)),
|
2023-03-01 10:29:56 +00:00
|
|
|
"image_url": talk.submission.image_url,
|
2023-02-28 09:14:26 +00:00
|
|
|
"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,
|
2023-02-28 18:10:18 +00:00
|
|
|
"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,
|
2023-02-28 09:14:26 +00:00
|
|
|
"talk": talk.submission.id,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
2021-11-21 07:06:35 +00:00
|
|
|
}
|
2022-11-08 18:43:17 +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}}}}}",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2022-11-08 18:43:17 +00:00
|
|
|
except Exception as e:
|
2022-11-08 19:04:28 +00:00
|
|
|
return JsonResponse(
|
|
|
|
{
|
|
|
|
"error": [
|
|
|
|
repr(e),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|