pretalx-musicrate/pretalx_musicrate/views.py

48 lines
1.5 KiB
Python

from django.contrib import messages
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from django.views.generic import FormView, TemplateView
from pretalx.common.mixins.views import EventPermissionRequired
from .forms import MusicrateSettingsForm
class MusicrateSettingsView(EventPermissionRequired, FormView):
permission_required = "orga.change_settings"
template_name = "pretalx_musicrate/settings.html"
form_class = MusicrateSettingsForm
def get_success_url(self):
return self.request.path
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["event"] = self.request.event
return kwargs
def form_valid(self, form):
form.save()
messages.success(
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