mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Allow adding question answers to ticket layouts
This commit is contained in:
@@ -394,12 +394,15 @@ class Event(EventMixin, LoggedModel):
|
||||
for v in vars:
|
||||
q.variations.add(variation_map[v.pk])
|
||||
|
||||
question_map = {}
|
||||
for q in Question.objects.filter(event=other).prefetch_related('items', 'options'):
|
||||
items = list(q.items.all())
|
||||
opts = list(q.options.all())
|
||||
question_map[q.pk] = q
|
||||
q.pk = None
|
||||
q.event = self
|
||||
q.save()
|
||||
|
||||
for i in items:
|
||||
q.items.add(item_map[i.pk])
|
||||
for o in opts:
|
||||
@@ -434,6 +437,7 @@ class Event(EventMixin, LoggedModel):
|
||||
event_copy_data.send(
|
||||
sender=self, other=other,
|
||||
tax_map=tax_map, category_map=category_map, item_map=item_map, variation_map=variation_map,
|
||||
question_map=question_map
|
||||
)
|
||||
|
||||
def get_payment_providers(self) -> dict:
|
||||
|
||||
@@ -253,8 +253,8 @@ but you might need to modify that data.
|
||||
|
||||
The ``sender`` keyword argument will contain the event of the **new** event. The ``other``
|
||||
keyword argument will contain the event to **copy from**. The keyword arguments
|
||||
``tax_map``, ``category_map``, ``item_map``, and ``variation_map`` contain mappings
|
||||
from object IDs in the original event to objects in the new event of the respective
|
||||
``tax_map``, ``category_map``, ``item_map``, ``question_map``, and ``variation_map`` contain
|
||||
mappings from object IDs in the original event to objects in the new event of the respective
|
||||
types.
|
||||
"""
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
from functools import partial
|
||||
|
||||
from django.dispatch import receiver
|
||||
from django.template.loader import get_template
|
||||
from django.urls import resolve
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.base.models import QuestionAnswer
|
||||
from pretix.base.signals import (
|
||||
EventPluginSignal, register_data_exporters, register_ticket_outputs,
|
||||
EventPluginSignal, event_copy_data, register_data_exporters,
|
||||
register_ticket_outputs,
|
||||
)
|
||||
from pretix.control.signals import html_head
|
||||
from pretix.presale.style import ( # NOQA: legacy import
|
||||
@@ -52,3 +57,36 @@ dictionaries as values that contain keys like in the following example::
|
||||
The evaluate member will be called with the order position, order and event as arguments. The event might
|
||||
also be a subevent, if applicable.
|
||||
"""
|
||||
|
||||
|
||||
def get_answer(op, order, event, question_id):
|
||||
try:
|
||||
a = op.answers.get(question_id=question_id)
|
||||
return str(a).replace("\n", "<br/>\n")
|
||||
except QuestionAnswer.DoesNotExist:
|
||||
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(signal=event_copy_data, dispatch_uid="pretix_ticketoutputpdf_copy_data")
|
||||
def event_copy_data_receiver(sender, other, question_map, **kwargs):
|
||||
layout = sender.settings.get('ticketoutput_pdf_layout', as_type=list)
|
||||
if not layout:
|
||||
return
|
||||
for o in layout:
|
||||
if o['type'] == 'textarea':
|
||||
if o['content'].startswith('question_'):
|
||||
o['content'] = 'question_{}'.format(question_map.get(int(o['content'][9:]), 0).pk)
|
||||
|
||||
sender.settings.set('ticketoutput_pdf_layout', list(layout))
|
||||
|
||||
Reference in New Issue
Block a user