feat: collect and show links from submissions
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Luca 2023-12-16 03:11:18 +01:00
parent f7e7ceaba2
commit cc4178baba
4 changed files with 75 additions and 6 deletions

View File

@ -77,7 +77,7 @@ msgstr ""
msgid "Join" msgid "Join"
msgstr "Mitmachen" msgstr "Mitmachen"
#: pretalx_musicrate/templates/pretalx_musicrate/present.html:15 #: pretalx_musicrate/templates/pretalx_musicrate/present.html:25
msgid "Show Join QR Code" msgid "Show Join QR Code"
msgstr "Mitmach-QR-Code anzeigen" msgstr "Mitmach-QR-Code anzeigen"
@ -101,19 +101,19 @@ msgstr "Zurück"
msgid "Next" msgid "Next"
msgstr "Weiter" msgstr "Weiter"
#: pretalx_musicrate/views.py:32 #: pretalx_musicrate/views.py:40
msgid "Invalid token" msgid "Invalid token"
msgstr "Ungültiges Token" msgstr "Ungültiges Token"
#: pretalx_musicrate/views.py:107 #: pretalx_musicrate/views.py:115
msgid "The pretalx-musicrate settings were updated." msgid "The pretalx-musicrate settings were updated."
msgstr "Die pretalx-musicrate-Einstellungen wurden gespeichert." msgstr "Die pretalx-musicrate-Einstellungen wurden gespeichert."
#: pretalx_musicrate/views.py:266 #: pretalx_musicrate/views.py:274
msgid "Saved!" msgid "Saved!"
msgstr "Gespeichert!" msgstr "Gespeichert!"
#: pretalx_musicrate/views.py:323 #: pretalx_musicrate/views.py:372
#, python-format #, python-format
msgid "%(num_ratings)d of %(num_jurors)d has rated this submission" msgid "%(num_ratings)d of %(num_jurors)d has rated this submission"
msgid_plural "%(num_ratings)d of %(num_jurors)d have rated this submission" msgid_plural "%(num_ratings)d of %(num_jurors)d have rated this submission"

View File

@ -2,6 +2,7 @@
{% load compress %} {% load compress %}
{% load i18n %} {% load i18n %}
{% load static %} {% load static %}
{% load youtube %}
{% block submission_header %} {% block submission_header %}
{% if next %} {% if next %}
@ -12,6 +13,15 @@
{% endblock %} {% endblock %}
{% block submission_content %} {% block submission_content %}
{% for type, link in links %}
{% if type == 'youtube' %}
<div class="embed-responsive embed-responsive-16by9 mb-3">
{% youtube link %}
</div>
{% else %}
<p>{{ link | urlize }}</p>
{% endif %}
{% endfor %}
<a class="btn btn-primary btn-lg btn-block mb-3" href="{% url "plugins:pretalx_musicrate:qrcode" event=request.event.slug %}">{% translate "Show Join QR Code" %}</a> <a class="btn btn-primary btn-lg btn-block mb-3" href="{% url "plugins:pretalx_musicrate:qrcode" event=request.event.slug %}">{% translate "Show Join QR Code" %}</a>
<p class="text-center" id="status"></p> <p class="text-center" id="status"></p>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,12 @@
from django import template
from django.utils.html import format_html
register = template.Library()
@register.simple_tag
def youtube(v):
return format_html(
'<iframe allow="autoplay; encrypted-media" allowfullscreen="" src="https://www.youtube-nocookie.com/embed/{}" width="560" height="315" frameborder="0"></iframe>',
v,
)

View File

@ -1,10 +1,13 @@
import re
from hmac import compare_digest from hmac import compare_digest
from urllib.parse import parse_qs, urlparse
from django.contrib import messages from django.contrib import messages
from django.http import JsonResponse from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse from django.urls import reverse
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.html import Urlizer
from django.utils.translation import gettext_lazy as _, ngettext from django.utils.translation import gettext_lazy as _, ngettext
from django.views.generic import FormView, TemplateView, View from django.views.generic import FormView, TemplateView, View
from django.views.generic.detail import SingleObjectMixin from django.views.generic.detail import SingleObjectMixin
@ -14,6 +17,10 @@ from pretalx.common.mixins.views import EventPermissionRequired
from .forms import MusicrateSettingsForm, RatingForm from .forms import MusicrateSettingsForm, RatingForm
from .models import Juror, Rating from .models import Juror, Rating
youtube_re = re.compile(
r"(?:https?://)?(youtu\.be/|(?:(?:m|www)\.)?youtube\.com/watch\?)", re.IGNORECASE
)
class JoinView(TemplateView): class JoinView(TemplateView):
template_name = "pretalx_musicrate/join.html" template_name = "pretalx_musicrate/join.html"
@ -286,6 +293,44 @@ class PresenterView(EventPermissionRequired, SubmissionMixin, TemplateView):
permission_required = "orga.view_submissions" permission_required = "orga.view_submissions"
template_name = "pretalx_musicrate/present.html" template_name = "pretalx_musicrate/present.html"
@context
@cached_property
def links(self):
class Extractor:
def __init__(self):
self.urls = []
def format(self, href, **kwargs):
self.urls.append(href)
return href
extractor = Extractor()
urlizer = Urlizer()
urlizer.url_template = extractor
urlizer(self.submission.abstract)
urlizer(self.submission.description)
urlizer(self.submission.notes)
urlizer(self.submission.internal_notes)
links = []
for url in extractor.urls:
if (m := youtube_re.search(url)) is not None:
links.append(
(
"youtube",
url.removeprefix("http")
.removeprefix("s")
.removeprefix("://")
.removeprefix("youtu.be/")[:11]
if m[1] == "youtu.be/"
else "".join(
parse_qs(urlparse(url).query).get("v", "dQw4w9WgXcQ")
),
)
)
else:
links.append(("other", url))
return links
@context @context
@property @property
def can_continue(self): def can_continue(self):
@ -303,7 +348,9 @@ class PresenterView(EventPermissionRequired, SubmissionMixin, TemplateView):
settings.save() settings.save()
except Exception: except Exception:
pass pass
return super().get(request, *args, **kwargs) response = super().get(request, *args, **kwargs)
response._csp_update = {"frame-src": "https://www.youtube-nocookie.com"}
return response
class MayAdvanceView(EventPermissionRequired, SubmissionMixin, View): class MayAdvanceView(EventPermissionRequired, SubmissionMixin, View):