Compare commits
3 Commits
f04e114062
...
bdd03fa015
Author | SHA1 | Date |
---|---|---|
Luca | bdd03fa015 | |
Luca | 09f32b85ea | |
Luca | 300b932daa |
|
@ -0,0 +1,21 @@
|
||||||
|
# Generated by Django 4.2.8 on 2023-12-15 01:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
import pretalx_musicrate.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("pretalx_musicrate", "0002_musicratesettings_genre_question_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="musicratesettings",
|
||||||
|
name="join_token",
|
||||||
|
field=models.CharField(
|
||||||
|
default=pretalx_musicrate.models.generate_token, max_length=43
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,7 +1,13 @@
|
||||||
|
from secrets import token_urlsafe
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
def generate_token():
|
||||||
|
return token_urlsafe(32)
|
||||||
|
|
||||||
|
|
||||||
class MusicrateSettings(models.Model):
|
class MusicrateSettings(models.Model):
|
||||||
event = models.OneToOneField(
|
event = models.OneToOneField(
|
||||||
to="event.Event",
|
to="event.Event",
|
||||||
|
@ -33,3 +39,4 @@ class MusicrateSettings(models.Model):
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
|
join_token = models.CharField(max_length=43, default=generate_token)
|
||||||
|
|
|
@ -1,6 +1,24 @@
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.urls import reverse
|
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)
|
@receiver(nav_event_settings)
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
{% extends "cfp/event/base.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>{% translate "Join collective rating" %}</h1>
|
||||||
|
<hr>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button class="btn btn-success btn-lg btn-block" type="submit"{% if not token_valid %} disabled{% endif %}>{% translate "Join" %}</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -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,20 @@
|
||||||
from django.urls import re_path
|
from django.urls import include, path
|
||||||
from pretalx.event.models.event import SLUG_REGEX
|
|
||||||
|
|
||||||
from .views import MusicrateSettingsView
|
from .views import JoinView, MusicrateSettingsView, QRCodeView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
re_path(
|
path(
|
||||||
rf"^orga/event/(?P<event>{SLUG_REGEX})/settings/p/pretalx_musicrate/$",
|
"orga/event/<slug:event>/settings/p/pretalx_musicrate/",
|
||||||
MusicrateSettingsView.as_view(),
|
MusicrateSettingsView.as_view(),
|
||||||
name="settings",
|
name="settings",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"<slug:event>/p/pretalx_musicrate/",
|
||||||
|
include(
|
||||||
|
[
|
||||||
|
path("", QRCodeView.as_view(), name="qrcode"),
|
||||||
|
path("<slug:token>/", JoinView.as_view(), name="join"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,12 +1,46 @@
|
||||||
|
from hmac import compare_digest
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import FormView
|
from django.views.generic import FormView, TemplateView
|
||||||
from pretalx.common.mixins.views import PermissionRequired
|
from pretalx.common.mixins.views import EventPermissionRequired
|
||||||
|
|
||||||
from .forms import MusicrateSettingsForm
|
from .forms import MusicrateSettingsForm
|
||||||
|
|
||||||
|
|
||||||
class MusicrateSettingsView(PermissionRequired, FormView):
|
class JoinView(TemplateView):
|
||||||
|
template_name = "pretalx_musicrate/join.html"
|
||||||
|
|
||||||
|
def validate_token(self, token):
|
||||||
|
if compare_digest(
|
||||||
|
token.encode("utf-8"),
|
||||||
|
self.request.event.pretalx_musicrate_settings.join_token.encode("utf-8"),
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
messages.error(self.request, _("Invalid token"))
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_context_data(self, token_valid=False, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
context["token_valid"] = token_valid
|
||||||
|
return context
|
||||||
|
|
||||||
|
def get(self, request, *args, token, **kwargs):
|
||||||
|
token_valid = self.validate_token(token)
|
||||||
|
return super().get(request, *args, token_valid=token_valid, **kwargs)
|
||||||
|
|
||||||
|
def post(self, request, *args, token, **kwargs):
|
||||||
|
token_valid = self.validate_token(token)
|
||||||
|
if token_valid:
|
||||||
|
return redirect(request.path)
|
||||||
|
return self.render_to_response(
|
||||||
|
self.get_context_data(token_valid=token_valid, **kwargs)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MusicrateSettingsView(EventPermissionRequired, FormView):
|
||||||
permission_required = "orga.change_settings"
|
permission_required = "orga.change_settings"
|
||||||
template_name = "pretalx_musicrate/settings.html"
|
template_name = "pretalx_musicrate/settings.html"
|
||||||
form_class = MusicrateSettingsForm
|
form_class = MusicrateSettingsForm
|
||||||
|
@ -14,9 +48,6 @@ class MusicrateSettingsView(PermissionRequired, FormView):
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return self.request.path
|
return self.request.path
|
||||||
|
|
||||||
def get_object(self):
|
|
||||||
return self.request.event
|
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
kwargs["event"] = self.request.event
|
kwargs["event"] = self.request.event
|
||||||
|
@ -28,3 +59,21 @@ class MusicrateSettingsView(PermissionRequired, FormView):
|
||||||
self.request, _("The pretalx-musicrate settings were updated.")
|
self.request, _("The pretalx-musicrate settings were updated.")
|
||||||
)
|
)
|
||||||
return super().form_valid(form)
|
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",
|
||||||
"django-i18nfield",
|
"django-i18nfield",
|
||||||
"pretalx",
|
"pretalx",
|
||||||
|
"qrcode",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
|
Loading…
Reference in New Issue