This commit is contained in:
Kara Engelhardt
2026-03-26 11:10:48 +01:00
parent a521956aca
commit 2e7d54174d
4 changed files with 22 additions and 61 deletions

View File

@@ -37,7 +37,7 @@ class WalletLayout(LoggedModel):
) )
platform = models.CharField(max_length=10) platform = models.CharField(max_length=10)
style = models.CharField(max_length=255) style = models.CharField(max_length=255)
layout = models.TextField() layout = models.JSONField()
class Meta: class Meta:
ordering = ("name",) ordering = ("name",)

View File

@@ -10,15 +10,12 @@ class WalletPlatform:
identifier: str identifier: str
name: str name: str
def get_layout_qs(self):
return WalletLayout.objects.filter(platform=self.identifier)
class ApplePlatform(WalletPlatform): class ApplePlatform(WalletPlatform):
identifier = "apple" identifier = "apple"
name = _("Apple") name = _("Apple")
class GooglePlatform(WalletPlatform): class GooglePlatform(WalletPlatform):
identifier = "apple" identifier = "google"
name = _("Google") name = _("Google")
class PlaceholderFieldType(enum.Enum): class PlaceholderFieldType(enum.Enum):

View File

@@ -1,6 +1,7 @@
{% extends "pretixcontrol/event/base.html" %} {% extends "pretixcontrol/event/base.html" %}
{% load i18n %} {% load i18n %}
{% load money %} {% load money %}
{% load wallet %}
{% block title %}{% trans "Wallet layouts" %}{% endblock %} {% block title %}{% trans "Wallet layouts" %}{% endblock %}
{% block content %} {% block content %}
<h1>{% trans "Wallet layouts" %}</h1> <h1>{% trans "Wallet layouts" %}</h1>
@@ -8,7 +9,8 @@
{% for platform in platforms.values %} {% for platform in platforms.values %}
<fieldset> <fieldset>
<legend>{{platform.name}}</legend> <legend>{{platform.name}}</legend>
{% if platforms.get_layout_qs|length == 0 %} {% with platform_layouts=platform|platform_layouts:request.event %}
{% if platform_layouts|length == 0 %}
<div class="empty-collection"> <div class="empty-collection">
<p> <p>
{% blocktrans trimmed %} {% blocktrans trimmed %}
@@ -33,7 +35,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for l in platforms.get_layout_qs %} {% for l in platform_layouts %}
<tr> <tr>
<td> <td>
{% if "can_change_event_settings" in request.eventpermset %} {% if "can_change_event_settings" in request.eventpermset %}
@@ -74,6 +76,7 @@
</table> </table>
</div> </div>
{% endif %} {% endif %}
{% endwith %}
</fieldset> </fieldset>
{% endfor %} {% endfor %}
</div> </div>

View File

@@ -34,7 +34,6 @@ class LayoutListView(EventPermissionRequiredMixin, ListView):
class LayoutEditForm(forms.ModelForm): class LayoutEditForm(forms.ModelForm):
style = forms.TypedChoiceField() style = forms.TypedChoiceField()
layout = forms.JSONField(initial={})
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.platform = kwargs.pop('platform') self.platform = kwargs.pop('platform')
@@ -70,12 +69,13 @@ class LayoutEditForm(forms.ModelForm):
) )
layout.validate() layout.validate()
return self.cleaned_data return self.cleaned_data
class LayoutCreateView(EventPermissionRequiredMixin, FormView): class LayoutEditorView(EventPermissionRequiredMixin, UpdateView):
template_name = "pretixplugins/wallet/edit.html" template_name = "pretixplugins/wallet/edit.html"
form_class = LayoutEditForm form_class = LayoutEditForm
model = WalletLayout model = WalletLayout
permission = "can_change_event_settings" # TODO: new permission name permission = "can_change_event_settings" # TODO: new permission name
pk_url_kwarg = "layout"
@property @property
def platform(self): def platform(self):
@@ -106,57 +106,18 @@ class LayoutCreateView(EventPermissionRequiredMixin, FormView):
} }
return context return context
def form_valid(self, form): def get_success_url(self) -> str:
self.object = WalletLayout.objects.create( return reverse(
event=self.request.event, "plugins:wallet:edit",
name=form.cleaned_data["name"], kwargs={
platform=self.platform, "organizer": self.request.event.organizer.slug,
style=form.cleaned_data["style"], "event": self.request.event.slug,
layout=form.cleaned_data["layout"], "platform": self.platform,
) "layout": self.object.pk,
return redirect( },
reverse(
"plugins:wallet:edit",
kwargs={
"organizer": self.request.event.organizer.slug,
"event": self.request.event.slug,
"platform": self.platform,
"layout": self.object.pk,
},
)
) )
class LayoutEditorView(EventPermissionRequiredMixin, UpdateView):
template_name = "pretixplugins/wallet/edit.html"
form_class = LayoutEditForm
success_url = ""
permission = "can_change_event_settings"
@property class LayoutCreateView(LayoutEditorView):
def platform(self): def get_object(self, queryset=None):
return self.kwargs["platform"] return WalletLayout(event=self.request.event, platform=self.platform)
def get_form_kwargs(self) -> dict[str, Any]:
kwargs = super().get_form_kwargs()
kwargs["platform"] = self.platform
return kwargs
def get_platform_styles(self):
if self.platform not in get_platforms():
raise Http404(
_("Unknown platform '{platform}'").format(platform=self.platform)
)
return get_platform_styles(self.platform)
def get_context_data(self, **kwargs) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
context["styles"] = {
id: style.asdict() for id, style in self.get_platform_styles().items()
}
context["variables"] = {
"text": {
varname: {"label": var["label"], "editor_sample": var["editor_sample"]}
for varname, var in get_variables(self.request.event).items()
}
}
return context