feat: add qr code with join token
This commit is contained in:
parent
300b932daa
commit
09f32b85ea
|
@ -1,6 +1,24 @@
|
|||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
from pretalx.orga.signals import nav_event_settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from pretalx.orga.signals import nav_event, nav_event_settings
|
||||
|
||||
|
||||
@receiver(nav_event)
|
||||
def pretalx_musicrate_qrcode(sender, request, **kwargs):
|
||||
if not request.user.has_perm("orga.view_submissions", request.event):
|
||||
return []
|
||||
return [
|
||||
{
|
||||
"active": request.resolver_match.url_name
|
||||
== "plugins:pretalx_musicrate:qrcode",
|
||||
"icon": "star",
|
||||
"label": _("Collective Rating"),
|
||||
"url": reverse(
|
||||
"plugins:pretalx_musicrate:qrcode", kwargs={"event": request.event.slug}
|
||||
),
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@receiver(nav_event_settings)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{% extends "cfp/event/base.html" %}
|
||||
{% load qrcode %}
|
||||
|
||||
{% block content %}
|
||||
<div class="align-items-center d-flex flex-column justify-content-center">
|
||||
{% qrcode contents %}
|
||||
{{ contents | urlize }}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -0,0 +1,15 @@
|
|||
from django import template
|
||||
from django.utils.safestring import mark_safe
|
||||
from qrcode import make
|
||||
from qrcode.image.svg import SvgPathFillImage
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def qrcode(data):
|
||||
return mark_safe(
|
||||
make(data, box_size=20, image_factory=SvgPathFillImage)
|
||||
.to_string()
|
||||
.decode("utf-8")
|
||||
)
|
|
@ -1,12 +1,19 @@
|
|||
from django.urls import re_path
|
||||
from pretalx.event.models.event import SLUG_REGEX
|
||||
from django.urls import include, path
|
||||
|
||||
from .views import MusicrateSettingsView
|
||||
from .views import MusicrateSettingsView, QRCodeView
|
||||
|
||||
urlpatterns = [
|
||||
re_path(
|
||||
rf"^orga/event/(?P<event>{SLUG_REGEX})/settings/p/pretalx_musicrate/$",
|
||||
path(
|
||||
"orga/event/<slug:event>/settings/p/pretalx_musicrate/",
|
||||
MusicrateSettingsView.as_view(),
|
||||
name="settings",
|
||||
),
|
||||
path(
|
||||
"<slug:event>/p/pretalx_musicrate/",
|
||||
include(
|
||||
[
|
||||
path("", QRCodeView.as_view(), name="qrcode"),
|
||||
]
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
from django.contrib import messages
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import FormView
|
||||
from pretalx.common.mixins.views import PermissionRequired
|
||||
from django.views.generic import FormView, TemplateView
|
||||
from pretalx.common.mixins.views import EventPermissionRequired
|
||||
|
||||
|
||||
from .forms import MusicrateSettingsForm
|
||||
|
||||
|
||||
class MusicrateSettingsView(PermissionRequired, FormView):
|
||||
class MusicrateSettingsView(EventPermissionRequired, FormView):
|
||||
permission_required = "orga.change_settings"
|
||||
template_name = "pretalx_musicrate/settings.html"
|
||||
form_class = MusicrateSettingsForm
|
||||
|
@ -14,9 +16,6 @@ class MusicrateSettingsView(PermissionRequired, FormView):
|
|||
def get_success_url(self):
|
||||
return self.request.path
|
||||
|
||||
def get_object(self):
|
||||
return self.request.event
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs["event"] = self.request.event
|
||||
|
@ -28,3 +27,21 @@ class MusicrateSettingsView(PermissionRequired, FormView):
|
|||
self.request, _("The pretalx-musicrate settings were updated.")
|
||||
)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class QRCodeView(EventPermissionRequired, TemplateView):
|
||||
permission_required = "orga.view_submissions"
|
||||
template_name = "pretalx_musicrate/qrcode.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["contents"] = self.request.build_absolute_uri(
|
||||
reverse(
|
||||
"plugins:pretalx_musicrate:join",
|
||||
kwargs={
|
||||
"event": self.request.event.slug,
|
||||
"token": self.request.event.pretalx_musicrate_settings.join_token,
|
||||
},
|
||||
)
|
||||
)
|
||||
return context
|
||||
|
|
|
@ -16,6 +16,7 @@ dependencies = [
|
|||
"Django",
|
||||
"django-i18nfield",
|
||||
"pretalx",
|
||||
"qrcode",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
|
|
Loading…
Reference in New Issue