Skip to content
Snippets Groups Projects
signals.py 1.62 KiB
Newer Older
from django import forms
from django.dispatch import receiver
from django.urls import resolve, reverse
from django.utils.translation import ugettext_lazy as _
from pretix.base.settings import settings_hierarkey
from pretix.control.signals import nav_event_settings
from pretix.presale.signals import question_form_fields

settings_hierarkey.add_default("matrix_inviter_items", [], list)


@receiver(question_form_fields, dispatch_uid="matrix_inviter_questions")
def add_matrix_id_question(sender, position, **kwargs):
    if str(position.item.pk) not in sender.settings.get("matrix_inviter_items"):
        return {}

    return {
        "matrix_inviter_matrix_id": forms.RegexField(
            label=_("Matrix ID"),
            required=False,
            regex="@[a-z0-9._=/-]+:.+",
            strip=True,
            error_messages={
                "invalid": _("Enter a Matrix ID of the form @username:homeserver.tld")
            },
            help_text=_("You will be invited to a Matrix room using this Matrix ID"),
        )
    }


Felix Schäfer's avatar
Felix Schäfer committed
@receiver(nav_event_settings, dispatch_uid="matrix_inviter_nav_settings")
def navbar_settings(sender, request=None, **kwargs):
    url = resolve(request.path_info)
    return [
        {
            "label": _("Matrix inviter"),
            "url": reverse(
                "plugins:pretix_matrix_inviter:settings",
                kwargs={
                    "event": request.event.slug,
                    "organizer": request.organizer.slug,
                },
            ),
            "active": url.namespace == "plugins:pretix_matrix_inviter"
            and url.url_name == "settings",
        }
    ]