mirror of
https://github.com/pretix/pretix.git
synced 2026-11-11 01:27:08 +00:00
cleanup wallet placeholder signal & image placeholder handling
This commit is contained in:
1 parent
e4585aceb5
commit
ba1f2c3deb
4 files changed
+42
-49
No files matched your search
@@ -36,9 +36,9 @@ class WalletPlatformLayoutSerializer(I18nAwareModelSerializer):
|
||||
raise ValidationError(_("Invalid style"))
|
||||
style = platform_styles[data["style"]]
|
||||
|
||||
style = style(event=self.context["event"], layout=data["layout"])
|
||||
style.validate()
|
||||
data["file_settings"] = style.extract_file_settings(
|
||||
obj = style(event=self.context["event"], layout=data["layout"])
|
||||
obj.validate()
|
||||
data["file_settings"] = obj.extract_file_settings(
|
||||
self.context["request"], data.get("file_settings", {})
|
||||
)
|
||||
|
||||
|
||||
@@ -2,19 +2,16 @@ from collections.abc import Callable
|
||||
from functools import cached_property
|
||||
from typing import Any
|
||||
|
||||
from tests.api.test_items import order_position
|
||||
from .signals import (
|
||||
register_wallet_text_placeholders,
|
||||
register_wallet_image_placeholders,
|
||||
)
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.core.files import File
|
||||
from django.dispatch import receiver
|
||||
from pretix.base.templatetags.money import money_filter
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.templatetags.static import static
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from i18nfield.strings import LazyI18nString
|
||||
|
||||
from pretix.base.templatetags.money import money_filter
|
||||
|
||||
from .signals import register_wallet_placeholders
|
||||
|
||||
|
||||
class BaseWalletPlaceholder:
|
||||
"""
|
||||
@@ -33,6 +30,11 @@ class BaseWalletPlaceholder:
|
||||
"""The unique identifier of this placeholder"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def content_type(self) -> str:
|
||||
"""The content type this placeholder generates (text / image)"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def label(self) -> LazyI18nString:
|
||||
"""The human readable name of this placeholder"""
|
||||
@@ -55,6 +57,10 @@ class BaseWalletPlaceholder:
|
||||
|
||||
|
||||
class BaseWalletTextPlaceholder(BaseWalletPlaceholder):
|
||||
@property
|
||||
def content_type(self) -> str:
|
||||
return "text"
|
||||
|
||||
def render(self, **context) -> str | None:
|
||||
"""
|
||||
This method is called to generate the text that is being shown on the pass.
|
||||
@@ -77,6 +83,10 @@ class BaseWalletTextPlaceholder(BaseWalletPlaceholder):
|
||||
|
||||
|
||||
class BaseWalletImagePlaceholder(BaseWalletPlaceholder):
|
||||
@property
|
||||
def content_type(self) -> str:
|
||||
return "image"
|
||||
|
||||
def render(self, **context) -> File | None:
|
||||
"""
|
||||
This method is called to generate the image that is being shown on the pass.
|
||||
@@ -199,6 +209,7 @@ class FunctionalContextTransformation(PlaceholderContextTransformation):
|
||||
def generated_context_name(self) -> str:
|
||||
return self.context_name
|
||||
|
||||
|
||||
def get_available_context(initial_context: set[str], transformations: list[PlaceholderContextTransformation]):
|
||||
used_trans = set()
|
||||
available_context = set(initial_context)
|
||||
@@ -217,6 +228,7 @@ def get_available_context(initial_context: set[str], transformations: list[Place
|
||||
|
||||
return available_context
|
||||
|
||||
|
||||
def get_transformed_context(context_args: dict[str, Any], transformations: list[PlaceholderContextTransformation]):
|
||||
used_trans = set()
|
||||
transformed_context_args = dict(context_args)
|
||||
@@ -240,6 +252,7 @@ def get_transformed_context(context_args: dict[str, Any], transformations: list[
|
||||
|
||||
return transformed_context_args
|
||||
|
||||
|
||||
class WalletPlaceholderRenderer:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -303,18 +316,10 @@ def get_wallet_placeholder_renderer(**kwargs):
|
||||
|
||||
|
||||
def get_wallet_placeholders(event) -> dict[str, dict[str, BaseWalletPlaceholder]]:
|
||||
placeholders = {
|
||||
"text": {
|
||||
v.identifier: v
|
||||
for r, vs in register_wallet_text_placeholders.send(sender=event)
|
||||
for v in vs
|
||||
},
|
||||
"image": {
|
||||
v.identifier: v
|
||||
for r, vs in register_wallet_image_placeholders.send(sender=event)
|
||||
for v in vs
|
||||
},
|
||||
}
|
||||
placeholders = {"text": {}, "image": {}}
|
||||
for r, ps in register_wallet_placeholders.send(sender=event):
|
||||
for placeholder in ps:
|
||||
placeholders[placeholder.content_type][placeholder.identifier] = placeholder
|
||||
return placeholders
|
||||
|
||||
|
||||
@@ -326,8 +331,8 @@ def get_static_file(name) -> File | None:
|
||||
|
||||
|
||||
@receiver(
|
||||
register_wallet_text_placeholders,
|
||||
dispatch_uid="plugin_wallet_register_wallet_text_placeholders",
|
||||
register_wallet_placeholders,
|
||||
dispatch_uid="plugin_wallet_register_wallet_placeholders",
|
||||
)
|
||||
def base_text_placeholders(sender, **kwargs):
|
||||
return [
|
||||
@@ -387,15 +392,7 @@ def base_text_placeholders(sender, **kwargs):
|
||||
{"item"},
|
||||
lambda item: item.description,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@receiver(
|
||||
register_wallet_image_placeholders,
|
||||
dispatch_uid="plugin_wallet_register_wallet_image_placeholders",
|
||||
)
|
||||
def base_image_placeholders(sender, **kwargs):
|
||||
return [
|
||||
# IMAGES
|
||||
FunctionalWalletImagePlaceholder(
|
||||
"poweredby",
|
||||
LazyI18nString.from_gettext("Logo"),
|
||||
|
||||
@@ -22,18 +22,10 @@
|
||||
|
||||
from pretix.base.signals import EventPluginSignal
|
||||
|
||||
register_wallet_text_placeholders = EventPluginSignal()
|
||||
register_wallet_placeholders = EventPluginSignal()
|
||||
"""
|
||||
This signal is sent out to get all known wallet placeholders. Receivers should return
|
||||
an list of subclasses of pretix.plugins.wallet.placeholders.BaseWalletTextPlaceholder.
|
||||
an list of subclasses of pretix.plugins.wallet.placeholders.BaseWalletPlaceholder.
|
||||
|
||||
As with all event-plugin signals, the ``sender`` keyword argument will contain the event.
|
||||
"""
|
||||
|
||||
register_wallet_image_placeholders = EventPluginSignal()
|
||||
"""
|
||||
This signal is sent out to get all known wallet placeholders. Receivers should return
|
||||
an list of subclasses of pretix.plugins.wallet.placeholders.BaseWalletImagePlaceholder.
|
||||
|
||||
As with all event-plugin signals, the ``sender`` keyword argument will contain the event.
|
||||
"""
|
||||
@@ -278,6 +278,9 @@ class SettingsField:
|
||||
self.help_text = help_text
|
||||
self.required = required
|
||||
|
||||
if type == "image" and required:
|
||||
raise NotImplementedError("required image settings are currently unsupported")
|
||||
|
||||
def asdict(self):
|
||||
return {
|
||||
"identifier": self.identifier,
|
||||
@@ -341,11 +344,12 @@ class PassStyle:
|
||||
"properties": {
|
||||
setting.identifier: {"type": ["string", "null"]}
|
||||
for setting in self.settings
|
||||
if setting.type == 'text'
|
||||
},
|
||||
"required": [
|
||||
setting.identifier for setting in self.settings if setting.required
|
||||
setting.identifier for setting in self.settings if setting.required and setting.type == 'text'
|
||||
],
|
||||
}
|
||||
},
|
||||
},
|
||||
"$defs": {
|
||||
"I18nString": {
|
||||
@@ -359,9 +363,9 @@ class PassStyle:
|
||||
if any(group.required for group in self.fieldgroups):
|
||||
schema.setdefault("required", [])
|
||||
schema["required"].append("fieldgroups")
|
||||
# if any(setting.required for setting in self.settings):
|
||||
# schema.setdefault("required", [])
|
||||
# schema["required"].append("settings")
|
||||
if any(setting.required and setting.type == 'text' for setting in self.settings):
|
||||
schema.setdefault("required", [])
|
||||
schema["required"].append("settings")
|
||||
|
||||
return schema
|
||||
|
||||
|
||||
Reference in new issue
Block a user