pretalx-musicrate/pretalx_musicrate/signals.py

68 lines
2.2 KiB
Python

from django.dispatch import receiver
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from pretalx.mail.placeholders import SimpleFunctionalMailTextPlaceholder
from pretalx.mail.signals import register_mail_placeholders
from pretalx.orga.signals import nav_event, nav_event_settings
@receiver(register_mail_placeholders)
def pretalx_musicrate_placeholders(sender, **kwargs):
return [
SimpleFunctionalMailTextPlaceholder(
"assignee",
["submission"],
lambda submission: (
assignee.user.name
if (assignee := submission.assignee) is not None
else "Günther"
),
"Günther",
_("The name of the submission's assignee"),
)
]
@receiver(nav_event)
def pretalx_musicrate_nav_event(sender, request, **kwargs):
if not request.user.has_perm("orga.view_submissions", request.event):
return []
return [
{
"active": request.resolver_match.view_name
== "plugins:pretalx_musicrate:enhanced_list",
"icon": "sticky-note-o",
"label": _("Proposals, but better"),
"url": reverse(
"plugins:pretalx_musicrate:enhanced_list",
kwargs={"event": request.event.slug},
),
},
{
"active": request.resolver_match.view_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)
def pretalx_musicrate_settings(sender, request, **kwargs):
if not request.user.has_perm("orga.change_settings", request.event):
return []
return [
{
"label": "pretalx-musicrate",
"url": reverse(
"plugins:pretalx_musicrate:settings.musicrate",
kwargs={"event": request.event.slug},
),
"active": request.resolver_match.view_name
== "plugins:pretalx_musicrate:settings.musicrate",
}
]