Allow empty plugin responses (#1056)

While plugin developers are supposed to return an empty dictionary, it's
conceivable that they might just put in a `return` if their field is not
needed, and pretix being generous about this would be cool.
This commit is contained in:
Tobias Kunze
2018-10-30 10:11:39 +01:00
committed by Raphael Michel
parent 9647cc6cf2
commit 3bf3ff1ee2
2 changed files with 12 additions and 10 deletions

View File

@@ -173,11 +173,12 @@ class OrderDetail(OrderView):
p.additional_fields = [] p.additional_fields = []
data = p.meta_info_data data = p.meta_info_data
for r, response in sorted(responses, key=lambda r: str(r[0])): for r, response in sorted(responses, key=lambda r: str(r[0])):
for key, value in response.items(): if response:
p.additional_fields.append({ for key, value in response.items():
'answer': data.get('question_form_data', {}).get(key), p.additional_fields.append({
'question': value.label 'answer': data.get('question_form_data', {}).get(key),
}) 'question': value.label
})
p.has_questions = ( p.has_questions = (
p.additional_fields or p.additional_fields or

View File

@@ -67,11 +67,12 @@ class CartMixin:
responses = question_form_fields.send(sender=self.request.event, position=cp) responses = question_form_fields.send(sender=self.request.event, position=cp)
data = cp.meta_info_data data = cp.meta_info_data
for r, response in sorted(responses, key=lambda r: str(r[0])): for r, response in sorted(responses, key=lambda r: str(r[0])):
for key, value in response.items(): if response:
pos_additional_fields[cp.pk].append({ for key, value in response.items():
'answer': data.get('question_form_data', {}).get(key), pos_additional_fields[cp.pk].append({
'question': value.label 'answer': data.get('question_form_data', {}).get(key),
}) 'question': value.label
})
# Group items of the same variation # Group items of the same variation
# We do this by list manipulations instead of a GROUP BY query, as # We do this by list manipulations instead of a GROUP BY query, as