forked from CGM_Public/pretix_original
API: Optional pdf_data field
This commit is contained in:
@@ -143,6 +143,9 @@ answers list of objects Answers to user
|
|||||||
├ question_identifier string The question's ``identifier`` field
|
├ question_identifier string The question's ``identifier`` field
|
||||||
├ options list of integers Internal IDs of selected option(s)s (only for choice types)
|
├ options list of integers Internal IDs of selected option(s)s (only for choice types)
|
||||||
└ option_identifiers list of strings The ``identifier`` fields of the selected option(s)s
|
└ option_identifiers list of strings The ``identifier`` fields of the selected option(s)s
|
||||||
|
pdf_data object Data object required for ticket PDF generation. By default,
|
||||||
|
this field is missing. It will be added only if you add the
|
||||||
|
``pdf_data=true`` query parameter to your request.
|
||||||
===================================== ========================== =======================================================
|
===================================== ========================== =======================================================
|
||||||
|
|
||||||
.. versionchanged:: 1.7
|
.. versionchanged:: 1.7
|
||||||
@@ -159,7 +162,7 @@ answers list of objects Answers to user
|
|||||||
|
|
||||||
.. versionchanged:: 1.16
|
.. versionchanged:: 1.16
|
||||||
|
|
||||||
The attribute ``pseudonymization_id`` has been added.
|
The attributes ``pseudonymization_id`` and ``pdf_data`` have been added.
|
||||||
|
|
||||||
|
|
||||||
Order endpoints
|
Order endpoints
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from pretix.base.models import (
|
|||||||
Question, QuestionAnswer, Quota,
|
Question, QuestionAnswer, Quota,
|
||||||
)
|
)
|
||||||
from pretix.base.models.orders import OrderFee
|
from pretix.base.models.orders import OrderFee
|
||||||
|
from pretix.base.pdf import get_variables
|
||||||
from pretix.base.signals import register_ticket_outputs
|
from pretix.base.signals import register_ticket_outputs
|
||||||
|
|
||||||
|
|
||||||
@@ -119,17 +120,34 @@ class PositionDownloadsField(serializers.Field):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
class PdfDataSerializer(serializers.Field):
|
||||||
|
def to_representation(self, instance: OrderPosition):
|
||||||
|
res = {}
|
||||||
|
|
||||||
|
ev = instance.subevent or instance.order.event
|
||||||
|
|
||||||
|
pdfvars = get_variables(instance.order.event)
|
||||||
|
for k, f in pdfvars.items():
|
||||||
|
res[k] = f['evaluate'](instance, instance.order, ev)
|
||||||
|
|
||||||
|
for k, v in ev.meta_data.items():
|
||||||
|
res['meta:' + k] = v
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
class OrderPositionSerializer(I18nAwareModelSerializer):
|
class OrderPositionSerializer(I18nAwareModelSerializer):
|
||||||
checkins = CheckinSerializer(many=True)
|
checkins = CheckinSerializer(many=True)
|
||||||
answers = AnswerSerializer(many=True)
|
answers = AnswerSerializer(many=True)
|
||||||
downloads = PositionDownloadsField(source='*')
|
downloads = PositionDownloadsField(source='*')
|
||||||
order = serializers.SlugRelatedField(slug_field='code', read_only=True)
|
order = serializers.SlugRelatedField(slug_field='code', read_only=True)
|
||||||
|
pdf_data = PdfDataSerializer(source='*')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = OrderPosition
|
model = OrderPosition
|
||||||
fields = ('id', 'order', 'positionid', 'item', 'variation', 'price', 'attendee_name', 'attendee_email',
|
fields = ('id', 'order', 'positionid', 'item', 'variation', 'price', 'attendee_name', 'attendee_email',
|
||||||
'voucher', 'tax_rate', 'tax_value', 'secret', 'addon_to', 'subevent', 'checkins', 'downloads',
|
'voucher', 'tax_rate', 'tax_value', 'secret', 'addon_to', 'subevent', 'checkins', 'downloads',
|
||||||
'answers', 'tax_rule', 'pseudonymization_id')
|
'answers', 'tax_rule', 'pseudonymization_id', 'pdf_data')
|
||||||
|
|
||||||
|
|
||||||
class OrderFeeSerializer(I18nAwareModelSerializer):
|
class OrderFeeSerializer(I18nAwareModelSerializer):
|
||||||
@@ -150,6 +168,11 @@ class OrderSerializer(I18nAwareModelSerializer):
|
|||||||
'payment_provider', 'fees', 'total', 'comment', 'invoice_address', 'positions', 'downloads',
|
'payment_provider', 'fees', 'total', 'comment', 'invoice_address', 'positions', 'downloads',
|
||||||
'checkin_attention', 'last_modified')
|
'checkin_attention', 'last_modified')
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
if not self.context['request'].query_params.get('pdf_data', 'false') == 'true':
|
||||||
|
self.fields['positions'].child.fields.pop('pdf_data')
|
||||||
|
|
||||||
|
|
||||||
class AnswerCreateSerializer(I18nAwareModelSerializer):
|
class AnswerCreateSerializer(I18nAwareModelSerializer):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user