mirror of
https://github.com/pretix/pretix.git
synced 2026-05-18 17:24:03 +00:00
WIP
This commit is contained in:
@@ -3,7 +3,7 @@ from typing import Any
|
||||
from django.http import Http404
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.views.generic import FormView, ListView, TemplateView
|
||||
from django.views.generic import FormView, ListView, CreateView, UpdateView
|
||||
from pretix.base.pdf import get_variables
|
||||
from pretix.control.permissions import EventPermissionRequiredMixin
|
||||
from .styles import PassLayout, get_platform_styles, get_platforms
|
||||
@@ -12,8 +12,10 @@ import json
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
from i18nfield.fields import I18nCharField
|
||||
from i18nfield.forms import I18nModelForm
|
||||
|
||||
|
||||
# TODO: should this even be a list view?
|
||||
class LayoutListView(EventPermissionRequiredMixin, ListView):
|
||||
model = WalletLayout
|
||||
permission = "can_change_event_settings"
|
||||
@@ -29,11 +31,19 @@ class LayoutListView(EventPermissionRequiredMixin, ListView):
|
||||
return ctx
|
||||
|
||||
|
||||
class EditorForm(forms.Form):
|
||||
name = forms.CharField()
|
||||
|
||||
class LayoutEditForm(forms.ModelForm):
|
||||
style = forms.TypedChoiceField()
|
||||
layout = forms.JSONField(initial={})
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.platform = kwargs.pop('platform')
|
||||
super().__init__(**kwargs)
|
||||
|
||||
class Meta:
|
||||
model = WalletLayout
|
||||
fields = ("name","style","layout")
|
||||
|
||||
def __init__(self, platform, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.platform = platform
|
||||
@@ -60,13 +70,12 @@ class EditorForm(forms.Form):
|
||||
)
|
||||
layout.validate()
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
class EditorView(EventPermissionRequiredMixin, FormView):
|
||||
|
||||
class LayoutCreateView(EventPermissionRequiredMixin, FormView):
|
||||
template_name = "pretixplugins/wallet/edit.html"
|
||||
form_class = EditorForm
|
||||
success_url = ""
|
||||
permission = "can_change_event_settings"
|
||||
form_class = LayoutEditForm
|
||||
model = WalletLayout
|
||||
permission = "can_change_event_settings" # TODO: new permission name
|
||||
|
||||
@property
|
||||
def platform(self):
|
||||
@@ -116,3 +125,38 @@ class EditorView(EventPermissionRequiredMixin, FormView):
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
class LayoutEditorView(EventPermissionRequiredMixin, UpdateView):
|
||||
template_name = "pretixplugins/wallet/edit.html"
|
||||
form_class = LayoutEditForm
|
||||
success_url = ""
|
||||
permission = "can_change_event_settings"
|
||||
|
||||
@property
|
||||
def platform(self):
|
||||
return self.kwargs["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
|
||||
Reference in New Issue
Block a user