Skip to content
Snippets Groups Projects
Commit de58d760 authored by Felix Schäfer's avatar Felix Schäfer :construction_worker:
Browse files

Django 4 compatibility #14

parent 0b48bb17
No related branches found
No related tags found
No related merge requests found
Pipeline #141665 failed
...@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed ### Changed
- Apply updated pretix plugin cookiecutter - Apply updated pretix plugin cookiecutter
- Django 4 compatibility #14
## [1.5.0] - 2022-10-09 ## [1.5.0] - 2022-10-09
### Added ### Added
......
...@@ -4,7 +4,7 @@ from django.forms import ( ...@@ -4,7 +4,7 @@ from django.forms import (
MultipleChoiceField, MultipleChoiceField,
RegexField, RegexField,
) )
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import gettext_lazy
from i18nfield.forms import I18nFormField, I18nTextInput from i18nfield.forms import I18nFormField, I18nTextInput
from pretix.base.forms import SettingsForm from pretix.base.forms import SettingsForm
...@@ -14,42 +14,46 @@ from .helpers import matrix_room_info_for_event ...@@ -14,42 +14,46 @@ from .helpers import matrix_room_info_for_event
class MatrixInviterForm(SettingsForm): class MatrixInviterForm(SettingsForm):
matrix_inviter_items = MultipleChoiceField( matrix_inviter_items = MultipleChoiceField(
widget=CheckboxSelectMultiple(attrs={"class": "scrolling-multiple-choice"}), widget=CheckboxSelectMultiple(attrs={"class": "scrolling-multiple-choice"}),
label=_("Ask Matrix ID for"), label=gettext_lazy("Ask Matrix ID for"),
required=True, required=True,
choices=[], choices=[],
help_text=_("These products will ask for a Matrix ID."), help_text=gettext_lazy("These products will ask for a Matrix ID."),
) )
matrix_inviter_authorization_token = CharField( matrix_inviter_authorization_token = CharField(
label=_("Access token"), label=gettext_lazy("Access token"),
strip=True, strip=True,
help_text=_( help_text=gettext_lazy(
"This should be the access token of a user that can invite attendees to the target Room or Space. " "This should be the access token of a user that can invite attendees to the target Room or Space. "
"Please note that other administrators of this event will be able to see this token, it should not be from " "Please note that other administrators of this event will be able to see this token, it should not be from "
"your own Matrix account but from a dedicated Matrix account." "your own Matrix account but from a dedicated Matrix account."
), ),
) )
matrix_inviter_matrix_server = CharField( matrix_inviter_matrix_server = CharField(
label=_("Matrix server"), label=gettext_lazy("Matrix server"),
strip=True, strip=True,
help_text=_("The matrix server the above access token is valid for."), help_text=gettext_lazy(
"The matrix server the above access token is valid for."
),
) )
matrix_inviter_hint = I18nFormField( matrix_inviter_hint = I18nFormField(
widget=I18nTextInput, widget=I18nTextInput,
label=_("Matrix ID field help text"), label=gettext_lazy("Matrix ID field help text"),
required=True, required=True,
help_text=_( help_text=gettext_lazy(
"This will be shown as help text on the Matrix ID field. It is recommended to inform your attendees " "This will be shown as help text on the Matrix ID field. It is recommended to inform your attendees "
"which room they will be invited to and what that room will be used for." "which room they will be invited to and what that room will be used for."
), ),
) )
matrix_inviter_reason = I18nFormField( matrix_inviter_reason = I18nFormField(
widget=I18nTextInput, widget=I18nTextInput,
label=_("Invitation message"), label=gettext_lazy("Invitation message"),
required=False, required=False,
help_text=_("This message will be added to the invitation to the Matrix room."), help_text=gettext_lazy(
"This message will be added to the invitation to the Matrix room."
),
) )
matrix_inviter_matrix_room = RegexField( matrix_inviter_matrix_room = RegexField(
label=_("Matrix room"), label=gettext_lazy("Matrix room"),
regex="(?:!|#)[^:]+:[^:,]+(?:\\s*,\\s*(?:!|#)[^:]+:[^:,]+)*", regex="(?:!|#)[^:]+:[^:,]+(?:\\s*,\\s*(?:!|#)[^:]+:[^:,]+)*",
strip=True, strip=True,
) )
...@@ -62,7 +66,7 @@ class MatrixInviterForm(SettingsForm): ...@@ -62,7 +66,7 @@ class MatrixInviterForm(SettingsForm):
room_info = matrix_room_info_for_event(self.obj) room_info = matrix_room_info_for_event(self.obj)
if not room_info: if not room_info:
room_help_text = _( room_help_text = gettext_lazy(
"Comma-separated list of room IDs or aliases to invite users to." "Comma-separated list of room IDs or aliases to invite users to."
) )
else: else:
...@@ -71,22 +75,24 @@ class MatrixInviterForm(SettingsForm): ...@@ -71,22 +75,24 @@ class MatrixInviterForm(SettingsForm):
if room["room_id"].startswith("!"): if room["room_id"].startswith("!"):
if room["canonical_alias"]: if room["canonical_alias"]:
room_help.append( room_help.append(
_( gettext_lazy(
'"{name}" (main address: <code>{canonical_alias}</code>)' '"{name}" (main address: <code>{canonical_alias}</code>)'
).format_map(room) ).format_map(room)
) )
else: else:
room_help.append(_('"{name}"').format_map(room)) room_help.append(gettext_lazy('"{name}"').format_map(room))
else: else:
if room["canonical_alias"]: if room["canonical_alias"]:
room_help.append( room_help.append(
_( gettext_lazy(
'"{name}" (<code>{room_id}</code>, main address: <code>{canonical_alias}</code>)' '"{name}" (<code>{room_id}</code>, main address: <code>{canonical_alias}</code>)'
).format_map(room) ).format_map(room)
) )
else: else:
room_help.append( room_help.append(
_('"{name}" (<code>{room_id}</code>)').format_map(room) gettext_lazy(
'"{name}" (<code>{room_id}</code>)'
).format_map(room)
) )
room_help_text = ", ".join(room_help) room_help_text = ", ".join(room_help)
self.fields["matrix_inviter_matrix_room"].help_text = room_help_text self.fields["matrix_inviter_matrix_room"].help_text = room_help_text
...@@ -2,7 +2,7 @@ import json ...@@ -2,7 +2,7 @@ import json
from django import forms from django import forms
from django.dispatch import receiver from django.dispatch import receiver
from django.urls import resolve, reverse from django.urls import resolve, reverse
from django.utils.translation import gettext_noop, ugettext_lazy as _ from django.utils.translation import gettext_lazy, gettext_noop
from i18nfield.strings import LazyI18nString from i18nfield.strings import LazyI18nString
from pretix.base.settings import settings_hierarkey from pretix.base.settings import settings_hierarkey
from pretix.base.signals import ( from pretix.base.signals import (
...@@ -51,12 +51,14 @@ def add_matrix_id_question(sender, position, **kwargs): ...@@ -51,12 +51,14 @@ def add_matrix_id_question(sender, position, **kwargs):
return { return {
"matrix_inviter_matrix_id": forms.RegexField( "matrix_inviter_matrix_id": forms.RegexField(
label=_("Matrix ID"), label=gettext_lazy("Matrix ID"),
required=False, required=False,
regex="@[a-z0-9._=/-]+:[a-z0-9.-]+", regex="@[a-z0-9._=/-]+:[a-z0-9.-]+",
strip=True, strip=True,
error_messages={ error_messages={
"invalid": _("Enter a Matrix ID of the form @username:homeserver.tld") "invalid": gettext_lazy(
"Enter a Matrix ID of the form @username:homeserver.tld"
)
}, },
help_text=rich_text_snippet(sender.settings.matrix_inviter_hint), help_text=rich_text_snippet(sender.settings.matrix_inviter_hint),
) )
...@@ -132,7 +134,7 @@ def navbar_settings(sender, request=None, **kwargs): ...@@ -132,7 +134,7 @@ def navbar_settings(sender, request=None, **kwargs):
url = resolve(request.path_info) url = resolve(request.path_info)
return [ return [
{ {
"label": _("Matrix inviter"), "label": gettext_lazy("Matrix inviter"),
"url": reverse( "url": reverse(
"plugins:pretix_matrix_inviter:settings", "plugins:pretix_matrix_inviter:settings",
kwargs={ kwargs={
...@@ -152,16 +154,16 @@ def logentry_display(sender, logentry, **kwargs): ...@@ -152,16 +154,16 @@ def logentry_display(sender, logentry, **kwargs):
return return
locales = { locales = {
"pretix_matrix_inviter.invite_sent": _( "pretix_matrix_inviter.invite_sent": gettext_lazy(
"{matrix_id} has been invited to {matrix_room}." "{matrix_id} has been invited to {matrix_room}."
), ),
"pretix_matrix_inviter.invite_rescinded": _( "pretix_matrix_inviter.invite_rescinded": gettext_lazy(
"{matrix_id} has been removed from {matrix_room}." "{matrix_id} has been removed from {matrix_room}."
), ),
"pretix_matrix_inviter.error": _( "pretix_matrix_inviter.error": gettext_lazy(
"There was an error inviting {matrix_id} to {matrix_room}: {error}" "There was an error inviting {matrix_id} to {matrix_room}: {error}"
), ),
"pretix_matrix_inviter.remove_error": _( "pretix_matrix_inviter.remove_error": gettext_lazy(
"There was an error removing {matrix_id} from {matrix_room}: {error}" "There was an error removing {matrix_id} from {matrix_room}: {error}"
), ),
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment