Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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"),
)
}
@receiver(signal=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",
}
]