mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
PDF editor: Move questions signal out of ticket provider
This commit is contained in:
@@ -6,11 +6,13 @@ import subprocess
|
||||
import tempfile
|
||||
import uuid
|
||||
from collections import OrderedDict
|
||||
from functools import partial
|
||||
from io import BytesIO
|
||||
|
||||
import bleach
|
||||
from django.conf import settings
|
||||
from django.contrib.staticfiles import finders
|
||||
from django.dispatch import receiver
|
||||
from django.utils.formats import date_format
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from PyPDF2 import PdfFileReader
|
||||
@@ -29,7 +31,7 @@ from reportlab.pdfgen.canvas import Canvas
|
||||
from reportlab.platypus import Paragraph
|
||||
|
||||
from pretix.base.invoice import ThumbnailingImageReader
|
||||
from pretix.base.models import Order, OrderPosition
|
||||
from pretix.base.models import Order, OrderPosition, QuestionAnswer
|
||||
from pretix.base.settings import PERSON_NAME_SCHEMES
|
||||
from pretix.base.signals import layout_text_variables
|
||||
from pretix.base.templatetags.money import money_filter
|
||||
@@ -193,6 +195,30 @@ DEFAULT_VARIABLES = OrderedDict((
|
||||
))
|
||||
|
||||
|
||||
@receiver(layout_text_variables, dispatch_uid="pretix_base_layout_text_variables_questions")
|
||||
def variables_from_questions(sender, *args, **kwargs):
|
||||
def get_answer(op, order, event, question_id):
|
||||
try:
|
||||
if 'answers' in getattr(op, '_prefetched_objects_cache', {}):
|
||||
a = [a for a in op.answers.all() if a.question_id == question_id][0]
|
||||
else:
|
||||
a = op.answers.get(question_id=question_id)
|
||||
return str(a).replace("\n", "<br/>\n")
|
||||
except QuestionAnswer.DoesNotExist:
|
||||
return ""
|
||||
except IndexError:
|
||||
return ""
|
||||
|
||||
d = {}
|
||||
for q in sender.questions.all():
|
||||
d['question_{}'.format(q.pk)] = {
|
||||
'label': _('Question: {question}').format(question=q.question),
|
||||
'editor_sample': _('<Answer: {question}>').format(question=q.question),
|
||||
'evaluate': partial(get_answer, question_id=q.pk)
|
||||
}
|
||||
return d
|
||||
|
||||
|
||||
def get_variables(event):
|
||||
v = copy.copy(DEFAULT_VARIABLES)
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import copy
|
||||
import json
|
||||
from functools import partial
|
||||
|
||||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
@@ -8,19 +7,15 @@ from django.utils.html import escape
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.base.channels import get_all_sales_channels
|
||||
from pretix.base.models import QuestionAnswer
|
||||
from pretix.base.signals import ( # NOQA: legacy import
|
||||
event_copy_data, item_copy_data, layout_text_variables, logentry_display,
|
||||
logentry_object_link, register_data_exporters, register_ticket_outputs,
|
||||
event_copy_data, item_copy_data, logentry_display, logentry_object_link,
|
||||
register_data_exporters, register_ticket_outputs,
|
||||
)
|
||||
from pretix.control.signals import item_forms
|
||||
from pretix.plugins.ticketoutputpdf.forms import TicketLayoutItemForm
|
||||
from pretix.plugins.ticketoutputpdf.models import (
|
||||
TicketLayout, TicketLayoutItem,
|
||||
)
|
||||
from pretix.presale.style import ( # NOQA: legacy import
|
||||
get_fonts, register_fonts,
|
||||
)
|
||||
|
||||
|
||||
@receiver(register_ticket_outputs, dispatch_uid="output_pdf")
|
||||
@@ -35,31 +30,6 @@ def register_data(sender, **kwargs):
|
||||
return AllTicketsPDF
|
||||
|
||||
|
||||
def get_answer(op, order, event, question_id):
|
||||
try:
|
||||
if 'answers' in getattr(op, '_prefetched_objects_cache', {}):
|
||||
a = [a for a in op.answers.all() if a.question_id == question_id][0]
|
||||
else:
|
||||
a = op.answers.get(question_id=question_id)
|
||||
return str(a).replace("\n", "<br/>\n")
|
||||
except QuestionAnswer.DoesNotExist:
|
||||
return ""
|
||||
except IndexError:
|
||||
return ""
|
||||
|
||||
|
||||
@receiver(layout_text_variables, dispatch_uid="pretix_ticketoutputpdf_layout_text_variables_questions")
|
||||
def variables_from_questions(sender, *args, **kwargs):
|
||||
d = {}
|
||||
for q in sender.questions.all():
|
||||
d['question_{}'.format(q.pk)] = {
|
||||
'label': _('Question: {question}').format(question=q.question),
|
||||
'editor_sample': _('<Answer: {question}>').format(question=q.question),
|
||||
'evaluate': partial(get_answer, question_id=q.pk)
|
||||
}
|
||||
return d
|
||||
|
||||
|
||||
@receiver(item_forms, dispatch_uid="pretix_ticketoutputpdf_item_forms")
|
||||
def control_item_forms(sender, request, item, **kwargs):
|
||||
forms = []
|
||||
|
||||
Reference in New Issue
Block a user