Compare commits

..

No commits in common. "bdd03fa0150ab82755f7fb2f044ecfb800843689" and "f04e114062148f7e7e7f679e0d5e1988d29dcfda" have entirely different histories.

10 changed files with 12 additions and 151 deletions

View File

@ -1,21 +0,0 @@
# 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
),
),
]

View File

@ -1,13 +1,7 @@
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",
@ -39,4 +33,3 @@ class MusicrateSettings(models.Model):
blank=True, blank=True,
null=True, null=True,
) )
join_token = models.CharField(max_length=43, default=generate_token)

View File

@ -1,24 +1,6 @@
from django.dispatch import receiver from django.dispatch import receiver
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from pretalx.orga.signals import nav_event_settings
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)

View File

@ -1,11 +0,0 @@
{% 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 %}

View File

@ -1,9 +0,0 @@
{% 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 %}

View File

@ -1,15 +0,0 @@
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")
)

View File

@ -1,20 +1,12 @@
from django.urls import include, path from django.urls import re_path
from pretalx.event.models.event import SLUG_REGEX
from .views import JoinView, MusicrateSettingsView, QRCodeView from .views import MusicrateSettingsView
urlpatterns = [ urlpatterns = [
path( re_path(
"orga/event/<slug:event>/settings/p/pretalx_musicrate/", rf"^orga/event/(?P<event>{SLUG_REGEX})/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"),
]
),
),
] ]

View File

@ -1,46 +1,12 @@
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, TemplateView from django.views.generic import FormView
from pretalx.common.mixins.views import EventPermissionRequired from pretalx.common.mixins.views import PermissionRequired
from .forms import MusicrateSettingsForm from .forms import MusicrateSettingsForm
class JoinView(TemplateView): class MusicrateSettingsView(PermissionRequired, FormView):
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
@ -48,6 +14,9 @@ class MusicrateSettingsView(EventPermissionRequired, 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
@ -59,21 +28,3 @@ class MusicrateSettingsView(EventPermissionRequired, 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

View File

@ -16,7 +16,6 @@ dependencies = [
"Django", "Django",
"django-i18nfield", "django-i18nfield",
"pretalx", "pretalx",
"qrcode",
] ]
[project.urls] [project.urls]