WIP preview

This commit is contained in:
Kara Engelhardt
2026-07-28 11:30:50 +02:00
parent 3c727c230a
commit 3b52a0703f
10 changed files with 167 additions and 64 deletions
+3 -5
View File
@@ -1,5 +1,6 @@
from .base import (
FieldEntryType,
FieldGroupDisplay,
ImageFieldGroup,
PlaceholderFieldGroup,
PredefinedFieldGroup,
@@ -216,7 +217,6 @@ class AppleWalletStyle(PassStyle):
pkpass.add_file("pass.json", json.dumps(pass_json))
return pkpass.finish()
class AppleWalletEventTicket(AppleWalletStyle):
identifier = "event_1"
name = _("Event Ticket Layout 1")
@@ -226,7 +226,6 @@ class AppleWalletEventTicket(AppleWalletStyle):
name=_("Icon"),
min_entries=0,
max_entries=1,
labels=False,
default_entries=[
PlaceholderFieldEntry(
content="poweredby",
@@ -238,7 +237,6 @@ class AppleWalletEventTicket(AppleWalletStyle):
name=_("Logo"),
min_entries=0,
max_entries=1,
labels=False,
default_entries=[
PlaceholderFieldEntry(
content="poweredby",
@@ -249,7 +247,7 @@ class AppleWalletEventTicket(AppleWalletStyle):
identifier="logo_text",
name=_("Logo text"),
max_entries=1,
labels=False,
display=FieldGroupDisplay.PLAIN,
default_entries=[],
),
TextFieldGroup(
@@ -275,7 +273,7 @@ class AppleWalletEventTicket(AppleWalletStyle):
identifier="code",
name=_("QR-Code"),
max_entries=1,
labels=False,
display=FieldGroupDisplay.CODE,
default_entries=[
PlaceholderFieldEntry(
content="secret",
+15 -10
View File
@@ -12,6 +12,10 @@ class FieldGroupType(enum.Enum):
PLACEHOLDER = "placeholder"
PREDEFINED = "predefined"
class FieldGroupDisplay(enum.Enum):
PLAIN = "plain"
WITH_LABEL = "with_label"
CODE = "code"
class FieldGroup:
type: FieldGroupType
@@ -106,7 +110,7 @@ class PlaceholderFieldGroup(FieldGroup):
type = FieldGroupType.PLACEHOLDER
content_type: FieldContentType
default_entries: list[FieldEntry]
labels: bool
display: FieldGroupDisplay
min_entries: int | None
max_entries: int | None
@@ -115,19 +119,19 @@ class PlaceholderFieldGroup(FieldGroup):
identifier: str,
name: str,
content_type: FieldContentType,
description: str=None,
description: str="",
required=False,
default_entries=None,
min_entries=None,
max_entries=None,
labels=True,
display=FieldGroupDisplay.WITH_LABEL,
):
super().__init__(identifier, name, description, required)
self.content_type = content_type
self.default_entries = default_entries or []
self.min_entries = min_entries
self.max_entries = max_entries
self.labels = labels
self.display = display
if self.required and (self.min_entries is None or self.min_entries < 1):
self.min_entries = 1
@@ -137,7 +141,7 @@ class PlaceholderFieldGroup(FieldGroup):
**super().asdict(),
"content_type": self.content_type.value,
"default_entries": [x.asdict() for x in self.default_entries],
"labels": self.labels,
"display": self.display.value,
"min_entries": self.min_entries,
"max_entries": self.max_entries,
}
@@ -172,7 +176,7 @@ class PlaceholderFieldGroup(FieldGroup):
def entries_schema(self, placeholders: list[str]):
baseprops = {}
if self.labels:
if self.display == FieldGroupDisplay.WITH_LABEL:
baseprops["label"] = {"$ref": "#/$defs/I18nString"}
schema = {
@@ -198,7 +202,7 @@ class PlaceholderFieldGroup(FieldGroup):
"required": ["type", "content"],
},
}
if self.labels:
if self.display == FieldGroupDisplay.WITH_LABEL:
schema["items"]["required"].append("label")
if self.min_entries is not None:
schema["minItems"] = self.min_entries
@@ -216,9 +220,10 @@ class TextFieldGroup(PlaceholderFieldGroup):
class ImageFieldGroup(PlaceholderFieldGroup):
content_type = FieldContentType.IMAGE
display = FieldGroupDisplay.PLAIN
def __init__(self, **kwargs):
super().__init__(content_type=self.content_type, **kwargs)
super().__init__(content_type=self.content_type, display=self.display, **kwargs)
class PassStyle:
@@ -299,11 +304,11 @@ class PassStyle:
if group.identifier in layout["fieldgroups"]:
for field in layout["fieldgroups"][group.identifier]["entries"]:
field_entry = {}
if group.labels:
if group.display == FieldGroupDisplay.WITH_LABEL:
field_entry["label"] = LazyI18nString(field["label"])
if field["type"] == FieldEntryType.PLACEHOLDER.value:
label, field_entry["value"] = self.render_placeholder(context, group.content_type.value, field['content'])
if group.labels and not str(field_entry['label']) and label:
if group.display == FieldGroupDisplay.WITH_LABEL and not str(field_entry['label']) and label:
field_entry['label'] = LazyI18nString(label)
elif field["type"] == FieldEntryType.CUSTOM.value:
+2 -2
View File
@@ -1,4 +1,4 @@
from .base import PassStyle, PredefinedFieldGroup, TextFieldGroup, WalletPlatform
from .base import FieldGroupDisplay, PassStyle, PredefinedFieldGroup, TextFieldGroup, WalletPlatform
from django.utils.translation import gettext_lazy as _
class GooglePlatform(WalletPlatform):
@@ -16,5 +16,5 @@ class GoogleWalletEventTicket(PassStyle):
platform = GooglePlatform
fieldgroups = [
PredefinedFieldGroup(identifier="seating", name=_("Seating")),
TextFieldGroup(identifier="qrcode", name=_("QR-Code"), labels=False),
TextFieldGroup(identifier="qrcode", name=_("QR-Code"), display=FieldGroupDisplay.PLAIN),
]