mirror of
https://github.com/pretix/pretix.git
synced 2026-11-11 01:27:08 +00:00
Show default placeholder label
This commit is contained in:
1 parent
dd6bde0d93
commit
d73f688bc4
4 files changed
+70
-19
No files matched your search
+2
-1
@@ -10,6 +10,7 @@ defineOptions({
|
||||
|
||||
const props = defineProps<{
|
||||
errors?: string[],
|
||||
placeholders: Record<string, string>
|
||||
}>();
|
||||
|
||||
const modelValue = defineModel<Record<string, string> | string>();
|
||||
@@ -25,6 +26,6 @@ watchEffect(() => {
|
||||
</script>
|
||||
|
||||
<template lang="pug">
|
||||
input.form-control(v-if="!!modelValue" v-for="(human_readable, locale) in store.locales" v-model="modelValue[locale]" v-bind="$attrs" :lang="locale" :title="human_readable" :placeholder="human_readable")
|
||||
input.form-control(v-if="!!modelValue" v-for="(human_readable, locale) in store.locales" v-model="modelValue[locale]" v-bind="$attrs" :lang="locale" :title="human_readable" :placeholder="placeholders[locale] || human_readable")
|
||||
.help-block(v-if="props.errors" v-for="error in props.errors") {{ error }}
|
||||
</template>
|
||||
+25
-2
@@ -4,6 +4,7 @@ import Select from "./input/select.vue";
|
||||
import I18nInput from "./input/i18ninput.vue";
|
||||
import TextContent from "./text-content.vue";
|
||||
import { StoreKey } from "../walletStore";
|
||||
import { i18nstringLocalize } from "../helpers.js";
|
||||
|
||||
const store = inject(StoreKey)!;
|
||||
|
||||
@@ -54,7 +55,7 @@ const placeholderChoices = computed(() => {
|
||||
.filter(([_, { required_context }]) =>
|
||||
new Set(required_context).isSubsetOf(availableContext),
|
||||
)
|
||||
.map(([k, v]): [string, string] => [k, v.label]);
|
||||
.map(([k, v]): [string, string] => [k, i18nstringLocalize(v.label)]);
|
||||
choices.push(["other", gettext("Other…")]);
|
||||
return choices;
|
||||
});
|
||||
@@ -70,6 +71,28 @@ const overflowText = computed(() => {
|
||||
);
|
||||
return interpolate(formats, [props.fieldgroup.max_entries])
|
||||
})
|
||||
|
||||
const placeholders = computed(() => {
|
||||
return fieldConfig.value.entries.map((entry) => {
|
||||
const placeholder =
|
||||
entry.type === "placeholder"
|
||||
? store.variables[props.fieldgroup.content_type][entry.content]
|
||||
: null;
|
||||
const placeholders = {};
|
||||
let base;
|
||||
if (i18nstringLocalize(entry.label)) {
|
||||
base = entry.label
|
||||
} else if (placeholder) {
|
||||
base = placeholder.label
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
for (const locale of Object.keys(store.locales)) {
|
||||
placeholders[locale] = i18nstringLocalize(base, locale)
|
||||
}
|
||||
return placeholders
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
<template lang="pug">
|
||||
@@ -90,7 +113,7 @@ const overflowText = computed(() => {
|
||||
tr(v-for="n, i in fieldConfig.entries.length" :key="i")
|
||||
td(v-if="fieldgroup.display == 'with_label'")
|
||||
.i18n-form-group
|
||||
I18nInput(v-model="fieldConfig.entries[n - 1].label")
|
||||
I18nInput(v-model="fieldConfig.entries[n - 1].label" :placeholders="placeholders[n - 1]")
|
||||
td
|
||||
TextContent(v-if='fieldgroup.content_type == "text"'
|
||||
v-model="fieldConfig.entries[n - 1]"
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
export function i18nstringLocalize(s: I18nString): string {
|
||||
export function i18nstringLocalize(s: I18nString, locale?: string): string {
|
||||
if (typeof s === 'string') {
|
||||
return s
|
||||
}
|
||||
if (s === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
var locale = document.body.attributes['data-pretixlocale'].value
|
||||
if (!locale) {
|
||||
locale = document.body.attributes['data-pretixlocale'].value
|
||||
}
|
||||
var short_locale = locale.split('-')[0]
|
||||
if (locale in s)
|
||||
return s[locale]
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import copy
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from django.db import transaction
|
||||
from django import forms
|
||||
from django.core.exceptions import BadRequest
|
||||
from django.db.models.query import QuerySet
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, DetailView, ListView, DeleteView, View
|
||||
from pretix_vrpayment_wero.payment import HttpRequest
|
||||
from pretix.base.i18n import language
|
||||
from pretix.base.pdf import get_images, get_variables
|
||||
from pretix.base.services.tickets import get_preview_position
|
||||
from pretix.control.permissions import EventPermissionRequiredMixin
|
||||
from django.conf import settings
|
||||
@@ -26,11 +23,18 @@ from .styles import (
|
||||
AVAILABLE_STYLES_DICT,
|
||||
)
|
||||
from django.contrib import messages
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.utils.functional import cached_property
|
||||
from django.templatetags.static import static
|
||||
from .placeholders import get_wallet_placeholder_renderer, get_wallet_placeholders, WalletPlaceholderRenderer
|
||||
from .placeholders import get_wallet_placeholder_renderer, get_wallet_placeholders
|
||||
from pretix.base.middleware import add_to_response_csp
|
||||
from i18nfield.strings import LazyI18nString
|
||||
|
||||
|
||||
def localize_lazyi18n_string(string: LazyI18nString, locales):
|
||||
data = {}
|
||||
for locale in locales:
|
||||
data[locale] = string.localize(locale)
|
||||
return data
|
||||
|
||||
|
||||
def get_editor_placeholders(event):
|
||||
with (
|
||||
@@ -41,7 +45,15 @@ def get_editor_placeholders(event):
|
||||
context = get_wallet_placeholder_renderer(order_position=p)
|
||||
placeholders = {
|
||||
t: {
|
||||
pid: {"label": str(p.label), "sample": str(context.render_sample(p)), "required_context": list(sorted(p.required_context))}
|
||||
pid: {
|
||||
"label": (
|
||||
localize_lazyi18n_string(p.label, event.settings.locales)
|
||||
if isinstance(p.label, LazyI18nString)
|
||||
else str(p.label)
|
||||
),
|
||||
"sample": str(context.render_sample(p)),
|
||||
"required_context": list(sorted(p.required_context)),
|
||||
}
|
||||
for pid, p in ps.items()
|
||||
}
|
||||
for t, ps in get_wallet_placeholders(event).items()
|
||||
@@ -90,13 +102,18 @@ class LayoutEditorView(LayoutDetailView):
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
|
||||
response = super().dispatch(request, *args, **kwargs)
|
||||
add_to_response_csp(response, {
|
||||
'img-src': ['blob:'],
|
||||
})
|
||||
add_to_response_csp(
|
||||
response,
|
||||
{
|
||||
"img-src": ["blob:"],
|
||||
},
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
class WalletLayoutCreateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = WalletLayout
|
||||
@@ -161,10 +178,16 @@ class LayoutPreviewView(EventPermissionRequiredMixin, View):
|
||||
style_id = request.POST.get("style")
|
||||
layout = request.POST.get("layout")
|
||||
file_settings = json.loads(request.POST.get("file_settings"))
|
||||
base_layout = event.wallet_layouts.get(pk=request.POST.get("id")).platform_layouts.filter(platform=platform_id).first()
|
||||
base_layout = (
|
||||
event.wallet_layouts.get(pk=request.POST.get("id"))
|
||||
.platform_layouts.filter(platform=platform_id)
|
||||
.first()
|
||||
)
|
||||
|
||||
if base_layout:
|
||||
base_file_settings = {fs.key: fs.file for fs in base_layout.file_settings.all()}
|
||||
base_file_settings = {
|
||||
fs.key: fs.file for fs in base_layout.file_settings.all()
|
||||
}
|
||||
else:
|
||||
base_file_settings = {}
|
||||
|
||||
@@ -185,7 +208,10 @@ class LayoutPreviewView(EventPermissionRequiredMixin, View):
|
||||
):
|
||||
p = get_preview_position(request.event)
|
||||
l = style(event=event, layout=layout)
|
||||
file_settings = {**base_file_settings, **l.extract_file_settings(request, file_settings)}
|
||||
file_settings = {
|
||||
**base_file_settings,
|
||||
**l.extract_file_settings(request, file_settings),
|
||||
}
|
||||
layout = style(event, layout, file_settings)
|
||||
layout.validate()
|
||||
|
||||
|
||||
Reference in new issue
Block a user