diff --git a/src/pretix/base/pdf.py b/src/pretix/base/pdf.py index 0329fb95cd..5bafaeacd2 100644 --- a/src/pretix/base/pdf.py +++ b/src/pretix/base/pdf.py @@ -504,10 +504,17 @@ def variables_from_questions(sender, *args, **kwargs): for q in sender.questions.all(): if q.type == Question.TYPE_FILE: continue + d['question_{}'.format(q.identifier)] = { + 'label': _('Question: {question}').format(question=q.question), + 'editor_sample': _('').format(question=q.question), + 'evaluate': partial(get_answer, question_id=q.pk), + 'migrate_from': 'question_{}'.format(q.pk) + } d['question_{}'.format(q.pk)] = { 'label': _('Question: {question}').format(question=q.question), 'editor_sample': _('').format(question=q.question), - 'evaluate': partial(get_answer, question_id=q.pk) + 'evaluate': partial(get_answer, question_id=q.pk), + 'hidden': True, } return d diff --git a/src/pretix/control/templates/pretixcontrol/pdf/index.html b/src/pretix/control/templates/pretixcontrol/pdf/index.html index ee35023d16..e8b91a8c6f 100644 --- a/src/pretix/control/templates/pretixcontrol/pdf/index.html +++ b/src/pretix/control/templates/pretixcontrol/pdf/index.html @@ -372,7 +372,9 @@
{% endfor %} +

+ {% trans "Show available placeholders" %} +

diff --git a/src/pretix/control/templates/pretixcontrol/pdf/placeholders.html b/src/pretix/control/templates/pretixcontrol/pdf/placeholders.html new file mode 100644 index 0000000000..25155270d5 --- /dev/null +++ b/src/pretix/control/templates/pretixcontrol/pdf/placeholders.html @@ -0,0 +1,68 @@ +{% extends "pretixcontrol/event/base.html" %} +{% load i18n %} +{% load static %} +{% load compress %} +{% block title %}{% trans "PDF Editor" %}{% endblock %} +{% block custom_header %} + {{ block.super }} + {% compress css %} + + {% endcompress %} + +{% endblock %} +{% block content %} +

+ {% trans "PDF Editor" %} + {% trans "Available placeholders" %} +

+

+ {% blocktrans trimmed %} + You can use placeholders in custom texts on tickets to enrich your text with individual data. Which + placeholders are available depends on your event settings, activated plugins, the selected product, + as well as user input. + This page lists all placeholders technically available for your event, however most of them can also + be empty in some cases depending on configuration. + {% endblocktrans %} +

+
+ + + + + + + + + + {% for varname, var in variables.items %} + {% if not var.hidden %} + + + + + + {% endif %} + {% endfor %} + {% for p in request.organizer.meta_properties.all %} + + + + + + {% endfor %} + {% for p in request.event.item_meta_properties.all %} + + + + + + {% endfor %} + +
{% trans "Placeholder" %}{% trans "Description" %}{% trans "Formatting example" %}
{{ "{" }}{{ varname }}{{ "}" }}{{ var.label }}{{ var.editor_sample }}
{{ "{" }}meta:{{ p.name }}{{ "}" }} + {% trans "Event attribute:" %} {{ p.name }} +
{{ "{" }}itemmeta:{{ p.name }}{{ "}" }} + {% trans "Item attribute:" %} {{ p.name }} +
+
+{% endblock %} + diff --git a/src/pretix/control/views/pdf.py b/src/pretix/control/views/pdf.py index 1837b3da59..5fbb79bd31 100644 --- a/src/pretix/control/views/pdf.py +++ b/src/pretix/control/views/pdf.py @@ -33,7 +33,7 @@ from django.core.files.storage import default_storage from django.http import ( FileResponse, HttpResponse, HttpResponseBadRequest, JsonResponse, ) -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, render from django.urls import reverse from django.utils.crypto import get_random_string from django.utils.timezone import now @@ -65,10 +65,17 @@ class BaseEditorView(EventPermissionRequiredMixin, TemplateView): title = None def get(self, request, *args, **kwargs): + if 'placeholders' in request.GET: + return self.get_placeholders_help(request) resp = super().get(request, *args, **kwargs) resp._csp_ignore = True return resp + def get_placeholders_help(self, request): + ctx = {} + ctx['variables'] = self.get_variables() + return render(request, 'pretixcontrol/pdf/placeholders.html', ctx) + def process_upload(self): f = self.request.FILES.get('background') error = False diff --git a/src/pretix/static/pretixcontrol/js/ui/editor.js b/src/pretix/static/pretixcontrol/js/ui/editor.js index 8fe3672d3f..0ef14b421a 100644 --- a/src/pretix/static/pretixcontrol/js/ui/editor.js +++ b/src/pretix/static/pretixcontrol/js/ui/editor.js @@ -286,7 +286,7 @@ var editor = { } else if (key.startsWith('meta:')) { return key.substr(5); } - return $('#toolbox-content option[value='+key+']').attr('data-sample') || ''; + return $('#toolbox-content option[value='+key+'], #toolbox-content option[data-old-value='+key+']').attr('data-sample') || ''; }, _load_page: function (page_number, dump) { @@ -396,6 +396,7 @@ var editor = { $("#toolbox-content-other").hide(); $("#toolbox-content-other-i18n").hide(); + $("#toolbox-content-other-help").hide(); $(".add-buttons button").prop('disabled', false); if (dump) { @@ -492,9 +493,15 @@ var editor = { if (!o.content && o.type == "barcodearea") { o.content = "secret"; } - $("#toolbox-content").val(o.content); + var $migrate_to = $("#toolbox-content option[data-old-value='" + o.content + "']"); + if ($migrate_to.length > 0) { + $("#toolbox-content").val($migrate_to.val()); + } else { + $("#toolbox-content").val(o.content); + } $("#toolbox-content-other").toggle($("#toolbox-content").val() === "other"); $("#toolbox-content-other-i18n").toggle($("#toolbox-content").val() === "other_i18n"); + $("#toolbox-content-other-help").toggle($("#toolbox-content").val() === "other" || $("#toolbox-content").val() === "other_i18n"); if (o.content === "other") { $("#toolbox-content-other").val(o.text); } else if (o.content === "other_i18n") { @@ -537,6 +544,7 @@ var editor = { $("#toolbox-content-other").toggle($("#toolbox-content").val() === "other"); $("#toolbox-content-other-i18n").toggle($("#toolbox-content").val() === "other_i18n"); + $("#toolbox-content-other-help").toggle($("#toolbox-content").val() === "other" || $("#toolbox-content").val() === "other_i18n"); o.content = $("#toolbox-content").val(); if ($("#toolbox-content").val() === "other") { o.text = $("#toolbox-content-other").val(); @@ -591,6 +599,7 @@ var editor = { o.rotate(parseFloat($("#toolbox-textrotation").val())); $("#toolbox-content-other").toggle($("#toolbox-content").val() === "other"); $("#toolbox-content-other-i18n").toggle($("#toolbox-content").val() === "other_i18n"); + $("#toolbox-content-other-help").toggle($("#toolbox-content").val() === "other" || $("#toolbox-content").val() === "other_i18n"); o.content = $("#toolbox-content").val(); if ($("#toolbox-content").val() === "other") { o.setText($("#toolbox-content-other").val());